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
main(int argc,char ** argv)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 ml_err("no mldev devices found\n");
30 goto error;
31 }
32
33 /* set default values for options */
34 ml_options_default(&opt);
35
36 /* parse the command line arguments */
37 ret = ml_options_parse(&opt, argc, argv);
38 if (ret) {
39 ml_err("parsing one or more user options failed");
40 goto error;
41 }
42
43 /* get test struct from name */
44 test = ml_test_get(opt.test_name);
45 if (test == NULL) {
46 ml_err("failed to find requested test: %s", opt.test_name);
47 goto error;
48 }
49
50 if (test->ops.test_result == NULL) {
51 ml_err("%s: ops.test_result not found", opt.test_name);
52 goto error;
53 }
54
55 /* check test options */
56 if (test->ops.opt_check) {
57 if (test->ops.opt_check(&opt)) {
58 ml_err("invalid command line argument");
59 goto error;
60 }
61 }
62
63 /* check the device capability */
64 if (test->ops.cap_check) {
65 if (test->ops.cap_check(&opt) == false) {
66 ml_info("unsupported test: %s", opt.test_name);
67 ret = ML_TEST_UNSUPPORTED;
68 goto no_cap;
69 }
70 }
71
72 /* dump options */
73 if (opt.debug) {
74 if (test->ops.opt_dump)
75 test->ops.opt_dump(&opt);
76 }
77
78 /* test specific setup */
79 if (test->ops.test_setup) {
80 if (test->ops.test_setup(test, &opt)) {
81 ml_err("failed to setup test: %s", opt.test_name);
82 goto error;
83 }
84 }
85
86 /* test driver */
87 if (test->ops.test_driver)
88 test->ops.test_driver(test, &opt);
89
90 /* get result */
91 if (test->ops.test_result)
92 ret = test->ops.test_result(test, &opt);
93
94 if (test->ops.test_destroy)
95 test->ops.test_destroy(test, &opt);
96
97 no_cap:
98 if (ret == ML_TEST_SUCCESS) {
99 printf("Result: " CLGRN "%s" CLNRM "\n", "Success");
100 } else if (ret == ML_TEST_FAILED) {
101 printf("Result: " CLRED "%s" CLNRM "\n", "Failed");
102 return EXIT_FAILURE;
103 } else if (ret == ML_TEST_UNSUPPORTED) {
104 printf("Result: " CLYEL "%s" CLNRM "\n", "Unsupported");
105 }
106
107 rte_eal_cleanup();
108
109 return 0;
110
111 error:
112 rte_eal_cleanup();
113
114 return EXIT_FAILURE;
115 }
116