1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #ifdef RTE_LIB_CMDLINE
15 #include <cmdline_rdline.h>
16 #include <cmdline_parse.h>
17 #include <cmdline_socket.h>
19 extern cmdline_parse_ctx_t main_ctx[];
22 #include <rte_memory.h>
24 #include <rte_cycles.h>
26 #include <rte_string_fns.h>
28 #include <rte_timer.h>
33 #include "test_pdump.h"
36 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
38 #define FOR_EACH_SUITE_TESTCASE(iter, suite, case) \
39 for (iter = 0, case = suite->unit_test_cases[0]; \
40 suite->unit_test_cases[iter].testcase || \
41 suite->unit_test_cases[iter].testcase_with_data; \
42 iter++, case = suite->unit_test_cases[iter])
44 #define FOR_EACH_SUITE_TESTSUITE(iter, suite, sub_ts) \
45 for (iter = 0, sub_ts = suite->unit_test_suites ? \
46 suite->unit_test_suites[0]:NULL; sub_ts && \
47 suite->unit_test_suites[iter]->suite_name != NULL; \
48 iter++, sub_ts = suite->unit_test_suites[iter])
50 const char *prgname; /* to be set to argv[0] */
52 static const char *recursive_call; /* used in linux for MP and other tests */
55 no_action(void){ return 0; }
58 do_recursive_call(void)
63 int (*action_fn)(void);
65 #ifndef RTE_EXEC_ENV_WINDOWS
66 { "run_secondary_instances", test_mp_secondary },
70 { "run_pdump_server_tests", test_pdump },
73 { "test_missing_c_flag", no_action },
74 { "test_main_lcore_flag", no_action },
75 { "test_invalid_n_flag", no_action },
76 { "test_no_hpet_flag", no_action },
77 { "test_allow_flag", no_action },
78 { "test_invalid_b_flag", no_action },
79 { "test_invalid_vdev_flag", no_action },
80 { "test_invalid_r_flag", no_action },
81 { "test_misc_flags", no_action },
82 { "test_memory_flags", no_action },
83 { "test_file_prefix", no_action },
84 { "test_no_huge_flag", no_action },
86 #ifndef RTE_EXEC_ENV_WINDOWS
87 { "timer_secondary_spawn_wait", test_timer_secondary },
92 if (recursive_call == NULL)
94 for (i = 0; i < RTE_DIM(actions); i++) {
95 if (strcmp(actions[i].env_var, recursive_call) == 0)
96 return (actions[i].action_fn)();
98 printf("ERROR - missing action to take for %s\n", recursive_call);
102 int last_test_result;
104 #define MAX_EXTRA_ARGS 32
107 main(int argc, char **argv)
109 #ifdef RTE_LIB_CMDLINE
111 char *tests[argc]; /* store an array of tests to run */
118 extra_args = getenv("DPDK_TEST_PARAMS");
119 if (extra_args != NULL && strlen(extra_args) > 0) {
121 char *eargv[MAX_EXTRA_ARGS];
126 RTE_LOG(INFO, APP, "Using additional DPDK_TEST_PARAMS: '%s'\n",
128 eargc = rte_strsplit(extra_args, strlen(extra_args),
129 eargv, MAX_EXTRA_ARGS, ' ');
131 /* merge argc/argv and the environment args */
132 all_argc = argc + eargc;
133 all_argv = malloc(sizeof(*all_argv) * (all_argc + 1));
134 if (all_argv == NULL) {
139 for (i = 0; i < argc; i++)
140 all_argv[i] = argv[i];
141 for (i = 0; i < eargc; i++)
142 all_argv[argc + i] = eargv[i];
143 all_argv[all_argc] = NULL;
145 /* call eal_init with combined args */
146 ret = rte_eal_init(all_argc, all_argv);
149 ret = rte_eal_init(argc, argv);
161 ret = rte_timer_subsystem_init();
162 if (ret < 0 && ret != -EALREADY) {
168 if (commands_init() < 0) {
173 recursive_call = getenv(RECURSIVE_ENV_VAR);
174 if (recursive_call != NULL) {
175 ret = do_recursive_call();
179 #ifdef RTE_LIBEAL_USE_HPET
180 if (rte_eal_hpet_init(1) < 0)
183 "HPET is not enabled, using TSC as default timer\n");
186 #ifdef RTE_LIB_CMDLINE
187 char *dpdk_test = getenv("DPDK_TEST");
189 if (dpdk_test && strlen(dpdk_test) == 0)
192 if (dpdk_test && !command_valid(dpdk_test)) {
193 RTE_LOG(WARNING, APP, "Invalid DPDK_TEST value '%s'\n", dpdk_test);
198 tests[test_count++] = dpdk_test;
199 for (i = 1; i < argc; i++) {
200 if (!command_valid(argv[i]))
201 RTE_LOG(WARNING, APP, "Invalid test requested: '%s'\n", argv[i]);
203 tests[test_count++] = argv[i];
206 if (test_count > 0) {
209 cl = cmdline_new(main_ctx, "RTE>>", 0, 1);
215 for (i = 0; i < test_count; i++) {
216 snprintf(buf, sizeof(buf), "%s\n", tests[i]);
217 if (cmdline_in(cl, buf, strlen(buf)) < 0) {
218 printf("error on cmdline input\n");
222 ret = last_test_result;
230 /* if no DPDK_TEST env variable, go interactive */
231 cl = cmdline_stdin_new(main_ctx, "RTE>>");
237 cmdline_interact(cl);
238 cmdline_stdin_exit(cl);
245 rte_timer_subsystem_finalize();
252 unit_test_suite_count_tcs_on_setup_fail(struct unit_test_suite *suite,
253 int test_success, unsigned int *sub_ts_failed,
254 unsigned int *sub_ts_skipped, unsigned int *sub_ts_total)
256 struct unit_test_case tc;
257 struct unit_test_suite *ts;
260 FOR_EACH_SUITE_TESTSUITE(i, suite, ts) {
261 unit_test_suite_count_tcs_on_setup_fail(
262 ts, test_success, sub_ts_failed,
263 sub_ts_skipped, sub_ts_total);
264 suite->total += ts->total;
265 suite->failed += ts->failed;
266 suite->skipped += ts->skipped;
273 FOR_EACH_SUITE_TESTCASE(i, suite, tc) {
275 if (!tc.enabled || test_success == TEST_SKIPPED)
283 unit_test_suite_reset_counts(struct unit_test_suite *suite)
285 struct unit_test_suite *ts;
288 FOR_EACH_SUITE_TESTSUITE(i, suite, ts)
289 unit_test_suite_reset_counts(ts);
292 suite->succeeded = 0;
295 suite->unsupported = 0;
299 unit_test_suite_runner(struct unit_test_suite *suite)
301 int test_success, i, ret;
303 struct unit_test_case tc;
304 struct unit_test_suite *ts;
305 unsigned int sub_ts_succeeded = 0, sub_ts_failed = 0;
306 unsigned int sub_ts_skipped = 0, sub_ts_total = 0;
308 unit_test_suite_reset_counts(suite);
310 if (suite->suite_name) {
311 printf(" + ------------------------------------------------------- +\n");
312 printf(" + Test Suite : %s\n", suite->suite_name);
316 test_success = suite->setup();
317 if (test_success != 0) {
319 * setup did not pass, so count all enabled tests and
320 * mark them as failed/skipped
322 unit_test_suite_count_tcs_on_setup_fail(suite,
323 test_success, &sub_ts_failed,
324 &sub_ts_skipped, &sub_ts_total);
329 printf(" + ------------------------------------------------------- +\n");
331 FOR_EACH_SUITE_TESTCASE(suite->total, suite, tc) {
339 /* run test case setup */
341 test_success = tc.setup();
343 test_success = TEST_SUCCESS;
345 if (test_success == TEST_SUCCESS) {
346 /* run the test case */
348 test_success = tc.testcase();
349 else if (tc.testcase_with_data)
350 test_success = tc.testcase_with_data(tc.data);
352 test_success = -ENOTSUP;
354 if (test_success == TEST_SUCCESS)
356 else if (test_success == TEST_SKIPPED)
358 else if (test_success == -ENOTSUP)
359 suite->unsupported++;
362 } else if (test_success == -ENOTSUP) {
363 suite->unsupported++;
368 /* run the test case teardown */
372 if (test_success == TEST_SUCCESS)
373 status = "succeeded";
374 else if (test_success == TEST_SKIPPED)
376 else if (test_success == -ENOTSUP)
377 status = "unsupported";
381 printf(" + TestCase [%2d] : %s %s\n", suite->total,
384 FOR_EACH_SUITE_TESTSUITE(i, suite, ts) {
385 ret = unit_test_suite_runner(ts);
386 if (ret == TEST_SUCCESS)
388 else if (ret == TEST_SKIPPED)
394 suite->total += ts->total;
395 suite->succeeded += ts->succeeded;
396 suite->failed += ts->failed;
397 suite->skipped += ts->skipped;
398 suite->unsupported += ts->unsupported;
399 suite->executed += ts->executed;
402 /* Run test suite teardown */
409 printf(" + ------------------------------------------------------- +\n");
410 printf(" + Test Suite Summary : %s\n", suite->suite_name);
411 printf(" + ------------------------------------------------------- +\n");
413 FOR_EACH_SUITE_TESTSUITE(i, suite, ts)
414 printf(" + %s : %d/%d passed, %d/%d skipped, "
415 "%d/%d failed, %d/%d unsupported\n", ts->suite_name,
416 ts->succeeded, ts->total, ts->skipped, ts->total,
417 ts->failed, ts->total, ts->unsupported, ts->total);
419 if (suite->unit_test_suites) {
420 printf(" + ------------------------------------------------------- +\n");
421 printf(" + Sub Testsuites Total : %2d\n", sub_ts_total);
422 printf(" + Sub Testsuites Skipped : %2d\n", sub_ts_skipped);
423 printf(" + Sub Testsuites Passed : %2d\n", sub_ts_succeeded);
424 printf(" + Sub Testsuites Failed : %2d\n", sub_ts_failed);
425 printf(" + ------------------------------------------------------- +\n");
428 printf(" + Tests Total : %2d\n", suite->total);
429 printf(" + Tests Skipped : %2d\n", suite->skipped);
430 printf(" + Tests Executed : %2d\n", suite->executed);
431 printf(" + Tests Unsupported: %2d\n", suite->unsupported);
432 printf(" + Tests Passed : %2d\n", suite->succeeded);
433 printf(" + Tests Failed : %2d\n", suite->failed);
434 printf(" + ------------------------------------------------------- +\n");
436 last_test_result = suite->failed;
440 if (suite->total == suite->skipped)