1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2022 Marvell. 3 */ 4 5 #include <rte_debug.h> 6 #include <rte_eal.h> 7 #include <rte_mldev.h> 8 9 #include "ml_common.h" 10 #include "ml_test.h" 11 12 struct ml_options opt; 13 struct ml_test *test; 14 15 int 16 main(int argc, char **argv) 17 { 18 uint16_t mldevs; 19 int ret; 20 21 ret = rte_eal_init(argc, argv); 22 if (ret < 0) 23 rte_panic("invalid EAL arguments\n"); 24 argc -= ret; 25 argv += ret; 26 27 mldevs = rte_ml_dev_count(); 28 if (!mldevs) 29 rte_panic("no mldev devices found\n"); 30 31 /* set default values for options */ 32 ml_options_default(&opt); 33 34 /* parse the command line arguments */ 35 ret = ml_options_parse(&opt, argc, argv); 36 if (ret) { 37 ml_err("parsing one or more user options failed"); 38 goto error; 39 } 40 41 /* get test struct from name */ 42 test = ml_test_get(opt.test_name); 43 if (test == NULL) { 44 ml_err("failed to find requested test: %s", opt.test_name); 45 goto error; 46 } 47 48 if (test->ops.test_result == NULL) { 49 ml_err("%s: ops.test_result not found", opt.test_name); 50 goto error; 51 } 52 53 /* check test options */ 54 if (test->ops.opt_check) { 55 if (test->ops.opt_check(&opt)) { 56 ml_err("invalid command line argument"); 57 goto error; 58 } 59 } 60 61 /* check the device capability */ 62 if (test->ops.cap_check) { 63 if (test->ops.cap_check(&opt) == false) { 64 ml_info("unsupported test: %s", opt.test_name); 65 ret = ML_TEST_UNSUPPORTED; 66 goto no_cap; 67 } 68 } 69 70 /* dump options */ 71 if (opt.debug) { 72 if (test->ops.opt_dump) 73 test->ops.opt_dump(&opt); 74 } 75 76 /* test specific setup */ 77 if (test->ops.test_setup) { 78 if (test->ops.test_setup(test, &opt)) { 79 ml_err("failed to setup test: %s", opt.test_name); 80 goto error; 81 } 82 } 83 84 /* test driver */ 85 if (test->ops.test_driver) 86 test->ops.test_driver(test, &opt); 87 88 /* get result */ 89 if (test->ops.test_result) 90 ret = test->ops.test_result(test, &opt); 91 92 if (test->ops.test_destroy) 93 test->ops.test_destroy(test, &opt); 94 95 no_cap: 96 if (ret == ML_TEST_SUCCESS) { 97 printf("Result: " CLGRN "%s" CLNRM "\n", "Success"); 98 } else if (ret == ML_TEST_FAILED) { 99 printf("Result: " CLRED "%s" CLNRM "\n", "Failed"); 100 return EXIT_FAILURE; 101 } else if (ret == ML_TEST_UNSUPPORTED) { 102 printf("Result: " CLYEL "%s" CLNRM "\n", "Unsupported"); 103 } 104 105 rte_eal_cleanup(); 106 107 return 0; 108 109 error: 110 rte_eal_cleanup(); 111 112 return EXIT_FAILURE; 113 } 114