1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
9 #include <rte_atomic.h>
10 #include <rte_debug.h>
12 #include <rte_eventdev.h>
14 #include "evt_options.h"
17 struct evt_options opt;
18 struct evt_test *test;
21 signal_handler(int signum)
26 if ((signum == SIGINT || signum == SIGTERM) && !once) {
28 printf("\nSignal %d received, preparing to exit...\n",
32 /* request all lcores to exit from the main loop */
33 *(int *)test->test_priv = true;
36 if (test->ops.ethdev_destroy)
37 test->ops.ethdev_destroy(test, &opt);
39 rte_eal_mp_wait_lcore();
41 if (test->ops.test_result)
42 test->ops.test_result(test, &opt);
44 if (opt.prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
45 RTE_ETH_FOREACH_DEV(i)
49 if (test->ops.eventdev_destroy)
50 test->ops.eventdev_destroy(test, &opt);
52 if (test->ops.mempool_destroy)
53 test->ops.mempool_destroy(test, &opt);
55 if (test->ops.test_destroy)
56 test->ops.test_destroy(test, &opt);
59 /* exit with the expected status */
60 signal(signum, SIG_DFL);
61 kill(getpid(), signum);
66 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
68 evt_options_dump(opts);
69 if (test->ops.opt_dump)
70 test->ops.opt_dump(opts);
74 main(int argc, char **argv)
79 signal(SIGINT, signal_handler);
80 signal(SIGTERM, signal_handler);
82 ret = rte_eal_init(argc, argv);
84 rte_panic("invalid EAL arguments\n");
88 evdevs = rte_event_dev_count();
90 rte_panic("no eventdev devices found\n");
92 /* Populate the default values of the options */
93 evt_options_default(&opt);
95 /* Parse the command line arguments */
96 ret = evt_options_parse(&opt, argc, argv);
98 evt_err("parsing on or more user options failed");
102 /* Get struct evt_test *test from name */
103 test = evt_test_get(opt.test_name);
105 evt_err("failed to find requested test: %s", opt.test_name);
109 if (test->ops.test_result == NULL) {
110 evt_err("%s: ops.test_result not found", opt.test_name);
114 /* Verify the command line options */
115 if (opt.dev_id >= rte_event_dev_count()) {
116 evt_err("invalid event device %d", opt.dev_id);
119 if (test->ops.opt_check) {
120 if (test->ops.opt_check(&opt)) {
121 evt_err("invalid command line argument");
122 evt_options_dump_all(test, &opt);
127 /* Check the eventdev capability before proceeding */
128 if (test->ops.cap_check) {
129 if (test->ops.cap_check(&opt) == false) {
130 evt_info("unsupported test: %s", opt.test_name);
131 evt_options_dump_all(test, &opt);
132 ret = EVT_TEST_UNSUPPORTED;
137 /* Dump the options */
138 if (opt.verbose_level)
139 evt_options_dump_all(test, &opt);
141 /* Test specific setup */
142 if (test->ops.test_setup) {
143 if (test->ops.test_setup(test, &opt)) {
144 evt_err("failed to setup test: %s", opt.test_name);
150 /* Test specific mempool setup */
151 if (test->ops.mempool_setup) {
152 if (test->ops.mempool_setup(test, &opt)) {
153 evt_err("%s: mempool setup failed", opt.test_name);
158 /* Test specific ethdev setup */
159 if (test->ops.ethdev_setup) {
160 if (test->ops.ethdev_setup(test, &opt)) {
161 evt_err("%s: ethdev setup failed", opt.test_name);
162 goto mempool_destroy;
166 /* Test specific eventdev setup */
167 if (test->ops.eventdev_setup) {
168 if (test->ops.eventdev_setup(test, &opt)) {
169 evt_err("%s: eventdev setup failed", opt.test_name);
175 if (test->ops.launch_lcores) {
176 if (test->ops.launch_lcores(test, &opt)) {
177 evt_err("%s: failed to launch lcores", opt.test_name);
178 goto eventdev_destroy;
182 rte_eal_mp_wait_lcore();
184 /* Print the test result */
185 ret = test->ops.test_result(test, &opt);
187 if (ret == EVT_TEST_SUCCESS) {
188 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
189 } else if (ret == EVT_TEST_FAILED) {
190 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
192 } else if (ret == EVT_TEST_UNSUPPORTED) {
193 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
198 if (test->ops.eventdev_destroy)
199 test->ops.eventdev_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);