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 #define FOR_EACH_SUITE_TESTCASE(iter, suite, case) \
40 for (iter = 0, case = suite->unit_test_cases[0]; \
41 suite->unit_test_cases[iter].testcase; \
42 iter++, case = suite->unit_test_cases[iter])
44 const char *prgname; /* to be set to argv[0] */
46 static const char *recursive_call; /* used in linux for MP and other tests */
49 no_action(void){ return 0; }
52 do_recursive_call(void)
57 int (*action_fn)(void);
59 { "run_secondary_instances", test_mp_secondary },
62 { "run_pdump_server_tests", test_pdump },
65 { "test_missing_c_flag", no_action },
66 { "test_main_lcore_flag", no_action },
67 { "test_invalid_n_flag", no_action },
68 { "test_no_hpet_flag", no_action },
69 { "test_allow_flag", no_action },
70 { "test_invalid_b_flag", no_action },
71 { "test_invalid_vdev_flag", no_action },
72 { "test_invalid_r_flag", no_action },
73 { "test_misc_flags", no_action },
74 { "test_memory_flags", no_action },
75 { "test_file_prefix", no_action },
76 { "test_no_huge_flag", no_action },
78 { "timer_secondary_spawn_wait", test_timer_secondary },
82 if (recursive_call == NULL)
84 for (i = 0; i < RTE_DIM(actions); i++) {
85 if (strcmp(actions[i].env_var, recursive_call) == 0)
86 return (actions[i].action_fn)();
88 printf("ERROR - missing action to take for %s\n", recursive_call);
94 #define MAX_EXTRA_ARGS 32
97 main(int argc, char **argv)
99 #ifdef RTE_LIB_CMDLINE
101 char *tests[argc]; /* store an array of tests to run */
108 extra_args = getenv("DPDK_TEST_PARAMS");
109 if (extra_args != NULL && strlen(extra_args) > 0) {
111 char *eargv[MAX_EXTRA_ARGS];
116 RTE_LOG(INFO, APP, "Using additional DPDK_TEST_PARAMS: '%s'\n",
118 eargc = rte_strsplit(extra_args, strlen(extra_args),
119 eargv, MAX_EXTRA_ARGS, ' ');
121 /* merge argc/argv and the environment args */
122 all_argc = argc + eargc;
123 all_argv = malloc(sizeof(*all_argv) * (all_argc + 1));
124 if (all_argv == NULL) {
129 for (i = 0; i < argc; i++)
130 all_argv[i] = argv[i];
131 for (i = 0; i < eargc; i++)
132 all_argv[argc + i] = eargv[i];
133 all_argv[all_argc] = NULL;
135 /* call eal_init with combined args */
136 ret = rte_eal_init(all_argc, all_argv);
139 ret = rte_eal_init(argc, argv);
151 ret = rte_timer_subsystem_init();
152 if (ret < 0 && ret != -EALREADY) {
158 if (commands_init() < 0) {
163 recursive_call = getenv(RECURSIVE_ENV_VAR);
164 if (recursive_call != NULL) {
165 ret = do_recursive_call();
169 #ifdef RTE_LIBEAL_USE_HPET
170 if (rte_eal_hpet_init(1) < 0)
173 "HPET is not enabled, using TSC as default timer\n");
176 #ifdef RTE_LIB_CMDLINE
177 char *dpdk_test = getenv("DPDK_TEST");
179 if (dpdk_test && strlen(dpdk_test) == 0)
182 if (dpdk_test && !command_valid(dpdk_test)) {
183 RTE_LOG(WARNING, APP, "Invalid DPDK_TEST value '%s'\n", dpdk_test);
188 tests[test_count++] = dpdk_test;
189 for (i = 1; i < argc; i++) {
190 if (!command_valid(argv[i]))
191 RTE_LOG(WARNING, APP, "Invalid test requested: '%s'\n", argv[i]);
193 tests[test_count++] = argv[i];
196 if (test_count > 0) {
199 cl = cmdline_new(main_ctx, "RTE>>", 0, 1);
205 for (i = 0; i < test_count; i++) {
206 snprintf(buf, sizeof(buf), "%s\n", tests[i]);
207 if (cmdline_in(cl, buf, strlen(buf)) < 0) {
208 printf("error on cmdline input\n");
212 ret = last_test_result;
220 /* if no DPDK_TEST env variable, go interactive */
221 cl = cmdline_stdin_new(main_ctx, "RTE>>");
227 cmdline_interact(cl);
228 cmdline_stdin_exit(cl);
236 rte_timer_subsystem_finalize();
243 unit_test_suite_count_tcs_on_setup_fail(struct unit_test_suite *suite,
246 struct unit_test_case tc;
249 FOR_EACH_SUITE_TESTCASE(i, suite, tc) {
251 if (!tc.enabled || test_success == TEST_SKIPPED)
259 unit_test_suite_reset_counts(struct unit_test_suite *suite)
263 suite->succeeded = 0;
266 suite->unsupported = 0;
270 unit_test_suite_runner(struct unit_test_suite *suite)
274 struct unit_test_case tc;
276 unit_test_suite_reset_counts(suite);
278 if (suite->suite_name) {
279 printf(" + ------------------------------------------------------- +\n");
280 printf(" + Test Suite : %s\n", suite->suite_name);
284 test_success = suite->setup();
285 if (test_success != 0) {
287 * setup did not pass, so count all enabled tests and
288 * mark them as failed/skipped
290 unit_test_suite_count_tcs_on_setup_fail(suite,
296 printf(" + ------------------------------------------------------- +\n");
298 FOR_EACH_SUITE_TESTCASE(suite->total, suite, tc) {
306 /* run test case setup */
308 test_success = tc.setup();
310 test_success = TEST_SUCCESS;
312 if (test_success == TEST_SUCCESS) {
313 /* run the test case */
314 test_success = tc.testcase();
315 if (test_success == TEST_SUCCESS)
317 else if (test_success == TEST_SKIPPED)
319 else if (test_success == -ENOTSUP)
320 suite->unsupported++;
323 } else if (test_success == -ENOTSUP) {
324 suite->unsupported++;
329 /* run the test case teardown */
333 if (test_success == TEST_SUCCESS)
334 status = "succeeded";
335 else if (test_success == TEST_SKIPPED)
337 else if (test_success == -ENOTSUP)
338 status = "unsupported";
342 printf(" + TestCase [%2d] : %s %s\n", suite->total,
346 /* Run test suite teardown */
353 printf(" + ------------------------------------------------------- +\n");
354 printf(" + Test Suite Summary : %s\n", suite->suite_name);
355 printf(" + Tests Total : %2d\n", suite->total);
356 printf(" + Tests Skipped : %2d\n", suite->skipped);
357 printf(" + Tests Executed : %2d\n", suite->executed);
358 printf(" + Tests Unsupported: %2d\n", suite->unsupported);
359 printf(" + Tests Passed : %2d\n", suite->succeeded);
360 printf(" + Tests Failed : %2d\n", suite->failed);
361 printf(" + ------------------------------------------------------- +\n");
363 last_test_result = suite->failed;
367 if (suite->total == suite->skipped)