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)
22 if (signum == SIGINT || signum == SIGTERM) {
23 printf("\nSignal %d received, preparing to exit...\n",
27 /* request all lcores to exit from the main loop */
28 *(int *)test->test_priv = true;
35 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
37 evt_options_dump(opts);
38 if (test->ops.opt_dump)
39 test->ops.opt_dump(opts);
43 main(int argc, char **argv)
48 signal(SIGINT, signal_handler);
49 signal(SIGTERM, signal_handler);
51 ret = rte_eal_init(argc, argv);
53 rte_panic("invalid EAL arguments\n");
57 evdevs = rte_event_dev_count();
59 rte_panic("no eventdev devices found\n");
61 /* Populate the default values of the options */
62 evt_options_default(&opt);
64 /* Parse the command line arguments */
65 ret = evt_options_parse(&opt, argc, argv);
67 evt_err("parsing one or more user options failed");
71 /* Get struct evt_test *test from name */
72 test = evt_test_get(opt.test_name);
74 evt_err("failed to find requested test: %s", opt.test_name);
78 if (test->ops.test_result == NULL) {
79 evt_err("%s: ops.test_result not found", opt.test_name);
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);
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);
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;
106 /* Dump the options */
107 if (opt.verbose_level)
108 evt_options_dump_all(test, &opt);
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);
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);
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;
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);
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;
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;
159 if (test->ops.ethdev_rx_stop)
160 test->ops.ethdev_rx_stop(test, &opt);
162 if (test->ops.cryptodev_destroy)
163 test->ops.cryptodev_destroy(test, &opt);
165 rte_eal_mp_wait_lcore();
167 if (test->ops.test_result)
168 test->ops.test_result(test, &opt);
170 if (test->ops.ethdev_destroy)
171 test->ops.ethdev_destroy(test, &opt);
173 if (test->ops.eventdev_destroy)
174 test->ops.eventdev_destroy(test, &opt);
176 if (test->ops.mempool_destroy)
177 test->ops.mempool_destroy(test, &opt);
179 if (test->ops.test_destroy)
180 test->ops.test_destroy(test, &opt);
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");
188 } else if (ret == EVT_TEST_UNSUPPORTED) {
189 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
194 if (test->ops.eventdev_destroy)
195 test->ops.eventdev_destroy(test, &opt);
198 if (test->ops.cryptodev_destroy)
199 test->ops.cryptodev_destroy(test, &opt);
202 if (test->ops.ethdev_destroy)
203 test->ops.ethdev_destroy(test, &opt);
206 if (test->ops.mempool_destroy)
207 test->ops.mempool_destroy(test, &opt);
210 if (test->ops.test_destroy)
211 test->ops.test_destroy(test, &opt);