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.eventdev_destroy)
33 test->ops.eventdev_destroy(test, &opt);
35 if (test->ops.ethdev_destroy)
36 test->ops.ethdev_destroy(test, &opt);
38 if (test->ops.mempool_destroy)
39 test->ops.mempool_destroy(test, &opt);
41 if (test->ops.test_destroy)
42 test->ops.test_destroy(test, &opt);
44 /* exit with the expected status */
45 signal(signum, SIG_DFL);
46 kill(getpid(), signum);
51 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
53 evt_options_dump(opts);
54 if (test->ops.opt_dump)
55 test->ops.opt_dump(opts);
59 main(int argc, char **argv)
64 signal(SIGINT, signal_handler);
65 signal(SIGTERM, signal_handler);
67 ret = rte_eal_init(argc, argv);
69 rte_panic("invalid EAL arguments\n");
73 evdevs = rte_event_dev_count();
75 rte_panic("no eventdev devices found\n");
77 /* Populate the default values of the options */
78 evt_options_default(&opt);
80 /* Parse the command line arguments */
81 ret = evt_options_parse(&opt, argc, argv);
83 evt_err("parsing on or more user options failed");
87 /* Get struct evt_test *test from name */
88 test = evt_test_get(opt.test_name);
90 evt_err("failed to find requested test: %s", opt.test_name);
94 if (test->ops.test_result == NULL) {
95 evt_err("%s: ops.test_result not found", opt.test_name);
99 /* Verify the command line options */
100 if (opt.dev_id >= rte_event_dev_count()) {
101 evt_err("invalid event device %d", opt.dev_id);
104 if (test->ops.opt_check) {
105 if (test->ops.opt_check(&opt)) {
106 evt_err("invalid command line argument");
107 evt_options_dump_all(test, &opt);
112 /* Check the eventdev capability before proceeding */
113 if (test->ops.cap_check) {
114 if (test->ops.cap_check(&opt) == false) {
115 evt_info("unsupported test: %s", opt.test_name);
116 evt_options_dump_all(test, &opt);
117 ret = EVT_TEST_UNSUPPORTED;
122 /* Dump the options */
123 if (opt.verbose_level)
124 evt_options_dump_all(test, &opt);
126 /* Test specific setup */
127 if (test->ops.test_setup) {
128 if (test->ops.test_setup(test, &opt)) {
129 evt_err("failed to setup test: %s", opt.test_name);
135 /* Test specific mempool setup */
136 if (test->ops.mempool_setup) {
137 if (test->ops.mempool_setup(test, &opt)) {
138 evt_err("%s: mempool setup failed", opt.test_name);
143 /* Test specific ethdev setup */
144 if (test->ops.ethdev_setup) {
145 if (test->ops.ethdev_setup(test, &opt)) {
146 evt_err("%s: ethdev setup failed", opt.test_name);
147 goto mempool_destroy;
151 /* Test specific eventdev setup */
152 if (test->ops.eventdev_setup) {
153 if (test->ops.eventdev_setup(test, &opt)) {
154 evt_err("%s: eventdev setup failed", opt.test_name);
160 if (test->ops.launch_lcores) {
161 if (test->ops.launch_lcores(test, &opt)) {
162 evt_err("%s: failed to launch lcores", opt.test_name);
163 goto eventdev_destroy;
167 rte_eal_mp_wait_lcore();
169 /* Print the test result */
170 ret = test->ops.test_result(test, &opt);
172 if (ret == EVT_TEST_SUCCESS) {
173 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
174 } else if (ret == EVT_TEST_FAILED) {
175 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
177 } else if (ret == EVT_TEST_UNSUPPORTED) {
178 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
183 if (test->ops.eventdev_destroy)
184 test->ops.eventdev_destroy(test, &opt);
187 if (test->ops.ethdev_destroy)
188 test->ops.ethdev_destroy(test, &opt);
191 if (test->ops.mempool_destroy)
192 test->ops.mempool_destroy(test, &opt);
195 if (test->ops.test_destroy)
196 test->ops.test_destroy(test, &opt);