1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #include <rte_common.h>
16 #include <cmdline_vt100.h>
17 #include <cmdline_rdline.h>
18 #include <cmdline_parse.h>
19 #include <cmdline_socket.h>
22 #include "test_cmdline.h"
24 #ifndef RTE_EXEC_ENV_WINDOWS
25 #define NULL_INPUT "/dev/null"
27 #define NULL_INPUT "NUL"
30 /****************************************************************/
31 /* static functions required for some tests */
33 valid_buffer(__rte_unused struct rdline *rdl,
34 __rte_unused const char *buf,
35 __rte_unused unsigned int size)
40 complete_buffer(__rte_unused struct rdline *rdl,
41 __rte_unused const char *buf,
42 __rte_unused char *dstbuf,
43 __rte_unused unsigned int dstsize,
44 __rte_unused int *state)
49 /****************************************************************/
52 test_cmdline_parse_fns(void)
55 cmdline_parse_ctx_t ctx;
57 char dst[CMDLINE_TEST_BUFSIZE];
59 cl = cmdline_new(&ctx, "prompt", -1, -1);
61 printf("Error: cannot create cmdline to test parse fns!\n");
65 if (cmdline_parse(NULL, "buffer") >= 0)
67 if (cmdline_parse(cl, NULL) >= 0)
70 if (cmdline_complete(NULL, "buffer", &i, dst, sizeof(dst)) >= 0)
72 if (cmdline_complete(cl, NULL, &i, dst, sizeof(dst)) >= 0)
74 if (cmdline_complete(cl, "buffer", NULL, dst, sizeof(dst)) >= 0)
76 if (cmdline_complete(cl, "buffer", &i, NULL, sizeof(dst)) >= 0)
83 printf("Error: function accepted null parameter!\n");
89 test_cmdline_rdline_fns(void)
92 rdline_write_char_t *wc = &cmdline_write_char;
93 rdline_validate_t *v = &valid_buffer;
94 rdline_complete_t *c = &complete_buffer;
96 rdl = rdline_new(NULL, v, c, NULL);
99 rdl = rdline_new(wc, NULL, c, NULL);
102 rdl = rdline_new(wc, v, NULL, NULL);
105 if (rdline_char_in(NULL, 0) >= 0)
107 if (rdline_get_buffer(NULL) != NULL)
109 if (rdline_add_history(NULL, "history") >= 0)
111 if (rdline_add_history(rdl, NULL) >= 0)
113 if (rdline_get_history_item(NULL, 0) != NULL)
117 rdline_get_history_buffer_size(NULL);
118 rdline_get_opaque(NULL);
119 rdline_newline(NULL, "prompt");
120 rdline_newline(rdl, NULL);
123 rdline_restart(NULL);
124 rdline_redisplay(NULL);
126 rdline_clear_history(NULL);
133 printf("Error: function accepted null parameter!\n");
139 test_cmdline_vt100_fns(void)
141 if (vt100_parser(NULL, 0) >= 0) {
142 printf("Error: function accepted null parameter!\n");
153 test_cmdline_socket_fns(void)
155 cmdline_parse_ctx_t ctx;
158 cl = cmdline_stdin_new(NULL, "prompt");
161 cl = cmdline_stdin_new(&ctx, NULL);
164 cl = cmdline_file_new(NULL, "prompt", NULL_INPUT);
167 cl = cmdline_file_new(&ctx, NULL, NULL_INPUT);
170 cl = cmdline_file_new(&ctx, "prompt", NULL);
173 cl = cmdline_file_new(&ctx, "prompt", "-/invalid/~/path");
175 printf("Error: succeeded in opening invalid file for reading!");
179 cl = cmdline_file_new(&ctx, "prompt", NULL_INPUT);
181 printf("Error: failed to open /dev/null for reading!");
188 cmdline_stdin_exit(NULL);
192 printf("Error: function accepted null parameter!\n");
198 test_cmdline_fns(void)
200 cmdline_parse_ctx_t ctx;
203 memset(&ctx, 0, sizeof(ctx));
204 cl = cmdline_new(NULL, "prompt", 0, 0);
207 cl = cmdline_new(&ctx, NULL, 0, 0);
210 cl = cmdline_new(&ctx, "test", -1, -1);
213 if (cmdline_in(NULL, "buffer", CMDLINE_TEST_BUFSIZE) >= 0)
215 if (cmdline_in(cl, NULL, CMDLINE_TEST_BUFSIZE) >= 0)
217 if (cmdline_write_char(NULL, 0) >= 0)
221 cmdline_set_prompt(NULL, "prompt");
223 cmdline_printf(NULL, "format");
224 cmdline_interact(NULL);
231 printf("Error: function accepted null parameter!\n");
237 /* test library functions. the point of these tests is not so much to test
238 * functions' behaviour as it is to make sure there are no segfaults if
239 * they are called with invalid parameters.
242 test_cmdline_lib(void)
244 if (test_cmdline_parse_fns() < 0)
246 if (test_cmdline_rdline_fns() < 0)
248 if (test_cmdline_vt100_fns() < 0)
250 if (test_cmdline_socket_fns() < 0)
252 if (test_cmdline_fns() < 0)