1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
15 #ifdef RTE_LIB_CMDLINE
16 #include <cmdline_rdline.h>
17 #include <cmdline_parse.h>
18 #include <cmdline_socket.h>
20 extern cmdline_parse_ctx_t main_ctx[];
23 #include <rte_memory.h>
25 #include <rte_cycles.h>
27 #include <rte_string_fns.h>
29 #include <rte_timer.h>
34 #include "test_pdump.h"
37 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
39 const char *prgname; /* to be set to argv[0] */
41 static const char *recursive_call; /* used in linux for MP and other tests */
44 no_action(void){ return 0; }
47 do_recursive_call(void)
52 int (*action_fn)(void);
54 { "run_secondary_instances", test_mp_secondary },
57 { "run_pdump_server_tests", test_pdump },
60 { "test_missing_c_flag", no_action },
61 { "test_main_lcore_flag", no_action },
62 { "test_invalid_n_flag", no_action },
63 { "test_no_hpet_flag", no_action },
64 { "test_allow_flag", no_action },
65 { "test_invalid_b_flag", no_action },
66 { "test_invalid_vdev_flag", no_action },
67 { "test_invalid_r_flag", no_action },
68 { "test_misc_flags", no_action },
69 { "test_memory_flags", no_action },
70 { "test_file_prefix", no_action },
71 { "test_no_huge_flag", no_action },
73 { "timer_secondary_spawn_wait", test_timer_secondary },
77 if (recursive_call == NULL)
79 for (i = 0; i < RTE_DIM(actions); i++) {
80 if (strcmp(actions[i].env_var, recursive_call) == 0)
81 return (actions[i].action_fn)();
83 printf("ERROR - missing action to take for %s\n", recursive_call);
89 #define MAX_EXTRA_ARGS 32
92 main(int argc, char **argv)
94 #ifdef RTE_LIB_CMDLINE
100 extra_args = getenv("DPDK_TEST_PARAMS");
101 if (extra_args != NULL && strlen(extra_args) > 0) {
103 char *eargv[MAX_EXTRA_ARGS];
108 RTE_LOG(INFO, APP, "Using additional DPDK_TEST_PARAMS: '%s'\n",
110 eargc = rte_strsplit(extra_args, strlen(extra_args),
111 eargv, MAX_EXTRA_ARGS, ' ');
113 /* merge argc/argv and the environment args */
114 all_argc = argc + eargc;
115 all_argv = malloc(sizeof(*all_argv) * (all_argc + 1));
116 if (all_argv == NULL) {
121 for (i = 0; i < argc; i++)
122 all_argv[i] = argv[i];
123 for (i = 0; i < eargc; i++)
124 all_argv[argc + i] = eargv[i];
125 all_argv[all_argc] = NULL;
127 /* call eal_init with combined args */
128 ret = rte_eal_init(all_argc, all_argv);
131 ret = rte_eal_init(argc, argv);
138 if (rte_timer_subsystem_init() < 0) {
144 if (commands_init() < 0) {
153 recursive_call = getenv(RECURSIVE_ENV_VAR);
154 if (recursive_call != NULL) {
155 ret = do_recursive_call();
159 #ifdef RTE_LIBEAL_USE_HPET
160 if (rte_eal_hpet_init(1) < 0)
163 "HPET is not enabled, using TSC as default timer\n");
166 #ifdef RTE_LIB_CMDLINE
167 char *dpdk_test = getenv("DPDK_TEST");
168 if (dpdk_test && strlen(dpdk_test)) {
171 cl = cmdline_new(main_ctx, "RTE>>", 0, 1);
177 snprintf(buf, sizeof(buf), "%s\n", dpdk_test);
178 if (cmdline_in(cl, buf, strlen(buf)) < 0) {
179 printf("error on cmdline input\n");
183 ret = last_test_result;
188 /* if no DPDK_TEST env variable, go interactive */
189 cl = cmdline_stdin_new(main_ctx, "RTE>>");
195 cmdline_interact(cl);
196 cmdline_stdin_exit(cl);
204 rte_timer_subsystem_finalize();
212 unit_test_suite_runner(struct unit_test_suite *suite)
215 unsigned int total = 0, executed = 0, skipped = 0;
216 unsigned int succeeded = 0, failed = 0, unsupported = 0;
219 if (suite->suite_name) {
220 printf(" + ------------------------------------------------------- +\n");
221 printf(" + Test Suite : %s\n", suite->suite_name);
225 test_success = suite->setup();
226 if (test_success != 0) {
228 * setup did not pass, so count all enabled tests and
229 * mark them as failed/skipped
231 while (suite->unit_test_cases[total].testcase) {
232 if (!suite->unit_test_cases[total].enabled ||
233 test_success == TEST_SKIPPED)
243 printf(" + ------------------------------------------------------- +\n");
245 while (suite->unit_test_cases[total].testcase) {
246 if (!suite->unit_test_cases[total].enabled) {
254 /* run test case setup */
255 if (suite->unit_test_cases[total].setup)
256 test_success = suite->unit_test_cases[total].setup();
258 test_success = TEST_SUCCESS;
260 if (test_success == TEST_SUCCESS) {
261 /* run the test case */
262 test_success = suite->unit_test_cases[total].testcase();
263 if (test_success == TEST_SUCCESS)
265 else if (test_success == TEST_SKIPPED)
267 else if (test_success == -ENOTSUP)
271 } else if (test_success == -ENOTSUP) {
277 /* run the test case teardown */
278 if (suite->unit_test_cases[total].teardown)
279 suite->unit_test_cases[total].teardown();
281 if (test_success == TEST_SUCCESS)
282 status = "succeeded";
283 else if (test_success == TEST_SKIPPED)
285 else if (test_success == -ENOTSUP)
286 status = "unsupported";
290 printf(" + TestCase [%2d] : %s %s\n", total,
291 suite->unit_test_cases[total].name, status);
296 /* Run test suite teardown */
303 printf(" + ------------------------------------------------------- +\n");
304 printf(" + Test Suite Summary \n");
305 printf(" + Tests Total : %2d\n", total);
306 printf(" + Tests Skipped : %2d\n", skipped);
307 printf(" + Tests Executed : %2d\n", executed);
308 printf(" + Tests Unsupported: %2d\n", unsupported);
309 printf(" + Tests Passed : %2d\n", succeeded);
310 printf(" + Tests Failed : %2d\n", failed);
311 printf(" + ------------------------------------------------------- +\n");
313 last_test_result = failed;
317 if (total == skipped)