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