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)
23 if (signum == SIGINT || signum == SIGTERM) {
24 printf("\nSignal %d received, preparing to exit...\n",
26 /* request all lcores to exit from the main loop */
27 *(int *)test->test_priv = true;
30 rte_eal_mp_wait_lcore();
32 if (test->ops.test_result)
33 test->ops.test_result(test, &opt);
35 if (test->ops.eventdev_destroy)
36 test->ops.eventdev_destroy(test, &opt);
38 if (test->ops.ethdev_destroy)
39 test->ops.ethdev_destroy(test, &opt);
41 if (test->ops.mempool_destroy)
42 test->ops.mempool_destroy(test, &opt);
44 if (test->ops.test_destroy)
45 test->ops.test_destroy(test, &opt);
47 /* exit with the expected status */
48 signal(signum, SIG_DFL);
49 kill(getpid(), signum);
54 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
56 evt_options_dump(opts);
57 if (test->ops.opt_dump)
58 test->ops.opt_dump(opts);
62 main(int argc, char **argv)
67 signal(SIGINT, signal_handler);
68 signal(SIGTERM, signal_handler);
70 ret = rte_eal_init(argc, argv);
72 rte_panic("invalid EAL arguments\n");
76 evdevs = rte_event_dev_count();
78 rte_panic("no eventdev devices found\n");
80 /* Populate the default values of the options */
81 evt_options_default(&opt);
83 /* Parse the command line arguments */
84 ret = evt_options_parse(&opt, argc, argv);
86 evt_err("parsing on or more user options failed");
90 /* Get struct evt_test *test from name */
91 test = evt_test_get(opt.test_name);
93 evt_err("failed to find requested test: %s", opt.test_name);
97 if (test->ops.test_result == NULL) {
98 evt_err("%s: ops.test_result not found", opt.test_name);
102 /* Verify the command line options */
103 if (opt.dev_id >= rte_event_dev_count()) {
104 evt_err("invalid event device %d", opt.dev_id);
107 if (test->ops.opt_check) {
108 if (test->ops.opt_check(&opt)) {
109 evt_err("invalid command line argument");
110 evt_options_dump_all(test, &opt);
115 /* Check the eventdev capability before proceeding */
116 if (test->ops.cap_check) {
117 if (test->ops.cap_check(&opt) == false) {
118 evt_info("unsupported test: %s", opt.test_name);
119 evt_options_dump_all(test, &opt);
120 ret = EVT_TEST_UNSUPPORTED;
125 /* Dump the options */
126 if (opt.verbose_level)
127 evt_options_dump_all(test, &opt);
129 /* Test specific setup */
130 if (test->ops.test_setup) {
131 if (test->ops.test_setup(test, &opt)) {
132 evt_err("failed to setup test: %s", opt.test_name);
138 /* Test specific mempool setup */
139 if (test->ops.mempool_setup) {
140 if (test->ops.mempool_setup(test, &opt)) {
141 evt_err("%s: mempool setup failed", opt.test_name);
146 /* Test specific ethdev setup */
147 if (test->ops.ethdev_setup) {
148 if (test->ops.ethdev_setup(test, &opt)) {
149 evt_err("%s: ethdev setup failed", opt.test_name);
150 goto mempool_destroy;
154 /* Test specific eventdev setup */
155 if (test->ops.eventdev_setup) {
156 if (test->ops.eventdev_setup(test, &opt)) {
157 evt_err("%s: eventdev setup failed", opt.test_name);
163 if (test->ops.launch_lcores) {
164 if (test->ops.launch_lcores(test, &opt)) {
165 evt_err("%s: failed to launch lcores", opt.test_name);
166 goto eventdev_destroy;
170 rte_eal_mp_wait_lcore();
172 /* Print the test result */
173 ret = test->ops.test_result(test, &opt);
175 if (ret == EVT_TEST_SUCCESS) {
176 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
177 } else if (ret == EVT_TEST_FAILED) {
178 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
180 } else if (ret == EVT_TEST_UNSUPPORTED) {
181 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
186 if (test->ops.eventdev_destroy)
187 test->ops.eventdev_destroy(test, &opt);
190 if (test->ops.ethdev_destroy)
191 test->ops.ethdev_destroy(test, &opt);
194 if (test->ops.mempool_destroy)
195 test->ops.mempool_destroy(test, &opt);
198 if (test->ops.test_destroy)
199 test->ops.test_destroy(test, &opt);