1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 David Herrmann <dh.herrmann@gmail.com>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
32 static void test_ring(void) {
33 static const char buf[8192];
41 l = ring_peek(&r, vec);
44 s = ring_push(&r, buf, 2048);
46 assert_se(ring_get_size(&r) == 2048);
48 l = ring_peek(&r, vec);
50 assert_se(vec[0].iov_len == 2048);
51 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
52 assert_se(ring_get_size(&r) == 2048);
55 assert_se(ring_get_size(&r) == 0);
57 l = ring_peek(&r, vec);
59 assert_se(ring_get_size(&r) == 0);
61 s = ring_push(&r, buf, 2048);
63 assert_se(ring_get_size(&r) == 2048);
65 l = ring_peek(&r, vec);
67 assert_se(vec[0].iov_len == 2048);
68 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
69 assert_se(ring_get_size(&r) == 2048);
71 s = ring_push(&r, buf, 1);
73 assert_se(ring_get_size(&r) == 2049);
75 l = ring_peek(&r, vec);
77 assert_se(vec[0].iov_len == 2048);
78 assert_se(vec[1].iov_len == 1);
79 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
80 assert_se(!memcmp(vec[1].iov_base, buf, vec[1].iov_len));
81 assert_se(ring_get_size(&r) == 2049);
84 assert_se(ring_get_size(&r) == 1);
86 l = ring_peek(&r, vec);
88 assert_se(vec[0].iov_len == 1);
89 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
90 assert_se(ring_get_size(&r) == 1);
93 assert_se(ring_get_size(&r) == 0);
95 s = ring_push(&r, buf, 2048);
97 assert_se(ring_get_size(&r) == 2048);
99 s = ring_push(&r, buf, 2049);
101 assert_se(ring_get_size(&r) == 4097);
103 l = ring_peek(&r, vec);
105 assert_se(vec[0].iov_len == 4097);
106 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
107 assert_se(ring_get_size(&r) == 4097);
110 assert_se(ring_get_size(&r) == 4096);
112 s = ring_push(&r, buf, 4096);
114 assert_se(ring_get_size(&r) == 8192);
116 l = ring_peek(&r, vec);
118 assert_se(vec[0].iov_len == 8191);
119 assert_se(vec[1].iov_len == 1);
120 assert_se(!memcmp(vec[0].iov_base, buf, vec[0].iov_len));
121 assert_se(!memcmp(vec[1].iov_base, buf, vec[1].iov_len));
122 assert_se(ring_get_size(&r) == 8192);
125 assert_se(ring_get_size(&r) == 0);
128 int main(int argc, char *argv[]) {
129 log_parse_environment();