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