MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_cirbuf_string_misc

Function test_cirbuf_string_misc

dpdk/app/test/test_cmdline_cirbuf.c:20–128  ·  view source on GitHub ↗

miscellaneous tests - they make bullseye happy */

Source from the content-addressed store, hash-verified

18
19/* miscellaneous tests - they make bullseye happy */
20static int
21test_cirbuf_string_misc(void)
22{
23 struct cirbuf cb;
24 char buf[CMDLINE_TEST_BUFSIZE];
25 char tmp[CMDLINE_TEST_BUFSIZE];
26
27 /* initialize buffers */
28 memset(buf, 0, sizeof(buf));
29 memset(tmp, 0, sizeof(tmp));
30
31 /*
32 * initialize circular buffer
33 */
34 if (cirbuf_init(&cb, buf, 0, sizeof(buf)) < 0) {
35 printf("Error: failed to initialize circular buffer!\n");
36 return -1;
37 }
38
39 /*
40 * add strings to head and tail, but read only tail
41 * this results in read operation that does not transcend
42 * from buffer end to buffer beginning (in other words,
43 * strlen <= cb->maxlen - cb->end)
44 */
45
46 /* add string to head */
47 if (cirbuf_add_buf_head(&cb, CIRBUF_STR_HEAD, sizeof(CIRBUF_STR_HEAD))
48 != (sizeof(CIRBUF_STR_HEAD))) {
49 printf("Error: failed to add string to head!\n");
50 return -1;
51 }
52 /* add string to tail */
53 if (cirbuf_add_buf_tail(&cb, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL))
54 != (sizeof(CIRBUF_STR_TAIL))) {
55 printf("Error: failed to add string to head!\n");
56 return -1;
57 }
58 /* read string from tail */
59 if (cirbuf_get_buf_tail(&cb, tmp, sizeof(CIRBUF_STR_TAIL))
60 != (sizeof(CIRBUF_STR_TAIL))) {
61 printf("Error: failed to get string from tail!\n");
62 return -1;
63 }
64 /* verify string */
65 if (strncmp(tmp, CIRBUF_STR_TAIL, sizeof(CIRBUF_STR_TAIL)) != 0) {
66 printf("Error: tail strings do not match!\n");
67 return -1;
68 }
69 /* clear buffers */
70 memset(tmp, 0, sizeof(tmp));
71 memset(buf, 0, sizeof(buf));
72
73
74
75 /*
76 * add a string to buffer when start/end is at end of buffer
77 */

Callers 1

test_cirbuf_stringFunction · 0.85

Calls 8

memsetFunction · 0.85
cirbuf_initFunction · 0.85
cirbuf_add_buf_headFunction · 0.85
cirbuf_add_buf_tailFunction · 0.85
cirbuf_get_buf_tailFunction · 0.85
strncmpFunction · 0.85
cirbuf_get_buf_headFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected