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 rte_eal_mp_wait_lcore();
40 if (test->ops.test_result)
41 test->ops.test_result(test, &opt);
43 if (opt.prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) {
44 RTE_ETH_FOREACH_DEV(i)
48 if (test->ops.eventdev_destroy)
49 test->ops.eventdev_destroy(test, &opt);
51 if (test->ops.mempool_destroy)
52 test->ops.mempool_destroy(test, &opt);
54 if (test->ops.test_destroy)
55 test->ops.test_destroy(test, &opt);
58 /* exit with the expected status */
59 signal(signum, SIG_DFL);
60 kill(getpid(), signum);
65 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
67 evt_options_dump(opts);
68 if (test->ops.opt_dump)
69 test->ops.opt_dump(opts);
73 main(int argc, char **argv)
78 signal(SIGINT, signal_handler);
79 signal(SIGTERM, signal_handler);
81 ret = rte_eal_init(argc, argv);
83 rte_panic("invalid EAL arguments\n");
87 evdevs = rte_event_dev_count();
89 rte_panic("no eventdev devices found\n");
91 /* Populate the default values of the options */
92 evt_options_default(&opt);
94 /* Parse the command line arguments */
95 ret = evt_options_parse(&opt, argc, argv);
97 evt_err("parsing one or more user options failed");
101 /* Get struct evt_test *test from name */
102 test = evt_test_get(opt.test_name);
104 evt_err("failed to find requested test: %s", opt.test_name);
108 if (test->ops.test_result == NULL) {
109 evt_err("%s: ops.test_result not found", opt.test_name);
113 /* Verify the command line options */
114 if (opt.dev_id >= rte_event_dev_count()) {
115 evt_err("invalid event device %d", opt.dev_id);
118 if (test->ops.opt_check) {
119 if (test->ops.opt_check(&opt)) {
120 evt_err("invalid command line argument");
121 evt_options_dump_all(test, &opt);
126 /* Check the eventdev capability before proceeding */
127 if (test->ops.cap_check) {
128 if (test->ops.cap_check(&opt) == false) {
129 evt_info("unsupported test: %s", opt.test_name);
130 evt_options_dump_all(test, &opt);
131 ret = EVT_TEST_UNSUPPORTED;
136 /* Dump the options */
137 if (opt.verbose_level)
138 evt_options_dump_all(test, &opt);
140 /* Test specific setup */
141 if (test->ops.test_setup) {
142 if (test->ops.test_setup(test, &opt)) {
143 evt_err("failed to setup test: %s", opt.test_name);
149 /* Test specific mempool setup */
150 if (test->ops.mempool_setup) {
151 if (test->ops.mempool_setup(test, &opt)) {
152 evt_err("%s: mempool setup failed", opt.test_name);
157 /* Test specific ethdev setup */
158 if (test->ops.ethdev_setup) {
159 if (test->ops.ethdev_setup(test, &opt)) {
160 evt_err("%s: ethdev setup failed", opt.test_name);
161 goto mempool_destroy;
165 /* Test specific eventdev setup */
166 if (test->ops.eventdev_setup) {
167 if (test->ops.eventdev_setup(test, &opt)) {
168 evt_err("%s: eventdev setup failed", opt.test_name);
174 if (test->ops.launch_lcores) {
175 if (test->ops.launch_lcores(test, &opt)) {
176 evt_err("%s: failed to launch lcores", opt.test_name);
177 goto eventdev_destroy;
181 rte_eal_mp_wait_lcore();
183 /* Print the test result */
184 ret = test->ops.test_result(test, &opt);
186 if (ret == EVT_TEST_SUCCESS) {
187 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
188 } else if (ret == EVT_TEST_FAILED) {
189 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
191 } else if (ret == EVT_TEST_UNSUPPORTED) {
192 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
197 if (test->ops.eventdev_destroy)
198 test->ops.eventdev_destroy(test, &opt);
201 if (test->ops.ethdev_destroy)
202 test->ops.ethdev_destroy(test, &opt);
205 if (test->ops.mempool_destroy)
206 test->ops.mempool_destroy(test, &opt);
209 if (test->ops.test_destroy)
210 test->ops.test_destroy(test, &opt);