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