1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
15 #ifdef RTE_LIBRTE_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>
28 #ifdef RTE_LIBRTE_TIMER
29 #include <rte_timer.h>
34 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
36 const char *prgname; /* to be set to argv[0] */
38 static const char *recursive_call; /* used in linuxapp for MP and other tests */
41 no_action(void){ return 0; }
44 do_recursive_call(void)
49 int (*action_fn)(void);
51 { "run_secondary_instances", test_mp_secondary },
52 { "test_missing_c_flag", no_action },
53 { "test_master_lcore_flag", no_action },
54 { "test_invalid_n_flag", no_action },
55 { "test_no_hpet_flag", no_action },
56 { "test_whitelist_flag", no_action },
57 { "test_invalid_b_flag", no_action },
58 { "test_invalid_vdev_flag", no_action },
59 { "test_invalid_r_flag", no_action },
60 { "test_misc_flags", no_action },
61 { "test_memory_flags", no_action },
62 { "test_file_prefix", no_action },
63 { "test_no_huge_flag", no_action },
66 if (recursive_call == NULL)
68 for (i = 0; i < sizeof(actions)/sizeof(actions[0]); i++) {
69 if (strcmp(actions[i].env_var, recursive_call) == 0)
70 return (actions[i].action_fn)();
72 printf("ERROR - missing action to take for %s\n", recursive_call);
78 #define MAX_EXTRA_ARGS 32
81 main(int argc, char **argv)
83 #ifdef RTE_LIBRTE_CMDLINE
89 extra_args = getenv("DPDK_TEST_PARAMS");
90 if (extra_args != NULL && strlen(extra_args) > 0) {
92 char *eargv[MAX_EXTRA_ARGS];
97 RTE_LOG(INFO, APP, "Using additional DPDK_TEST_PARAMS: '%s'\n",
99 eargc = rte_strsplit(extra_args, strlen(extra_args),
100 eargv, MAX_EXTRA_ARGS, ' ');
102 /* merge argc/argv and the environment args */
103 all_argc = argc + eargc;
104 all_argv = malloc(sizeof(*all_argv) * (all_argc + 1));
105 if (all_argv == NULL) {
110 for (i = 0; i < argc; i++)
111 all_argv[i] = argv[i];
112 for (i = 0; i < eargc; i++)
113 all_argv[argc + i] = eargv[i];
114 all_argv[all_argc] = NULL;
116 /* call eal_init with combined args */
117 ret = rte_eal_init(all_argc, all_argv);
120 ret = rte_eal_init(argc, argv);
126 #ifdef RTE_LIBRTE_TIMER
127 rte_timer_subsystem_init();
130 if (commands_init() < 0) {
139 recursive_call = getenv(RECURSIVE_ENV_VAR);
140 if (recursive_call != NULL) {
141 ret = do_recursive_call();
145 #ifdef RTE_LIBEAL_USE_HPET
146 if (rte_eal_hpet_init(1) < 0)
149 "HPET is not enabled, using TSC as default timer\n");
152 #ifdef RTE_LIBRTE_CMDLINE
153 cl = cmdline_stdin_new(main_ctx, "RTE>>");
159 char *dpdk_test = getenv("DPDK_TEST");
160 if (dpdk_test && strlen(dpdk_test)) {
162 snprintf(buf, sizeof(buf), "%s\n", dpdk_test);
163 if (cmdline_in(cl, buf, strlen(buf)) < 0) {
164 printf("error on cmdline input\n");
169 cmdline_stdin_exit(cl);
170 ret = last_test_result;
173 /* if no DPDK_TEST env variable, go interactive */
174 cmdline_interact(cl);
175 cmdline_stdin_exit(cl);
186 unit_test_suite_runner(struct unit_test_suite *suite)
189 unsigned int total = 0, executed = 0, skipped = 0;
190 unsigned int succeeded = 0, failed = 0, unsupported = 0;
193 if (suite->suite_name) {
194 printf(" + ------------------------------------------------------- +\n");
195 printf(" + Test Suite : %s\n", suite->suite_name);
199 if (suite->setup() != 0) {
201 * setup failed, so count all enabled tests and mark
204 while (suite->unit_test_cases[total].testcase) {
205 if (!suite->unit_test_cases[total].enabled)
214 printf(" + ------------------------------------------------------- +\n");
216 while (suite->unit_test_cases[total].testcase) {
217 if (!suite->unit_test_cases[total].enabled) {
225 /* run test case setup */
226 if (suite->unit_test_cases[total].setup)
227 test_success = suite->unit_test_cases[total].setup();
229 test_success = TEST_SUCCESS;
231 if (test_success == TEST_SUCCESS) {
232 /* run the test case */
233 test_success = suite->unit_test_cases[total].testcase();
234 if (test_success == TEST_SUCCESS)
236 else if (test_success == -ENOTSUP)
240 } else if (test_success == -ENOTSUP) {
246 /* run the test case teardown */
247 if (suite->unit_test_cases[total].teardown)
248 suite->unit_test_cases[total].teardown();
250 if (test_success == TEST_SUCCESS)
251 status = "succeeded";
252 else if (test_success == -ENOTSUP)
253 status = "unsupported";
257 printf(" + TestCase [%2d] : %s %s\n", total,
258 suite->unit_test_cases[total].name, status);
263 /* Run test suite teardown */
270 printf(" + ------------------------------------------------------- +\n");
271 printf(" + Test Suite Summary \n");
272 printf(" + Tests Total : %2d\n", total);
273 printf(" + Tests Skipped : %2d\n", skipped);
274 printf(" + Tests Executed : %2d\n", executed);
275 printf(" + Tests Unsupported: %2d\n", unsupported);
276 printf(" + Tests Passed : %2d\n", succeeded);
277 printf(" + Tests Failed : %2d\n", failed);
278 printf(" + ------------------------------------------------------- +\n");
280 last_test_result = failed;