]> git.proxmox.com Git - mirror_frr.git/blob - tests/lib/test_stream.c
Merge pull request #12845 from sri-mohan1/sri-mohan-ldp
[mirror_frr.git] / tests / lib / test_stream.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Simple stream test.
3 *
4 * Copyright (C) 2006 Sun Microsystems, Inc.
5 */
6
7 #include <zebra.h>
8 #include <stream.h>
9 #include <thread.h>
10
11 #include "printfrr.h"
12
13 static unsigned long long ham = 0xdeadbeefdeadbeef;
14 struct thread_master *master;
15
16 static void print_stream(struct stream *s)
17 {
18 size_t getp = stream_get_getp(s);
19
20 printfrr("endp: %zu, readable: %zu, writeable: %zu\n",
21 stream_get_endp(s), STREAM_READABLE(s), STREAM_WRITEABLE(s));
22
23 while (STREAM_READABLE(s)) {
24 printfrr("0x%x ", *stream_pnt(s));
25 stream_forward_getp(s, 1);
26 }
27
28 printfrr("\n");
29
30 /* put getp back to where it was */
31 stream_set_getp(s, getp);
32 }
33
34 int main(void)
35 {
36 struct stream *s;
37
38 s = stream_new(1024);
39
40 stream_putc(s, ham);
41 stream_putw(s, ham);
42 stream_putl(s, ham);
43 stream_putq(s, ham);
44
45 print_stream(s);
46
47 stream_resize_inplace(&s, stream_get_endp(s));
48
49 print_stream(s);
50
51 printfrr("c: 0x%hhx\n", stream_getc(s));
52 printfrr("w: 0x%hx\n", stream_getw(s));
53 printfrr("l: 0x%x\n", stream_getl(s));
54 printfrr("q: 0x%" PRIx64 "\n", stream_getq(s));
55
56 return 0;
57 }