xref: /dpdk/app/test-eventdev/evt_main.c (revision da7e701151ea8b742d4c38ace3e4fefd1b4507fc)
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 		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
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
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 eventdev setup */
142 	if (test->ops.eventdev_setup) {
143 		if (test->ops.eventdev_setup(test, &opt)) {
144 			evt_err("%s: eventdev setup failed", opt.test_name);
145 			goto cryptodev_destroy;
146 		}
147 	}
148 
149 	/* Launch lcores */
150 	if (test->ops.launch_lcores) {
151 		if (test->ops.launch_lcores(test, &opt)) {
152 			evt_err("%s: failed to launch lcores", opt.test_name);
153 			goto eventdev_destroy;
154 		}
155 	}
156 
157 	if (test->ops.ethdev_rx_stop)
158 		test->ops.ethdev_rx_stop(test, &opt);
159 
160 	rte_eal_mp_wait_lcore();
161 
162 	if (test->ops.test_result)
163 		test->ops.test_result(test, &opt);
164 
165 	if (test->ops.ethdev_destroy)
166 		test->ops.ethdev_destroy(test, &opt);
167 
168 	if (test->ops.eventdev_destroy)
169 		test->ops.eventdev_destroy(test, &opt);
170 
171 	if (test->ops.cryptodev_destroy)
172 		test->ops.cryptodev_destroy(test, &opt);
173 
174 	if (test->ops.mempool_destroy)
175 		test->ops.mempool_destroy(test, &opt);
176 
177 	if (test->ops.test_destroy)
178 		test->ops.test_destroy(test, &opt);
179 
180 nocap:
181 	if (ret == EVT_TEST_SUCCESS) {
182 		printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
183 	} else if (ret == EVT_TEST_FAILED) {
184 		printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
185 		return EXIT_FAILURE;
186 	} else if (ret == EVT_TEST_UNSUPPORTED) {
187 		printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
188 	}
189 
190 	return 0;
191 eventdev_destroy:
192 	if (test->ops.eventdev_destroy)
193 		test->ops.eventdev_destroy(test, &opt);
194 
195 cryptodev_destroy:
196 	if (test->ops.cryptodev_destroy)
197 		test->ops.cryptodev_destroy(test, &opt);
198 
199 ethdev_destroy:
200 	if (test->ops.ethdev_destroy)
201 		test->ops.ethdev_destroy(test, &opt);
202 
203 mempool_destroy:
204 	if (test->ops.mempool_destroy)
205 		test->ops.mempool_destroy(test, &opt);
206 
207 test_destroy:
208 	if (test->ops.test_destroy)
209 		test->ops.test_destroy(test, &opt);
210 error:
211 	return EXIT_FAILURE;
212 }
213