]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/test/test/test_cmdline_lib.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
15 #include <cmdline_vt100.h>
16 #include <cmdline_rdline.h>
17 #include <cmdline_parse.h>
18 #include <cmdline_socket.h>
21 #include "test_cmdline.h"
23 /****************************************************************/
24 /* static functions required for some tests */
26 valid_buffer(__attribute__((unused
))struct rdline
*rdl
,
27 __attribute__((unused
))const char *buf
,
28 __attribute__((unused
)) unsigned int size
)
33 complete_buffer(__attribute__((unused
)) struct rdline
*rdl
,
34 __attribute__((unused
)) const char *buf
,
35 __attribute__((unused
)) char *dstbuf
,
36 __attribute__((unused
)) unsigned int dstsize
,
37 __attribute__((unused
)) int *state
)
42 /****************************************************************/
45 test_cmdline_parse_fns(void)
49 char dst
[CMDLINE_TEST_BUFSIZE
];
51 if (cmdline_parse(NULL
, "buffer") >= 0)
53 if (cmdline_parse(&cl
, NULL
) >= 0)
56 if (cmdline_complete(NULL
, "buffer", &i
, dst
, sizeof(dst
)) >= 0)
58 if (cmdline_complete(&cl
, NULL
, &i
, dst
, sizeof(dst
)) >= 0)
60 if (cmdline_complete(&cl
, "buffer", NULL
, dst
, sizeof(dst
)) >= 0)
62 if (cmdline_complete(&cl
, "buffer", &i
, NULL
, sizeof(dst
)) >= 0)
68 printf("Error: function accepted null parameter!\n");
73 test_cmdline_rdline_fns(void)
76 rdline_write_char_t
*wc
= &cmdline_write_char
;
77 rdline_validate_t
*v
= &valid_buffer
;
78 rdline_complete_t
*c
= &complete_buffer
;
80 if (rdline_init(NULL
, wc
, v
, c
) >= 0)
82 if (rdline_init(&rdl
, NULL
, v
, c
) >= 0)
84 if (rdline_init(&rdl
, wc
, NULL
, c
) >= 0)
86 if (rdline_init(&rdl
, wc
, v
, NULL
) >= 0)
88 if (rdline_char_in(NULL
, 0) >= 0)
90 if (rdline_get_buffer(NULL
) != NULL
)
92 if (rdline_add_history(NULL
, "history") >= 0)
94 if (rdline_add_history(&rdl
, NULL
) >= 0)
96 if (rdline_get_history_item(NULL
, 0) != NULL
)
100 rdline_newline(NULL
, "prompt");
101 rdline_newline(&rdl
, NULL
);
104 rdline_restart(NULL
);
105 rdline_redisplay(NULL
);
107 rdline_clear_history(NULL
);
112 printf("Error: function accepted null parameter!\n");
117 test_cmdline_vt100_fns(void)
119 if (vt100_parser(NULL
, 0) >= 0) {
120 printf("Error: function accepted null parameter!\n");
131 test_cmdline_socket_fns(void)
133 cmdline_parse_ctx_t ctx
;
135 if (cmdline_stdin_new(NULL
, "prompt") != NULL
)
137 if (cmdline_stdin_new(&ctx
, NULL
) != NULL
)
139 if (cmdline_file_new(NULL
, "prompt", "/dev/null") != NULL
)
141 if (cmdline_file_new(&ctx
, NULL
, "/dev/null") != NULL
)
143 if (cmdline_file_new(&ctx
, "prompt", NULL
) != NULL
)
145 if (cmdline_file_new(&ctx
, "prompt", "-/invalid/~/path") != NULL
) {
146 printf("Error: succeeded in opening invalid file for reading!");
149 if (cmdline_file_new(&ctx
, "prompt", "/dev/null") == NULL
) {
150 printf("Error: failed to open /dev/null for reading!");
155 cmdline_stdin_exit(NULL
);
159 printf("Error: function accepted null parameter!\n");
164 test_cmdline_fns(void)
166 cmdline_parse_ctx_t ctx
;
167 struct cmdline cl
, *tmp
;
169 memset(&ctx
, 0, sizeof(ctx
));
170 tmp
= cmdline_new(&ctx
, "test", -1, -1);
174 if (cmdline_new(NULL
, "prompt", 0, 0) != NULL
)
176 if (cmdline_new(&ctx
, NULL
, 0, 0) != NULL
)
178 if (cmdline_in(NULL
, "buffer", CMDLINE_TEST_BUFSIZE
) >= 0)
180 if (cmdline_in(&cl
, NULL
, CMDLINE_TEST_BUFSIZE
) >= 0)
182 if (cmdline_write_char(NULL
, 0) >= 0)
186 cmdline_set_prompt(NULL
, "prompt");
188 cmdline_printf(NULL
, "format");
189 /* this should fail as stream handles are invalid */
190 cmdline_printf(tmp
, "format");
191 cmdline_interact(NULL
);
194 /* check if void calls change anything when they should fail */
197 cmdline_printf(&cl
, NULL
);
198 if (memcmp(&cl
, tmp
, sizeof(cl
))) goto mismatch
;
199 cmdline_set_prompt(&cl
, NULL
);
200 if (memcmp(&cl
, tmp
, sizeof(cl
))) goto mismatch
;
201 cmdline_in(&cl
, NULL
, CMDLINE_TEST_BUFSIZE
);
202 if (memcmp(&cl
, tmp
, sizeof(cl
))) goto mismatch
;
209 printf("Error: function accepted null parameter!\n");
212 printf("Error: data changed!\n");
216 /* test library functions. the point of these tests is not so much to test
217 * functions' behaviour as it is to make sure there are no segfaults if
218 * they are called with invalid parameters.
221 test_cmdline_lib(void)
223 if (test_cmdline_parse_fns() < 0)
225 if (test_cmdline_rdline_fns() < 0)
227 if (test_cmdline_vt100_fns() < 0)
229 if (test_cmdline_socket_fns() < 0)
231 if (test_cmdline_fns() < 0)