153a3b7e8SJerin Jacob /* SPDX-License-Identifier: BSD-3-Clause 253a3b7e8SJerin Jacob * Copyright(c) 2017 Cavium, Inc 36d1729deSJerin Jacob */ 46d1729deSJerin Jacob 56d1729deSJerin Jacob #include <stdio.h> 66d1729deSJerin Jacob #include <unistd.h> 76d1729deSJerin Jacob #include <signal.h> 86d1729deSJerin Jacob 96d1729deSJerin Jacob #include <rte_debug.h> 106d1729deSJerin Jacob #include <rte_eal.h> 116d1729deSJerin Jacob #include <rte_eventdev.h> 126d1729deSJerin Jacob 133f3872b1SJerin Jacob #include "evt_options.h" 143f3872b1SJerin Jacob #include "evt_test.h" 153f3872b1SJerin Jacob 163f3872b1SJerin Jacob struct evt_options opt; 173f3872b1SJerin Jacob struct evt_test *test; 183f3872b1SJerin Jacob 192b0bf13cSJerin Jacob static void 202b0bf13cSJerin Jacob signal_handler(int signum) 212b0bf13cSJerin Jacob { 22685bb577SPavan Nikhilesh int i; 23685bb577SPavan Nikhilesh static uint8_t once; 24685bb577SPavan Nikhilesh 25685bb577SPavan Nikhilesh if ((signum == SIGINT || signum == SIGTERM) && !once) { 26685bb577SPavan Nikhilesh once = true; 272b0bf13cSJerin Jacob printf("\nSignal %d received, preparing to exit...\n", 282b0bf13cSJerin Jacob signum); 29685bb577SPavan Nikhilesh 30685bb577SPavan Nikhilesh if (test != NULL) { 312b0bf13cSJerin Jacob /* request all lcores to exit from the main loop */ 322b0bf13cSJerin Jacob *(int *)test->test_priv = true; 332b0bf13cSJerin Jacob rte_wmb(); 342b0bf13cSJerin Jacob 35685bb577SPavan Nikhilesh if (test->ops.ethdev_destroy) 36685bb577SPavan Nikhilesh test->ops.ethdev_destroy(test, &opt); 37685bb577SPavan Nikhilesh 38*de2bc16eSShijith Thotton if (test->ops.cryptodev_destroy) 39*de2bc16eSShijith Thotton test->ops.cryptodev_destroy(test, &opt); 40*de2bc16eSShijith Thotton 412b0bf13cSJerin Jacob rte_eal_mp_wait_lcore(); 422b0bf13cSJerin Jacob 436b1a14a8SPavan Nikhilesh if (test->ops.test_result) 446b1a14a8SPavan Nikhilesh test->ops.test_result(test, &opt); 456b1a14a8SPavan Nikhilesh 46685bb577SPavan Nikhilesh if (opt.prod_type == EVT_PROD_TYPE_ETH_RX_ADPTR) { 47685bb577SPavan Nikhilesh RTE_ETH_FOREACH_DEV(i) 48685bb577SPavan Nikhilesh rte_eth_dev_close(i); 49685bb577SPavan Nikhilesh } 50685bb577SPavan Nikhilesh 512b0bf13cSJerin Jacob if (test->ops.eventdev_destroy) 522b0bf13cSJerin Jacob test->ops.eventdev_destroy(test, &opt); 532b0bf13cSJerin Jacob 542b0bf13cSJerin Jacob if (test->ops.mempool_destroy) 552b0bf13cSJerin Jacob test->ops.mempool_destroy(test, &opt); 562b0bf13cSJerin Jacob 572b0bf13cSJerin Jacob if (test->ops.test_destroy) 582b0bf13cSJerin Jacob test->ops.test_destroy(test, &opt); 59685bb577SPavan Nikhilesh } 602b0bf13cSJerin Jacob 612b0bf13cSJerin Jacob /* exit with the expected status */ 622b0bf13cSJerin Jacob signal(signum, SIG_DFL); 632b0bf13cSJerin Jacob kill(getpid(), signum); 642b0bf13cSJerin Jacob } 652b0bf13cSJerin Jacob } 663f3872b1SJerin Jacob 673f3872b1SJerin Jacob static inline void 683f3872b1SJerin Jacob evt_options_dump_all(struct evt_test *test, struct evt_options *opts) 693f3872b1SJerin Jacob { 703f3872b1SJerin Jacob evt_options_dump(opts); 713f3872b1SJerin Jacob if (test->ops.opt_dump) 723f3872b1SJerin Jacob test->ops.opt_dump(opts); 733f3872b1SJerin Jacob } 743f3872b1SJerin Jacob 756d1729deSJerin Jacob int 766d1729deSJerin Jacob main(int argc, char **argv) 776d1729deSJerin Jacob { 786d1729deSJerin Jacob uint8_t evdevs; 796d1729deSJerin Jacob int ret; 806d1729deSJerin Jacob 812b0bf13cSJerin Jacob signal(SIGINT, signal_handler); 822b0bf13cSJerin Jacob signal(SIGTERM, signal_handler); 832b0bf13cSJerin Jacob 846d1729deSJerin Jacob ret = rte_eal_init(argc, argv); 856d1729deSJerin Jacob if (ret < 0) 866d1729deSJerin Jacob rte_panic("invalid EAL arguments\n"); 876d1729deSJerin Jacob argc -= ret; 886d1729deSJerin Jacob argv += ret; 896d1729deSJerin Jacob 906d1729deSJerin Jacob evdevs = rte_event_dev_count(); 916d1729deSJerin Jacob if (!evdevs) 926d1729deSJerin Jacob rte_panic("no eventdev devices found\n"); 936d1729deSJerin Jacob 943f3872b1SJerin Jacob /* Populate the default values of the options */ 953f3872b1SJerin Jacob evt_options_default(&opt); 963f3872b1SJerin Jacob 973f3872b1SJerin Jacob /* Parse the command line arguments */ 983f3872b1SJerin Jacob ret = evt_options_parse(&opt, argc, argv); 993f3872b1SJerin Jacob if (ret) { 10020841a25SRashmi Shetty evt_err("parsing one or more user options failed"); 1013f3872b1SJerin Jacob goto error; 1023f3872b1SJerin Jacob } 1033f3872b1SJerin Jacob 1043f3872b1SJerin Jacob /* Get struct evt_test *test from name */ 1053f3872b1SJerin Jacob test = evt_test_get(opt.test_name); 1063f3872b1SJerin Jacob if (test == NULL) { 1073f3872b1SJerin Jacob evt_err("failed to find requested test: %s", opt.test_name); 1083f3872b1SJerin Jacob goto error; 1093f3872b1SJerin Jacob } 1103f3872b1SJerin Jacob 1113f3872b1SJerin Jacob if (test->ops.test_result == NULL) { 1123f3872b1SJerin Jacob evt_err("%s: ops.test_result not found", opt.test_name); 1133f3872b1SJerin Jacob goto error; 1143f3872b1SJerin Jacob } 1153f3872b1SJerin Jacob 1163f3872b1SJerin Jacob /* Verify the command line options */ 1173f3872b1SJerin Jacob if (opt.dev_id >= rte_event_dev_count()) { 1183f3872b1SJerin Jacob evt_err("invalid event device %d", opt.dev_id); 1193f3872b1SJerin Jacob goto error; 1203f3872b1SJerin Jacob } 1213f3872b1SJerin Jacob if (test->ops.opt_check) { 1223f3872b1SJerin Jacob if (test->ops.opt_check(&opt)) { 1233f3872b1SJerin Jacob evt_err("invalid command line argument"); 1243f3872b1SJerin Jacob evt_options_dump_all(test, &opt); 1253f3872b1SJerin Jacob goto error; 1263f3872b1SJerin Jacob } 1273f3872b1SJerin Jacob } 1283f3872b1SJerin Jacob 1293f3872b1SJerin Jacob /* Check the eventdev capability before proceeding */ 1303f3872b1SJerin Jacob if (test->ops.cap_check) { 1313f3872b1SJerin Jacob if (test->ops.cap_check(&opt) == false) { 1323f3872b1SJerin Jacob evt_info("unsupported test: %s", opt.test_name); 1333f3872b1SJerin Jacob evt_options_dump_all(test, &opt); 1343f3872b1SJerin Jacob ret = EVT_TEST_UNSUPPORTED; 1353f3872b1SJerin Jacob goto nocap; 1363f3872b1SJerin Jacob } 1373f3872b1SJerin Jacob } 1383f3872b1SJerin Jacob 1393f3872b1SJerin Jacob /* Dump the options */ 1403f3872b1SJerin Jacob if (opt.verbose_level) 1413f3872b1SJerin Jacob evt_options_dump_all(test, &opt); 1423f3872b1SJerin Jacob 1433f3872b1SJerin Jacob /* Test specific setup */ 1443f3872b1SJerin Jacob if (test->ops.test_setup) { 1453f3872b1SJerin Jacob if (test->ops.test_setup(test, &opt)) { 1463f3872b1SJerin Jacob evt_err("failed to setup test: %s", opt.test_name); 1473f3872b1SJerin Jacob goto error; 1483f3872b1SJerin Jacob 1493f3872b1SJerin Jacob } 1503f3872b1SJerin Jacob } 1513f3872b1SJerin Jacob 1523f3872b1SJerin Jacob /* Test specific mempool setup */ 1533f3872b1SJerin Jacob if (test->ops.mempool_setup) { 1543f3872b1SJerin Jacob if (test->ops.mempool_setup(test, &opt)) { 1553f3872b1SJerin Jacob evt_err("%s: mempool setup failed", opt.test_name); 1563f3872b1SJerin Jacob goto test_destroy; 1573f3872b1SJerin Jacob } 1583f3872b1SJerin Jacob } 1593f3872b1SJerin Jacob 1603f3872b1SJerin Jacob /* Test specific ethdev setup */ 1613f3872b1SJerin Jacob if (test->ops.ethdev_setup) { 1623f3872b1SJerin Jacob if (test->ops.ethdev_setup(test, &opt)) { 1633f3872b1SJerin Jacob evt_err("%s: ethdev setup failed", opt.test_name); 1643f3872b1SJerin Jacob goto mempool_destroy; 1653f3872b1SJerin Jacob } 1663f3872b1SJerin Jacob } 1673f3872b1SJerin Jacob 168*de2bc16eSShijith Thotton /* Test specific cryptodev setup */ 169*de2bc16eSShijith Thotton if (test->ops.cryptodev_setup) { 170*de2bc16eSShijith Thotton if (test->ops.cryptodev_setup(test, &opt)) { 171*de2bc16eSShijith Thotton evt_err("%s: cryptodev setup failed", opt.test_name); 172*de2bc16eSShijith Thotton goto ethdev_destroy; 173*de2bc16eSShijith Thotton } 174*de2bc16eSShijith Thotton } 175*de2bc16eSShijith Thotton 1763f3872b1SJerin Jacob /* Test specific eventdev setup */ 1773f3872b1SJerin Jacob if (test->ops.eventdev_setup) { 1783f3872b1SJerin Jacob if (test->ops.eventdev_setup(test, &opt)) { 1793f3872b1SJerin Jacob evt_err("%s: eventdev setup failed", opt.test_name); 180*de2bc16eSShijith Thotton goto cryptodev_destroy; 1813f3872b1SJerin Jacob } 1823f3872b1SJerin Jacob } 1833f3872b1SJerin Jacob 1843f3872b1SJerin Jacob /* Launch lcores */ 1853f3872b1SJerin Jacob if (test->ops.launch_lcores) { 1863f3872b1SJerin Jacob if (test->ops.launch_lcores(test, &opt)) { 1873f3872b1SJerin Jacob evt_err("%s: failed to launch lcores", opt.test_name); 1883f3872b1SJerin Jacob goto eventdev_destroy; 1893f3872b1SJerin Jacob } 1903f3872b1SJerin Jacob } 1913f3872b1SJerin Jacob 1923f3872b1SJerin Jacob rte_eal_mp_wait_lcore(); 1933f3872b1SJerin Jacob 1943f3872b1SJerin Jacob /* Print the test result */ 1953f3872b1SJerin Jacob ret = test->ops.test_result(test, &opt); 1963f3872b1SJerin Jacob nocap: 1973f3872b1SJerin Jacob if (ret == EVT_TEST_SUCCESS) { 1983f3872b1SJerin Jacob printf("Result: "CLGRN"%s"CLNRM"\n", "Success"); 1993f3872b1SJerin Jacob } else if (ret == EVT_TEST_FAILED) { 2003f3872b1SJerin Jacob printf("Result: "CLRED"%s"CLNRM"\n", "Failed"); 2013f3872b1SJerin Jacob return EXIT_FAILURE; 2023f3872b1SJerin Jacob } else if (ret == EVT_TEST_UNSUPPORTED) { 2033f3872b1SJerin Jacob printf("Result: "CLYEL"%s"CLNRM"\n", "Unsupported"); 2043f3872b1SJerin Jacob } 2053f3872b1SJerin Jacob 2066d1729deSJerin Jacob return 0; 2073f3872b1SJerin Jacob eventdev_destroy: 2083f3872b1SJerin Jacob if (test->ops.eventdev_destroy) 2093f3872b1SJerin Jacob test->ops.eventdev_destroy(test, &opt); 2103f3872b1SJerin Jacob 211*de2bc16eSShijith Thotton cryptodev_destroy: 212*de2bc16eSShijith Thotton if (test->ops.cryptodev_destroy) 213*de2bc16eSShijith Thotton test->ops.cryptodev_destroy(test, &opt); 214*de2bc16eSShijith Thotton 2153f3872b1SJerin Jacob ethdev_destroy: 2163f3872b1SJerin Jacob if (test->ops.ethdev_destroy) 2173f3872b1SJerin Jacob test->ops.ethdev_destroy(test, &opt); 2183f3872b1SJerin Jacob 2193f3872b1SJerin Jacob mempool_destroy: 2203f3872b1SJerin Jacob if (test->ops.mempool_destroy) 2213f3872b1SJerin Jacob test->ops.mempool_destroy(test, &opt); 2223f3872b1SJerin Jacob 2233f3872b1SJerin Jacob test_destroy: 2243f3872b1SJerin Jacob if (test->ops.test_destroy) 2253f3872b1SJerin Jacob test->ops.test_destroy(test, &opt); 2263f3872b1SJerin Jacob error: 2273f3872b1SJerin Jacob return EXIT_FAILURE; 2286d1729deSJerin Jacob } 229