]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | /* SPDX-License-Identifier: BSD-3-Clause |
2 | * Copyright(c) 2010-2014 Intel Corporation | |
7c673cae FG |
3 | */ |
4 | ||
5 | #include <string.h> | |
6 | #include <stdio.h> | |
7 | #include <stdint.h> | |
8 | #include <stdarg.h> | |
9 | #include <stdlib.h> | |
10 | #include <errno.h> | |
11 | #include <termios.h> | |
12 | #include <ctype.h> | |
13 | #include <sys/queue.h> | |
14 | ||
15 | #ifdef RTE_LIBRTE_CMDLINE | |
16 | #include <cmdline_rdline.h> | |
17 | #include <cmdline_parse.h> | |
18 | #include <cmdline_socket.h> | |
19 | #include <cmdline.h> | |
20 | extern cmdline_parse_ctx_t main_ctx[]; | |
21 | #endif | |
22 | ||
23 | #include <rte_memory.h> | |
7c673cae FG |
24 | #include <rte_eal.h> |
25 | #include <rte_cycles.h> | |
26 | #include <rte_log.h> | |
27 | #include <rte_string_fns.h> | |
28 | #ifdef RTE_LIBRTE_TIMER | |
29 | #include <rte_timer.h> | |
30 | #endif | |
31 | ||
32 | #include "test.h" | |
33 | ||
34 | #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 | |
35 | ||
36 | const char *prgname; /* to be set to argv[0] */ | |
37 | ||
38 | static const char *recursive_call; /* used in linuxapp for MP and other tests */ | |
39 | ||
40 | static int | |
41 | no_action(void){ return 0; } | |
42 | ||
43 | static int | |
44 | do_recursive_call(void) | |
45 | { | |
46 | unsigned i; | |
47 | struct { | |
48 | const char *env_var; | |
49 | int (*action_fn)(void); | |
50 | } actions[] = { | |
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 }, | |
7c673cae | 60 | { "test_misc_flags", no_action }, |
7c673cae FG |
61 | { "test_memory_flags", no_action }, |
62 | { "test_file_prefix", no_action }, | |
63 | { "test_no_huge_flag", no_action }, | |
64 | }; | |
65 | ||
66 | if (recursive_call == NULL) | |
67 | return -1; | |
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)(); | |
71 | } | |
72 | printf("ERROR - missing action to take for %s\n", recursive_call); | |
73 | return -1; | |
74 | } | |
75 | ||
11fdf7f2 TL |
76 | int last_test_result; |
77 | ||
7c673cae FG |
78 | int |
79 | main(int argc, char **argv) | |
80 | { | |
81 | #ifdef RTE_LIBRTE_CMDLINE | |
82 | struct cmdline *cl; | |
83 | #endif | |
84 | int ret; | |
85 | ||
86 | ret = rte_eal_init(argc, argv); | |
87 | if (ret < 0) | |
88 | return -1; | |
89 | ||
90 | #ifdef RTE_LIBRTE_TIMER | |
91 | rte_timer_subsystem_init(); | |
92 | #endif | |
93 | ||
94 | if (commands_init() < 0) | |
95 | return -1; | |
96 | ||
97 | argv += ret; | |
98 | ||
99 | prgname = argv[0]; | |
100 | ||
101 | if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL) | |
102 | return do_recursive_call(); | |
103 | ||
104 | #ifdef RTE_LIBEAL_USE_HPET | |
105 | if (rte_eal_hpet_init(1) < 0) | |
106 | #endif | |
107 | RTE_LOG(INFO, APP, | |
108 | "HPET is not enabled, using TSC as default timer\n"); | |
109 | ||
110 | ||
111 | #ifdef RTE_LIBRTE_CMDLINE | |
112 | cl = cmdline_stdin_new(main_ctx, "RTE>>"); | |
113 | if (cl == NULL) { | |
114 | return -1; | |
115 | } | |
11fdf7f2 TL |
116 | |
117 | char *dpdk_test = getenv("DPDK_TEST"); | |
118 | if (dpdk_test && strlen(dpdk_test)) { | |
119 | char buf[1024]; | |
120 | snprintf(buf, sizeof(buf), "%s\n", dpdk_test); | |
121 | if (cmdline_in(cl, buf, strlen(buf)) < 0) { | |
122 | printf("error on cmdline input\n"); | |
123 | return -1; | |
124 | } | |
125 | ||
126 | cmdline_stdin_exit(cl); | |
127 | return last_test_result; | |
128 | } | |
129 | /* if no DPDK_TEST env variable, go interactive */ | |
7c673cae FG |
130 | cmdline_interact(cl); |
131 | cmdline_stdin_exit(cl); | |
132 | #endif | |
133 | ||
134 | return 0; | |
135 | } | |
136 | ||
137 | ||
138 | int | |
139 | unit_test_suite_runner(struct unit_test_suite *suite) | |
140 | { | |
141 | int test_success; | |
11fdf7f2 TL |
142 | unsigned int total = 0, executed = 0, skipped = 0; |
143 | unsigned int succeeded = 0, failed = 0, unsupported = 0; | |
144 | const char *status; | |
7c673cae FG |
145 | |
146 | if (suite->suite_name) { | |
147 | printf(" + ------------------------------------------------------- +\n"); | |
148 | printf(" + Test Suite : %s\n", suite->suite_name); | |
149 | } | |
150 | ||
151 | if (suite->setup) | |
11fdf7f2 TL |
152 | if (suite->setup() != 0) { |
153 | /* | |
154 | * setup failed, so count all enabled tests and mark | |
155 | * them as failed | |
156 | */ | |
157 | while (suite->unit_test_cases[total].testcase) { | |
158 | if (!suite->unit_test_cases[total].enabled) | |
159 | skipped++; | |
160 | else | |
161 | failed++; | |
162 | total++; | |
163 | } | |
7c673cae | 164 | goto suite_summary; |
11fdf7f2 | 165 | } |
7c673cae FG |
166 | |
167 | printf(" + ------------------------------------------------------- +\n"); | |
168 | ||
169 | while (suite->unit_test_cases[total].testcase) { | |
170 | if (!suite->unit_test_cases[total].enabled) { | |
171 | skipped++; | |
172 | total++; | |
173 | continue; | |
174 | } else { | |
175 | executed++; | |
176 | } | |
177 | ||
178 | /* run test case setup */ | |
179 | if (suite->unit_test_cases[total].setup) | |
180 | test_success = suite->unit_test_cases[total].setup(); | |
181 | else | |
182 | test_success = TEST_SUCCESS; | |
183 | ||
184 | if (test_success == TEST_SUCCESS) { | |
185 | /* run the test case */ | |
186 | test_success = suite->unit_test_cases[total].testcase(); | |
187 | if (test_success == TEST_SUCCESS) | |
188 | succeeded++; | |
11fdf7f2 TL |
189 | else if (test_success == -ENOTSUP) |
190 | unsupported++; | |
7c673cae FG |
191 | else |
192 | failed++; | |
11fdf7f2 TL |
193 | } else if (test_success == -ENOTSUP) { |
194 | unsupported++; | |
7c673cae FG |
195 | } else { |
196 | failed++; | |
197 | } | |
198 | ||
199 | /* run the test case teardown */ | |
200 | if (suite->unit_test_cases[total].teardown) | |
201 | suite->unit_test_cases[total].teardown(); | |
202 | ||
203 | if (test_success == TEST_SUCCESS) | |
11fdf7f2 TL |
204 | status = "succeeded"; |
205 | else if (test_success == -ENOTSUP) | |
206 | status = "unsupported"; | |
7c673cae | 207 | else |
11fdf7f2 TL |
208 | status = "failed"; |
209 | ||
210 | printf(" + TestCase [%2d] : %s %s\n", total, | |
211 | suite->unit_test_cases[total].name, status); | |
7c673cae FG |
212 | |
213 | total++; | |
214 | } | |
215 | ||
216 | /* Run test suite teardown */ | |
217 | if (suite->teardown) | |
218 | suite->teardown(); | |
219 | ||
220 | goto suite_summary; | |
221 | ||
222 | suite_summary: | |
223 | printf(" + ------------------------------------------------------- +\n"); | |
224 | printf(" + Test Suite Summary \n"); | |
225 | printf(" + Tests Total : %2d\n", total); | |
226 | printf(" + Tests Skipped : %2d\n", skipped); | |
227 | printf(" + Tests Executed : %2d\n", executed); | |
11fdf7f2 | 228 | printf(" + Tests Unsupported: %2d\n", unsupported); |
7c673cae FG |
229 | printf(" + Tests Passed : %2d\n", succeeded); |
230 | printf(" + Tests Failed : %2d\n", failed); | |
231 | printf(" + ------------------------------------------------------- +\n"); | |
232 | ||
11fdf7f2 TL |
233 | last_test_result = failed; |
234 | ||
7c673cae FG |
235 | if (failed) |
236 | return -1; | |
237 | ||
238 | return 0; | |
239 | } |