4 * Copyright (C) Cavium 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_debug.h>
39 #include <rte_eventdev.h>
41 #include "evt_options.h"
44 struct evt_options opt;
45 struct evt_test *test;
49 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
51 evt_options_dump(opts);
52 if (test->ops.opt_dump)
53 test->ops.opt_dump(opts);
57 main(int argc, char **argv)
62 ret = rte_eal_init(argc, argv);
64 rte_panic("invalid EAL arguments\n");
68 evdevs = rte_event_dev_count();
70 rte_panic("no eventdev devices found\n");
72 /* Populate the default values of the options */
73 evt_options_default(&opt);
75 /* Parse the command line arguments */
76 ret = evt_options_parse(&opt, argc, argv);
78 evt_err("parsing on or more user options failed");
82 /* Get struct evt_test *test from name */
83 test = evt_test_get(opt.test_name);
85 evt_err("failed to find requested test: %s", opt.test_name);
89 if (test->ops.test_result == NULL) {
90 evt_err("%s: ops.test_result not found", opt.test_name);
94 /* Verify the command line options */
95 if (opt.dev_id >= rte_event_dev_count()) {
96 evt_err("invalid event device %d", opt.dev_id);
99 if (test->ops.opt_check) {
100 if (test->ops.opt_check(&opt)) {
101 evt_err("invalid command line argument");
102 evt_options_dump_all(test, &opt);
107 /* Check the eventdev capability before proceeding */
108 if (test->ops.cap_check) {
109 if (test->ops.cap_check(&opt) == false) {
110 evt_info("unsupported test: %s", opt.test_name);
111 evt_options_dump_all(test, &opt);
112 ret = EVT_TEST_UNSUPPORTED;
117 /* Dump the options */
118 if (opt.verbose_level)
119 evt_options_dump_all(test, &opt);
121 /* Test specific setup */
122 if (test->ops.test_setup) {
123 if (test->ops.test_setup(test, &opt)) {
124 evt_err("failed to setup test: %s", opt.test_name);
130 /* Test specific mempool setup */
131 if (test->ops.mempool_setup) {
132 if (test->ops.mempool_setup(test, &opt)) {
133 evt_err("%s: mempool setup failed", opt.test_name);
138 /* Test specific ethdev setup */
139 if (test->ops.ethdev_setup) {
140 if (test->ops.ethdev_setup(test, &opt)) {
141 evt_err("%s: ethdev setup failed", opt.test_name);
142 goto mempool_destroy;
146 /* Test specific eventdev setup */
147 if (test->ops.eventdev_setup) {
148 if (test->ops.eventdev_setup(test, &opt)) {
149 evt_err("%s: eventdev setup failed", opt.test_name);
155 if (test->ops.launch_lcores) {
156 if (test->ops.launch_lcores(test, &opt)) {
157 evt_err("%s: failed to launch lcores", opt.test_name);
158 goto eventdev_destroy;
162 rte_eal_mp_wait_lcore();
164 /* Print the test result */
165 ret = test->ops.test_result(test, &opt);
167 if (ret == EVT_TEST_SUCCESS) {
168 printf("Result: "CLGRN"%s"CLNRM"\n", "Success");
169 } else if (ret == EVT_TEST_FAILED) {
170 printf("Result: "CLRED"%s"CLNRM"\n", "Failed");
172 } else if (ret == EVT_TEST_UNSUPPORTED) {
173 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
178 if (test->ops.eventdev_destroy)
179 test->ops.eventdev_destroy(test, &opt);
182 if (test->ops.ethdev_destroy)
183 test->ops.ethdev_destroy(test, &opt);
186 if (test->ops.mempool_destroy)
187 test->ops.mempool_destroy(test, &opt);
190 if (test->ops.test_destroy)
191 test->ops.test_destroy(test, &opt);