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