app/testeventdev: invoke the test ops
[dpdk.git] / app / test-eventdev / evt_main.c
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
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.
19  *
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.
31  */
32
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <signal.h>
36
37 #include <rte_debug.h>
38 #include <rte_eal.h>
39 #include <rte_eventdev.h>
40
41 #include "evt_options.h"
42 #include "evt_test.h"
43
44 struct evt_options opt;
45 struct evt_test *test;
46
47
48 static inline void
49 evt_options_dump_all(struct evt_test *test, struct evt_options *opts)
50 {
51         evt_options_dump(opts);
52         if (test->ops.opt_dump)
53                 test->ops.opt_dump(opts);
54 }
55
56 int
57 main(int argc, char **argv)
58 {
59         uint8_t evdevs;
60         int ret;
61
62         ret = rte_eal_init(argc, argv);
63         if (ret < 0)
64                 rte_panic("invalid EAL arguments\n");
65         argc -= ret;
66         argv += ret;
67
68         evdevs = rte_event_dev_count();
69         if (!evdevs)
70                 rte_panic("no eventdev devices found\n");
71
72         /* Populate the default values of the options */
73         evt_options_default(&opt);
74
75         /* Parse the command line arguments */
76         ret = evt_options_parse(&opt, argc, argv);
77         if (ret) {
78                 evt_err("parsing on or more user options failed");
79                 goto error;
80         }
81
82         /* Get struct evt_test *test from name */
83         test = evt_test_get(opt.test_name);
84         if (test == NULL) {
85                 evt_err("failed to find requested test: %s", opt.test_name);
86                 goto error;
87         }
88
89         if (test->ops.test_result == NULL) {
90                 evt_err("%s: ops.test_result not found", opt.test_name);
91                 goto error;
92         }
93
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);
97                 goto error;
98         }
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);
103                         goto error;
104                 }
105         }
106
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;
113                         goto nocap;
114                 }
115         }
116
117         /* Dump the options */
118         if (opt.verbose_level)
119                 evt_options_dump_all(test, &opt);
120
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);
125                         goto error;
126
127                 }
128         }
129
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);
134                         goto test_destroy;
135                 }
136         }
137
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;
143                 }
144         }
145
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);
150                         goto ethdev_destroy;
151                 }
152         }
153
154         /* Launch lcores */
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;
159                 }
160         }
161
162         rte_eal_mp_wait_lcore();
163
164         /* Print the test result */
165         ret = test->ops.test_result(test, &opt);
166 nocap:
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");
171                 return EXIT_FAILURE;
172         } else if (ret == EVT_TEST_UNSUPPORTED) {
173                 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported");
174         }
175
176         return 0;
177 eventdev_destroy:
178         if (test->ops.eventdev_destroy)
179                 test->ops.eventdev_destroy(test, &opt);
180
181 ethdev_destroy:
182         if (test->ops.ethdev_destroy)
183                 test->ops.ethdev_destroy(test, &opt);
184
185 mempool_destroy:
186         if (test->ops.mempool_destroy)
187                 test->ops.mempool_destroy(test, &opt);
188
189 test_destroy:
190         if (test->ops.test_destroy)
191                 test->ops.test_destroy(test, &opt);
192 error:
193         return EXIT_FAILURE;
194 }