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