1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2017 Cavium, Inc 3 */ 4 5 #include <stdio.h> 6 #include <unistd.h> 7 #include <signal.h> 8 9 #include <rte_atomic.h> 10 #include <rte_debug.h> 11 #include <rte_eal.h> 12 #include <rte_eventdev.h> 13 14 #include "evt_options.h" 15 #include "evt_test.h" 16 17 struct evt_options opt; 18 struct evt_test *test; 19 20 static void 21 signal_handler(int signum) 22 { 23 if (signum == SIGINT || signum == SIGTERM) { 24 printf("\nSignal %d received, preparing to exit...\n", 25 signum); 26 /* request all lcores to exit from the main loop */ 27 *(int *)test->test_priv = true; 28 rte_wmb(); 29 30 rte_eal_mp_wait_lcore(); 31 32 if (test->ops.test_result) 33 test->ops.test_result(test, &opt); 34 35 if (test->ops.eventdev_destroy) 36 test->ops.eventdev_destroy(test, &opt); 37 38 if (test->ops.ethdev_destroy) 39 test->ops.ethdev_destroy(test, &opt); 40 41 if (test->ops.mempool_destroy) 42 test->ops.mempool_destroy(test, &opt); 43 44 if (test->ops.test_destroy) 45 test->ops.test_destroy(test, &opt); 46 47 /* exit with the expected status */ 48 signal(signum, SIG_DFL); 49 kill(getpid(), signum); 50 } 51 } 52 53 static inline void 54 evt_options_dump_all(struct evt_test *test, struct evt_options *opts) 55 { 56 evt_options_dump(opts); 57 if (test->ops.opt_dump) 58 test->ops.opt_dump(opts); 59 } 60 61 int 62 main(int argc, char **argv) 63 { 64 uint8_t evdevs; 65 int ret; 66 67 signal(SIGINT, signal_handler); 68 signal(SIGTERM, signal_handler); 69 70 ret = rte_eal_init(argc, argv); 71 if (ret < 0) 72 rte_panic("invalid EAL arguments\n"); 73 argc -= ret; 74 argv += ret; 75 76 evdevs = rte_event_dev_count(); 77 if (!evdevs) 78 rte_panic("no eventdev devices found\n"); 79 80 /* Populate the default values of the options */ 81 evt_options_default(&opt); 82 83 /* Parse the command line arguments */ 84 ret = evt_options_parse(&opt, argc, argv); 85 if (ret) { 86 evt_err("parsing on or more user options failed"); 87 goto error; 88 } 89 90 /* Get struct evt_test *test from name */ 91 test = evt_test_get(opt.test_name); 92 if (test == NULL) { 93 evt_err("failed to find requested test: %s", opt.test_name); 94 goto error; 95 } 96 97 if (test->ops.test_result == NULL) { 98 evt_err("%s: ops.test_result not found", opt.test_name); 99 goto error; 100 } 101 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); 105 goto error; 106 } 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); 111 goto error; 112 } 113 } 114 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; 121 goto nocap; 122 } 123 } 124 125 /* Dump the options */ 126 if (opt.verbose_level) 127 evt_options_dump_all(test, &opt); 128 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); 133 goto error; 134 135 } 136 } 137 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); 142 goto test_destroy; 143 } 144 } 145 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; 151 } 152 } 153 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); 158 goto ethdev_destroy; 159 } 160 } 161 162 /* Launch lcores */ 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; 167 } 168 } 169 170 rte_eal_mp_wait_lcore(); 171 172 /* Print the test result */ 173 ret = test->ops.test_result(test, &opt); 174 nocap: 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"); 179 return EXIT_FAILURE; 180 } else if (ret == EVT_TEST_UNSUPPORTED) { 181 printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported"); 182 } 183 184 return 0; 185 eventdev_destroy: 186 if (test->ops.eventdev_destroy) 187 test->ops.eventdev_destroy(test, &opt); 188 189 ethdev_destroy: 190 if (test->ops.ethdev_destroy) 191 test->ops.ethdev_destroy(test, &opt); 192 193 mempool_destroy: 194 if (test->ops.mempool_destroy) 195 test->ops.mempool_destroy(test, &opt); 196 197 test_destroy: 198 if (test->ops.test_destroy) 199 test->ops.test_destroy(test, &opt); 200 error: 201 return EXIT_FAILURE; 202 } 203