1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
11 #include <rte_eventdev.h>
13 #include "evt_options.h"
16 struct evt_options opt;
17 struct evt_test *test;
20 signal_handler(int signum)
25 if ((signum == SIGINT || signum == SIGTERM) && !once) {
27 printf("\nSignal %d received, preparing to exit...\n",
31 /* request all lcores to exit from the main loop */
32 *(int *)test->test_priv = true;
35 if (test->ops.ethdev_destroy)
36 test->ops.ethdev_destroy(test, &opt);
38 if (test->ops.cryptodev_destroy)
39 test->ops.cryptodev_destroy(test, &opt);
41 rte_eal_mp_wait_lcore();
43 if (test->ops.test_result)
44 test->ops.test_result(test, &opt);
46 if (opt.prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
47 RTE_ETH_FOREACH_DEV(i)
51 if (test->ops.eventdev_destroy)
52 test->ops.eventdev_destroy(test, &opt);
54 if (test->ops.mempool_destroy)
55 test->ops.mempool_destroy(test, &opt);
57 if (test->ops.test_destroy)
58 test->ops.test_destroy(test, &opt);
61 /* exit with the expected status */
62 signal(signum, SIG_DFL);
63 kill(getpid(), signum);
68 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
70 evt_options_dump(opts);
71 if (test->ops.opt_dump)
72 test->ops.opt_dump(opts);
76 main(int argc, char **argv)
81 signal(SIGINT, signal_handler);
82 signal(SIGTERM, signal_handler);
84 ret = rte_eal_init(argc, argv);
86 rte_panic("invalid EAL arguments\n");
90 evdevs = rte_event_dev_count();
92 rte_panic("no eventdev devices found\n");
94 /* Populate the default values of the options */
95 evt_options_default(&opt);
97 /* Parse the command line arguments */
98 ret = evt_options_parse(&opt, argc, argv);
100 evt_err("parsing one or more user options failed");
104 /* Get struct evt_test *test from name */
105 test = evt_test_get(opt.test_name);
107 evt_err("failed to find requested test: %s", opt.test_name);
111 if (test->ops.test_result == NULL) {
112 evt_err("%s: ops.test_result not found", opt.test_name);
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);
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);
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;
139 /* Dump the options */
140 if (opt.verbose_level)
141 evt_options_dump_all(test, &opt);
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);
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);
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;
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);
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;
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;
192 rte_eal_mp_wait_lcore();
194 /* Print the test result */
195 ret = test->ops.test_result(test, &opt);
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");
202 } else if (ret == EVT_TEST_UNSUPPORTED) {
203 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
208 if (test->ops.eventdev_destroy)
209 test->ops.eventdev_destroy(test, &opt);
212 if (test->ops.cryptodev_destroy)
213 test->ops.cryptodev_destroy(test, &opt);
216 if (test->ops.ethdev_destroy)
217 test->ops.ethdev_destroy(test, &opt);
220 if (test->ops.mempool_destroy)
221 test->ops.mempool_destroy(test, &opt);
224 if (test->ops.test_destroy)
225 test->ops.test_destroy(test, &opt);