Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 |
| 4 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 6db8ea5 | 2020-07-28 19:41:13 -0600 | [diff] [blame] | 8 | #include <console.h> |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 9 | #include <vsprintf.h> |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 10 | #include <test/suites.h> |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 11 | #include <test/test.h> |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 12 | #include <test/ut.h> |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 13 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 14 | /** |
| 15 | * struct suite - A set of tests for a certain topic |
| 16 | * |
| 17 | * All tests end up in a single 'struct unit_test' linker-list array, in order |
| 18 | * of the suite they are in |
| 19 | * |
| 20 | * @name: Name of suite |
| 21 | * @start: First test in suite |
| 22 | * @end: End test in suite (points to the first test in the next suite) |
| 23 | * @cmd: Command to use to run the suite |
| 24 | */ |
| 25 | struct suite { |
| 26 | const char *name; |
| 27 | struct unit_test *start; |
| 28 | struct unit_test *end; |
| 29 | ut_cmd_func cmd; |
| 30 | }; |
| 31 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 32 | static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc, |
| 33 | char *const argv[]); |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 34 | |
Simon Glass | fb998c2 | 2022-10-29 19:47:12 -0600 | [diff] [blame] | 35 | static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc, |
| 36 | char *const argv[]); |
| 37 | |
Philippe Reynes | 1f99f84 | 2019-12-17 19:07:04 +0100 | [diff] [blame] | 38 | int cmd_ut_category(const char *name, const char *prefix, |
| 39 | struct unit_test *tests, int n_ents, |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 40 | int argc, char *const argv[]) |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 41 | { |
Simon Glass | 3869eb5 | 2025-01-20 14:25:26 -0700 | [diff] [blame] | 42 | struct unit_test_state uts; |
Simon Glass | 85ba7c3 | 2022-10-29 19:47:13 -0600 | [diff] [blame] | 43 | const char *test_insert = NULL; |
Simon Glass | 91a187b | 2022-08-01 07:58:45 -0600 | [diff] [blame] | 44 | int runs_per_text = 1; |
Simon Glass | 1f1614b | 2022-10-20 18:22:50 -0600 | [diff] [blame] | 45 | bool force_run = false; |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 46 | int ret; |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 47 | |
Simon Glass | 1f1614b | 2022-10-20 18:22:50 -0600 | [diff] [blame] | 48 | while (argc > 1 && *argv[1] == '-') { |
| 49 | const char *str = argv[1]; |
| 50 | |
| 51 | switch (str[1]) { |
| 52 | case 'r': |
| 53 | runs_per_text = dectoul(str + 2, NULL); |
| 54 | break; |
| 55 | case 'f': |
| 56 | force_run = true; |
| 57 | break; |
Simon Glass | 85ba7c3 | 2022-10-29 19:47:13 -0600 | [diff] [blame] | 58 | case 'I': |
| 59 | test_insert = str + 2; |
| 60 | break; |
Simon Glass | 1f1614b | 2022-10-20 18:22:50 -0600 | [diff] [blame] | 61 | } |
Simon Glass | 91a187b | 2022-08-01 07:58:45 -0600 | [diff] [blame] | 62 | argv++; |
Simon Glass | 85ba7c3 | 2022-10-29 19:47:13 -0600 | [diff] [blame] | 63 | argc--; |
Simon Glass | 91a187b | 2022-08-01 07:58:45 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Simon Glass | 3869eb5 | 2025-01-20 14:25:26 -0700 | [diff] [blame] | 66 | ut_init_state(&uts); |
| 67 | ret = ut_run_list(&uts, name, prefix, tests, n_ents, |
Simon Glass | 793a98e | 2023-11-18 14:05:20 -0700 | [diff] [blame] | 68 | cmd_arg1(argc, argv), runs_per_text, force_run, |
Simon Glass | 85ba7c3 | 2022-10-29 19:47:13 -0600 | [diff] [blame] | 69 | test_insert); |
Simon Glass | 3869eb5 | 2025-01-20 14:25:26 -0700 | [diff] [blame] | 70 | ut_uninit_state(&uts); |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 71 | |
Simon Glass | 5722fb2 | 2021-03-07 17:34:47 -0700 | [diff] [blame] | 72 | return ret ? CMD_RET_FAILURE : 0; |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 75 | /* declare linker-list symbols for the start and end of a suite */ |
| 76 | #define SUITE_DECL(_name) \ |
| 77 | ll_start_decl(suite_start_ ## _name, struct unit_test, ut_ ## _name); \ |
| 78 | ll_end_decl(suite_end_ ## _name, struct unit_test, ut_ ## _name) |
| 79 | |
| 80 | /* declare a test suite which uses a subcommand to run */ |
| 81 | #define SUITE_CMD(_name, _cmd_func) { \ |
| 82 | #_name, \ |
| 83 | suite_start_ ## _name, \ |
| 84 | suite_end_ ## _name, \ |
| 85 | _cmd_func, \ |
| 86 | } |
| 87 | |
| 88 | /* declare a test suite which can be run directly without a subcommand */ |
| 89 | #define SUITE(_name) { \ |
| 90 | #_name, \ |
| 91 | suite_start_ ## _name, \ |
| 92 | suite_end_ ## _name, \ |
| 93 | NULL, \ |
| 94 | } |
| 95 | |
| 96 | SUITE_DECL(info); |
| 97 | SUITE_DECL(bdinfo); |
| 98 | SUITE_DECL(bootstd); |
| 99 | SUITE_DECL(cmd); |
| 100 | SUITE_DECL(common); |
| 101 | SUITE_DECL(dm); |
| 102 | SUITE_DECL(env); |
| 103 | SUITE_DECL(exit); |
| 104 | SUITE_DECL(fdt); |
| 105 | SUITE_DECL(font); |
| 106 | SUITE_DECL(optee); |
| 107 | SUITE_DECL(overlay); |
| 108 | SUITE_DECL(lib); |
| 109 | SUITE_DECL(log); |
| 110 | SUITE_DECL(mbr); |
| 111 | SUITE_DECL(mem); |
| 112 | SUITE_DECL(setexpr); |
| 113 | SUITE_DECL(measurement); |
| 114 | SUITE_DECL(bloblist); |
| 115 | SUITE_DECL(bootm); |
| 116 | SUITE_DECL(addrmap); |
| 117 | SUITE_DECL(hush); |
| 118 | SUITE_DECL(loadm); |
| 119 | SUITE_DECL(pci_mps); |
| 120 | SUITE_DECL(seama); |
| 121 | SUITE_DECL(upl); |
| 122 | |
| 123 | static struct suite suites[] = { |
| 124 | SUITE_CMD(info, do_ut_info), |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 125 | #ifdef CONFIG_CMD_BDI |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 126 | SUITE_CMD(bdinfo, do_ut_bdinfo), |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 127 | #endif |
Simon Glass | 804aa37 | 2023-10-01 19:15:15 -0600 | [diff] [blame] | 128 | #ifdef CONFIG_UT_BOOTSTD |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 129 | SUITE_CMD(bootstd, do_ut_bootstd), |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 130 | #endif |
Simon Glass | 621a97e | 2023-10-01 19:15:12 -0600 | [diff] [blame] | 131 | #ifdef CONFIG_CMDLINE |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 132 | SUITE_CMD(cmd, do_ut_cmd), |
Simon Glass | 621a97e | 2023-10-01 19:15:12 -0600 | [diff] [blame] | 133 | #endif |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 134 | SUITE_CMD(common, do_ut_common), |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 135 | #if defined(CONFIG_UT_DM) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 136 | SUITE_CMD(dm, do_ut_dm), |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 137 | #endif |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 138 | #if defined(CONFIG_UT_ENV) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 139 | SUITE_CMD(env, do_ut_env), |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 140 | #endif |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 141 | SUITE_CMD(exit, do_ut_exit), |
Simon Glass | f3c6a1d | 2022-07-13 06:06:59 -0600 | [diff] [blame] | 142 | #ifdef CONFIG_CMD_FDT |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 143 | SUITE_CMD(fdt, do_ut_fdt), |
Simon Glass | f3c6a1d | 2022-07-13 06:06:59 -0600 | [diff] [blame] | 144 | #endif |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 145 | #ifdef CONFIG_CONSOLE_TRUETYPE |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 146 | SUITE_CMD(font, do_ut_font), |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 147 | #endif |
Heiko Stuebner | 1c9bb9b | 2019-10-23 16:46:41 +0200 | [diff] [blame] | 148 | #ifdef CONFIG_UT_OPTEE |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 149 | SUITE_CMD(optee, do_ut_optee), |
Heiko Stuebner | 1c9bb9b | 2019-10-23 16:46:41 +0200 | [diff] [blame] | 150 | #endif |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_UT_OVERLAY |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 152 | SUITE_CMD(overlay, do_ut_overlay), |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 153 | #endif |
Heinrich Schuchardt | f77a635 | 2019-01-30 07:53:31 +0100 | [diff] [blame] | 154 | #ifdef CONFIG_UT_LIB |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 155 | SUITE_CMD(lib, do_ut_lib), |
Heinrich Schuchardt | f77a635 | 2019-01-30 07:53:31 +0100 | [diff] [blame] | 156 | #endif |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 157 | #ifdef CONFIG_UT_LOG |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 158 | SUITE_CMD(log, do_ut_log), |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 159 | #endif |
Alexander Gendin | 038cb02 | 2023-10-09 01:24:36 +0000 | [diff] [blame] | 160 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_MBR) && defined(CONFIG_CMD_MMC) \ |
| 161 | && defined(CONFIG_MMC_SANDBOX) && defined(CONFIG_MMC_WRITE) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 162 | SUITE_CMD(mbr, do_ut_mbr), |
Alexander Gendin | 038cb02 | 2023-10-09 01:24:36 +0000 | [diff] [blame] | 163 | #endif |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 164 | SUITE_CMD(mem, do_ut_mem), |
Heinrich Schuchardt | 90a082d | 2022-10-01 21:42:35 +0200 | [diff] [blame] | 165 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_SETEXPR) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 166 | SUITE_CMD(setexpr, do_ut_setexpr), |
Heinrich Schuchardt | c33f85e | 2021-02-17 12:58:14 +0100 | [diff] [blame] | 167 | #endif |
Eddie James | 1a55a7a | 2023-10-24 10:43:51 -0500 | [diff] [blame] | 168 | #ifdef CONFIG_MEASURED_BOOT |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 169 | SUITE_CMD(measurement, do_ut_measurement), |
Eddie James | 1a55a7a | 2023-10-24 10:43:51 -0500 | [diff] [blame] | 170 | #endif |
Simon Glass | 1edaed0 | 2017-11-25 11:57:33 -0700 | [diff] [blame] | 171 | #ifdef CONFIG_SANDBOX |
Evgeny Bachinin | fbdb85a | 2024-12-02 16:45:24 +0300 | [diff] [blame] | 172 | #if CONFIG_IS_ENABLED(BLOBLIST) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 173 | SUITE_CMD(bloblist, do_ut_bloblist), |
| 174 | SUITE_CMD(bootm, do_ut_bootm), |
Simon Glass | 1edaed0 | 2017-11-25 11:57:33 -0700 | [diff] [blame] | 175 | #endif |
Evgeny Bachinin | 4b74ddd | 2024-12-02 16:45:25 +0300 | [diff] [blame] | 176 | #endif |
Bin Meng | 261fc06 | 2021-02-25 17:22:35 +0800 | [diff] [blame] | 177 | #ifdef CONFIG_CMD_ADDRMAP |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 178 | SUITE_CMD(addrmap, do_ut_addrmap), |
Bin Meng | 261fc06 | 2021-02-25 17:22:35 +0800 | [diff] [blame] | 179 | #endif |
Francis Laniel | 2dba91a | 2023-12-22 22:02:21 +0100 | [diff] [blame] | 180 | #if CONFIG_IS_ENABLED(HUSH_PARSER) |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 181 | SUITE_CMD(hush, do_ut_hush), |
Francis Laniel | 2dba91a | 2023-12-22 22:02:21 +0100 | [diff] [blame] | 182 | #endif |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 183 | #ifdef CONFIG_CMD_LOADM |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 184 | SUITE_CMD(loadm, do_ut_loadm), |
Rui Miguel Silva | 433f15a | 2022-05-11 10:55:40 +0100 | [diff] [blame] | 185 | #endif |
Stephen Carlson | e5c05ae | 2023-03-10 11:07:15 -0800 | [diff] [blame] | 186 | #ifdef CONFIG_CMD_PCI_MPS |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 187 | SUITE_CMD(pci_mps, do_ut_pci_mps), |
Stephen Carlson | e5c05ae | 2023-03-10 11:07:15 -0800 | [diff] [blame] | 188 | #endif |
Linus Walleij | bef3925 | 2023-02-01 00:16:13 +0100 | [diff] [blame] | 189 | #ifdef CONFIG_CMD_SEAMA |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 190 | SUITE_CMD(seama, do_ut_seama), |
Linus Walleij | bef3925 | 2023-02-01 00:16:13 +0100 | [diff] [blame] | 191 | #endif |
Simon Glass | aac2569 | 2024-08-07 16:47:29 -0600 | [diff] [blame] | 192 | #ifdef CONFIG_CMD_UPL |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 193 | SUITE_CMD(upl, do_ut_upl), |
Simon Glass | aac2569 | 2024-08-07 16:47:29 -0600 | [diff] [blame] | 194 | #endif |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 195 | }; |
| 196 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 197 | /** run_suite() - Run a suite of tests */ |
| 198 | static int run_suite(struct suite *ste, struct cmd_tbl *cmdtp, int flag, |
| 199 | int argc, char *const argv[]) |
| 200 | { |
| 201 | int ret; |
| 202 | |
| 203 | if (ste->cmd) { |
| 204 | ret = ste->cmd(cmdtp, flag, argc, argv); |
| 205 | } else { |
| 206 | int n_ents = ste->end - ste->start; |
| 207 | char prefix[30]; |
| 208 | |
| 209 | /* use a standard prefix */ |
| 210 | snprintf(prefix, sizeof(prefix), "%s_test", ste->name); |
| 211 | ret = cmd_ut_category(ste->name, prefix, ste->start, n_ents, |
| 212 | argc, argv); |
| 213 | } |
| 214 | |
| 215 | return ret; |
| 216 | } |
| 217 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 218 | static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc, |
| 219 | char *const argv[]) |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 220 | { |
| 221 | int i; |
| 222 | int retval; |
| 223 | int any_fail = 0; |
| 224 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 225 | for (i = 0; i < ARRAY_SIZE(suites); i++) { |
| 226 | struct suite *ste = &suites[i]; |
| 227 | char *const argv[] = {(char *)ste->name, NULL}; |
| 228 | |
| 229 | printf("----Running %s tests----\n", ste->name); |
| 230 | retval = run_suite(ste, cmdtp, flag, 1, argv); |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 231 | if (!any_fail) |
| 232 | any_fail = retval; |
| 233 | } |
| 234 | |
| 235 | return any_fail; |
| 236 | } |
| 237 | |
Simon Glass | fb998c2 | 2022-10-29 19:47:12 -0600 | [diff] [blame] | 238 | static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc, |
| 239 | char *const argv[]) |
| 240 | { |
Simon Glass | cfb38f8 | 2025-01-20 14:25:30 -0700 | [diff] [blame] | 241 | const char *flags; |
| 242 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 243 | printf("Test suites: %d\n", (int)ARRAY_SIZE(suites)); |
Simon Glass | fb998c2 | 2022-10-29 19:47:12 -0600 | [diff] [blame] | 244 | printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT()); |
| 245 | |
Simon Glass | cfb38f8 | 2025-01-20 14:25:30 -0700 | [diff] [blame] | 246 | flags = cmd_arg1(argc, argv); |
| 247 | if (flags && !strcmp("-s", flags)) { |
| 248 | int i; |
| 249 | |
| 250 | puts("\nTests Suite\n"); |
| 251 | puts("----- -----\n"); |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 252 | for (i = 1; i < ARRAY_SIZE(suites); i++) { |
| 253 | struct suite *ste = &suites[i]; |
| 254 | long n_ent = ste->end - ste->start; |
| 255 | |
| 256 | if (n_ent) |
| 257 | printf("%5ld %s\n", n_ent, ste->name); |
| 258 | else |
| 259 | printf("%5s %s\n", "?", ste->name); |
| 260 | } |
Simon Glass | cfb38f8 | 2025-01-20 14:25:30 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Simon Glass | fb998c2 | 2022-10-29 19:47:12 -0600 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 266 | static struct suite *find_suite(const char *name) |
| 267 | { |
| 268 | struct suite *ste; |
| 269 | int i; |
| 270 | |
| 271 | for (i = 0, ste = suites; i < ARRAY_SIZE(suites); i++, ste++) { |
| 272 | if (!strcmp(ste->name, name)) |
| 273 | return ste; |
| 274 | } |
| 275 | |
| 276 | return NULL; |
| 277 | } |
| 278 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 279 | static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 280 | { |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 281 | struct suite *ste; |
| 282 | const char *name; |
| 283 | int ret; |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 284 | |
| 285 | if (argc < 2) |
| 286 | return CMD_RET_USAGE; |
| 287 | |
| 288 | /* drop initial "ut" arg */ |
| 289 | argc--; |
| 290 | argv++; |
| 291 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 292 | name = argv[0]; |
| 293 | if (!strcmp(name, "all")) { |
| 294 | ret = do_ut_all(cmdtp, flag, argc, argv); |
| 295 | } else if (!strcmp(name, "info")) { |
| 296 | ret = do_ut_info(cmdtp, flag, argc, argv); |
| 297 | } else { |
| 298 | ste = find_suite(argv[0]); |
| 299 | if (!ste) { |
| 300 | printf("Suite '%s' not found\n", argv[0]); |
| 301 | return CMD_RET_FAILURE; |
| 302 | } |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 303 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 304 | ret = run_suite(ste, cmdtp, flag, argc, argv); |
| 305 | } |
| 306 | if (ret) |
| 307 | return ret; |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 308 | |
Simon Glass | 78fd76b | 2025-01-20 14:25:33 -0700 | [diff] [blame^] | 309 | return 0; |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 310 | } |
| 311 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 312 | U_BOOT_LONGHELP(ut, |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 313 | "[-r] [-f] [<suite>] - run unit tests\n" |
| 314 | " -r<runs> Number of times to run each test\n" |
| 315 | " -f Force 'manual' tests to run as well\n" |
| 316 | " <suite> Test suite to run, or all\n" |
| 317 | "\n" |
Simon Glass | fb998c2 | 2022-10-29 19:47:12 -0600 | [diff] [blame] | 318 | "\nOptions for <suite>:" |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 319 | "\nall - execute all enabled tests" |
Simon Glass | cfb38f8 | 2025-01-20 14:25:30 -0700 | [diff] [blame] | 320 | "\ninfo [-s] - show info about tests [and suites]" |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 321 | #ifdef CONFIG_CMD_ADDRMAP |
| 322 | "\naddrmap - very basic test of addrmap command" |
| 323 | #endif |
Marek Vasut | 2cd173c | 2023-05-31 03:03:58 +0200 | [diff] [blame] | 324 | #ifdef CONFIG_CMD_BDI |
| 325 | "\nbdinfo - bdinfo command" |
| 326 | #endif |
Heinrich Schuchardt | b8b6c81 | 2018-08-31 21:31:28 +0200 | [diff] [blame] | 327 | #ifdef CONFIG_SANDBOX |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 328 | "\nbloblist - bloblist implementation" |
Heinrich Schuchardt | b8b6c81 | 2018-08-31 21:31:28 +0200 | [diff] [blame] | 329 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 330 | #ifdef CONFIG_BOOTSTD |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 331 | "\nbootstd - standard boot implementation" |
| 332 | #endif |
Simon Glass | 621a97e | 2023-10-01 19:15:12 -0600 | [diff] [blame] | 333 | #ifdef CONFIG_CMDLINE |
| 334 | "\ncmd - test various commands" |
| 335 | #endif |
Simon Glass | 3394c3c | 2024-11-02 13:36:56 -0600 | [diff] [blame] | 336 | "\ncommon - tests for common/ directory" |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 337 | #ifdef CONFIG_UT_DM |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 338 | "\ndm - driver model" |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 339 | #endif |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 340 | #ifdef CONFIG_UT_ENV |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 341 | "\nenv - environment" |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 342 | #endif |
Simon Glass | f3c6a1d | 2022-07-13 06:06:59 -0600 | [diff] [blame] | 343 | #ifdef CONFIG_CMD_FDT |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 344 | "\nfdt - fdt command" |
Simon Glass | f3c6a1d | 2022-07-13 06:06:59 -0600 | [diff] [blame] | 345 | #endif |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 346 | #ifdef CONFIG_CONSOLE_TRUETYPE |
Marek Vasut | ef9eb6c | 2023-08-13 00:16:41 +0200 | [diff] [blame] | 347 | "\nfont - font command" |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 348 | #endif |
Francis Laniel | 2dba91a | 2023-12-22 22:02:21 +0100 | [diff] [blame] | 349 | #if CONFIG_IS_ENABLED(HUSH_PARSER) |
| 350 | "\nhush - Test hush behavior" |
| 351 | #endif |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 352 | #ifdef CONFIG_CMD_LOADM |
| 353 | "\nloadm - loadm command parameters and loading memory blob" |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 354 | #endif |
Heinrich Schuchardt | f77a635 | 2019-01-30 07:53:31 +0100 | [diff] [blame] | 355 | #ifdef CONFIG_UT_LIB |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 356 | "\nlib - library functions" |
Heinrich Schuchardt | f77a635 | 2019-01-30 07:53:31 +0100 | [diff] [blame] | 357 | #endif |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 358 | #ifdef CONFIG_UT_LOG |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 359 | "\nlog - logging functions" |
Heinrich Schuchardt | f433d50 | 2020-02-26 21:48:18 +0100 | [diff] [blame] | 360 | #endif |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 361 | "\nmem - memory-related commands" |
Heiko Stuebner | 1c9bb9b | 2019-10-23 16:46:41 +0200 | [diff] [blame] | 362 | #ifdef CONFIG_UT_OPTEE |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 363 | "\noptee - test OP-TEE" |
Heiko Stuebner | 1c9bb9b | 2019-10-23 16:46:41 +0200 | [diff] [blame] | 364 | #endif |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 365 | #ifdef CONFIG_UT_OVERLAY |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 366 | "\noverlay - device tree overlays" |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 367 | #endif |
Stephen Carlson | e5c05ae | 2023-03-10 11:07:15 -0800 | [diff] [blame] | 368 | #ifdef CONFIG_CMD_PCI_MPS |
| 369 | "\npci_mps - PCI Express Maximum Payload Size" |
| 370 | #endif |
Simon Glass | 154bb8e | 2022-10-29 19:47:10 -0600 | [diff] [blame] | 371 | "\nsetexpr - setexpr command" |
Linus Walleij | bef3925 | 2023-02-01 00:16:13 +0100 | [diff] [blame] | 372 | #ifdef CONFIG_CMD_SEAMA |
| 373 | "\nseama - seama command parameters loading and decoding" |
| 374 | #endif |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 375 | ); |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 376 | |
| 377 | U_BOOT_CMD( |
| 378 | ut, CONFIG_SYS_MAXARGS, 1, do_ut, |
| 379 | "unit tests", ut_help_text |
| 380 | ); |