1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
3 */
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <signal.h>
8
9 #include <rte_atomic.h>
10 #include <rte_debug.h>
11 #include <rte_eal.h>
12 #include <rte_eventdev.h>
13
14 #include "evt_options.h"
15 #include "evt_test.h"
16
17 struct evt_options opt;
18 struct evt_test *test;
19
20 static void
signal_handler(int signum)21 signal_handler(int signum)
22 {
23 int i;
24 static uint8_t once;
25
26 if ((signum == SIGINT || signum == SIGTERM) && !once) {
27 once = true;
28 printf("\nSignal %d received, preparing to exit...\n",
29 signum);
30
31 if (test != NULL) {
32 /* request all lcores to exit from the main loop */
33 *(int *)test->test_priv = true;
34 rte_wmb();
35
36 if (test->ops.ethdev_destroy)
37 test->ops.ethdev_destroy(test, &opt);
38
39 rte_eal_mp_wait_lcore();
40
41 if (test->ops.test_result)
42 test->ops.test_result(test, &opt);
43
44 if (opt.prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
45 RTE_ETH_FOREACH_DEV(i)
46 rte_eth_dev_close(i);
47 }
48
49 if (test->ops.eventdev_destroy)
50 test->ops.eventdev_destroy(test, &opt);
51
52 if (test->ops.mempool_destroy)
53 test->ops.mempool_destroy(test, &opt);
54
55 if (test->ops.test_destroy)
56 test->ops.test_destroy(test, &opt);
57 }
58
59 /* exit with the expected status */
60 signal(signum, SIG_DFL);
61 kill(getpid(), signum);
62 }
63 }
64
65 static inline void
evt_options_dump_all(struct evt_test * test,struct evt_options * opts)66 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
67 {
68 evt_options_dump(opts);
69 if (test->ops.opt_dump)
70 test->ops.opt_dump(opts);
71 }
72
73 int
main(int argc,char ** argv)74 main(int argc, char **argv)
75 {
76 uint8_t evdevs;
77 int ret;
78
79 signal(SIGINT, signal_handler);
80 signal(SIGTERM, signal_handler);
81
82 ret = rte_eal_init(argc, argv);
83 if (ret < 0)
84 rte_panic("invalid EAL arguments\n");
85 argc -= ret;
86 argv += ret;
87
88 evdevs = rte_event_dev_count();
89 if (!evdevs)
90 rte_panic("no eventdev devices found\n");
91
92 /* Populate the default values of the options */
93 evt_options_default(&opt);
94
95 /* Parse the command line arguments */
96 ret = evt_options_parse(&opt, argc, argv);
97 if (ret) {
98 evt_err("parsing on or more user options failed");
99 goto error;
100 }
101
102 /* Get struct evt_test *test from name */
103 test = evt_test_get(opt.test_name);
104 if (test == NULL) {
105 evt_err("failed to find requested test: %s", opt.test_name);
106 goto error;
107 }
108
109 if (test->ops.test_result == NULL) {
110 evt_err("%s: ops.test_result not found", opt.test_name);
111 goto error;
112 }
113
114 /* Verify the command line options */
115 if (opt.dev_id >= rte_event_dev_count()) {
116 evt_err("invalid event device %d", opt.dev_id);
117 goto error;
118 }
119 if (test->ops.opt_check) {
120 if (test->ops.opt_check(&opt)) {
121 evt_err("invalid command line argument");
122 evt_options_dump_all(test, &opt);
123 goto error;
124 }
125 }
126
127 /* Check the eventdev capability before proceeding */
128 if (test->ops.cap_check) {
129 if (test->ops.cap_check(&opt) == false) {
130 evt_info("unsupported test: %s", opt.test_name);
131 evt_options_dump_all(test, &opt);
132 ret = EVT_TEST_UNSUPPORTED;
133 goto nocap;
134 }
135 }
136
137 /* Dump the options */
138 if (opt.verbose_level)
139 evt_options_dump_all(test, &opt);
140
141 /* Test specific setup */
142 if (test->ops.test_setup) {
143 if (test->ops.test_setup(test, &opt)) {
144 evt_err("failed to setup test: %s", opt.test_name);
145 goto error;
146
147 }
148 }
149
150 /* Test specific mempool setup */
151 if (test->ops.mempool_setup) {
152 if (test->ops.mempool_setup(test, &opt)) {
153 evt_err("%s: mempool setup failed", opt.test_name);
154 goto test_destroy;
155 }
156 }
157
158 /* Test specific ethdev setup */
159 if (test->ops.ethdev_setup) {
160 if (test->ops.ethdev_setup(test, &opt)) {
161 evt_err("%s: ethdev setup failed", opt.test_name);
162 goto mempool_destroy;
163 }
164 }
165
166 /* Test specific eventdev setup */
167 if (test->ops.eventdev_setup) {
168 if (test->ops.eventdev_setup(test, &opt)) {
169 evt_err("%s: eventdev setup failed", opt.test_name);
170 goto ethdev_destroy;
171 }
172 }
173
174 /* Launch lcores */
175 if (test->ops.launch_lcores) {
176 if (test->ops.launch_lcores(test, &opt)) {
177 evt_err("%s: failed to launch lcores", opt.test_name);
178 goto eventdev_destroy;
179 }
180 }
181
182 rte_eal_mp_wait_lcore();
183
184 /* Print the test result */
185 ret = test->ops.test_result(test, &opt);
186 nocap:
187 if (ret == EVT_TEST_SUCCESS) {
188 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
189 } else if (ret == EVT_TEST_FAILED) {
190 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
191 return EXIT_FAILURE;
192 } else if (ret == EVT_TEST_UNSUPPORTED) {
193 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
194 }
195
196 return 0;
197 eventdev_destroy:
198 if (test->ops.eventdev_destroy)
199 test->ops.eventdev_destroy(test, &opt);
200
201 ethdev_destroy:
202 if (test->ops.ethdev_destroy)
203 test->ops.ethdev_destroy(test, &opt);
204
205 mempool_destroy:
206 if (test->ops.mempool_destroy)
207 test->ops.mempool_destroy(test, &opt);
208
209 test_destroy:
210 if (test->ops.test_destroy)
211 test->ops.test_destroy(test, &opt);
212 error:
213 return EXIT_FAILURE;
214 }
215