net/vmxnet3: remove useless copy when setting MAC address
[dpdk.git] / test / test / test.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
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>
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 },
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 },
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
76 int
77 main(int argc, char **argv)
78 {
79 #ifdef RTE_LIBRTE_CMDLINE
80         struct cmdline *cl;
81 #endif
82         int ret;
83
84         ret = rte_eal_init(argc, argv);
85         if (ret < 0)
86                 return -1;
87
88 #ifdef RTE_LIBRTE_TIMER
89         rte_timer_subsystem_init();
90 #endif
91
92         if (commands_init() < 0)
93                 return -1;
94
95         argv += ret;
96
97         prgname = argv[0];
98
99         if ((recursive_call = getenv(RECURSIVE_ENV_VAR)) != NULL)
100                 return do_recursive_call();
101
102 #ifdef RTE_LIBEAL_USE_HPET
103         if (rte_eal_hpet_init(1) < 0)
104 #endif
105                 RTE_LOG(INFO, APP,
106                                 "HPET is not enabled, using TSC as default timer\n");
107
108
109 #ifdef RTE_LIBRTE_CMDLINE
110         cl = cmdline_stdin_new(main_ctx, "RTE>>");
111         if (cl == NULL) {
112                 return -1;
113         }
114         cmdline_interact(cl);
115         cmdline_stdin_exit(cl);
116 #endif
117
118         return 0;
119 }
120
121
122 int
123 unit_test_suite_runner(struct unit_test_suite *suite)
124 {
125         int test_success;
126         unsigned int total = 0, executed = 0, skipped = 0;
127         unsigned int succeeded = 0, failed = 0, unsupported = 0;
128         const char *status;
129
130         if (suite->suite_name) {
131                 printf(" + ------------------------------------------------------- +\n");
132                 printf(" + Test Suite : %s\n", suite->suite_name);
133         }
134
135         if (suite->setup)
136                 if (suite->setup() != 0)
137                         goto suite_summary;
138
139         printf(" + ------------------------------------------------------- +\n");
140
141         while (suite->unit_test_cases[total].testcase) {
142                 if (!suite->unit_test_cases[total].enabled) {
143                         skipped++;
144                         total++;
145                         continue;
146                 } else {
147                         executed++;
148                 }
149
150                 /* run test case setup */
151                 if (suite->unit_test_cases[total].setup)
152                         test_success = suite->unit_test_cases[total].setup();
153                 else
154                         test_success = TEST_SUCCESS;
155
156                 if (test_success == TEST_SUCCESS) {
157                         /* run the test case */
158                         test_success = suite->unit_test_cases[total].testcase();
159                         if (test_success == TEST_SUCCESS)
160                                 succeeded++;
161                         else if (test_success == -ENOTSUP)
162                                 unsupported++;
163                         else
164                                 failed++;
165                 } else if (test_success == -ENOTSUP) {
166                         unsupported++;
167                 } else {
168                         failed++;
169                 }
170
171                 /* run the test case teardown */
172                 if (suite->unit_test_cases[total].teardown)
173                         suite->unit_test_cases[total].teardown();
174
175                 if (test_success == TEST_SUCCESS)
176                         status = "succeeded";
177                 else if (test_success == -ENOTSUP)
178                         status = "unsupported";
179                 else
180                         status = "failed";
181
182                 printf(" + TestCase [%2d] : %s %s\n", total,
183                                 suite->unit_test_cases[total].name, status);
184
185                 total++;
186         }
187
188         /* Run test suite teardown */
189         if (suite->teardown)
190                 suite->teardown();
191
192         goto suite_summary;
193
194 suite_summary:
195         printf(" + ------------------------------------------------------- +\n");
196         printf(" + Test Suite Summary \n");
197         printf(" + Tests Total :       %2d\n", total);
198         printf(" + Tests Skipped :     %2d\n", skipped);
199         printf(" + Tests Executed :    %2d\n", executed);
200         printf(" + Tests Unsupported:  %2d\n", unsupported);
201         printf(" + Tests Passed :      %2d\n", succeeded);
202         printf(" + Tests Failed :      %2d\n", failed);
203         printf(" + ------------------------------------------------------- +\n");
204
205         if (failed)
206                 return -1;
207
208         return 0;
209 }