1 // SPDX-License-Identifier: GPL-2.0
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
10 #include <test/suites.h>
11 #include <test/test.h>
14 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
17 static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
20 int cmd_ut_category(const char *name, const char *prefix,
21 struct unit_test *tests, int n_ents,
22 int argc, char *const argv[])
24 const char *test_insert = NULL;
25 int runs_per_text = 1;
26 bool force_run = false;
29 while (argc > 1 && *argv[1] == '-') {
30 const char *str = argv[1];
34 runs_per_text = dectoul(str + 2, NULL);
40 test_insert = str + 2;
47 ret = ut_run_list(name, prefix, tests, n_ents,
48 argc > 1 ? argv[1] : NULL, runs_per_text, force_run,
51 return ret ? CMD_RET_FAILURE : 0;
54 static struct cmd_tbl cmd_ut_sub[] = {
55 U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
56 U_BOOT_CMD_MKENT(info, 1, 1, do_ut_info, "", ""),
58 U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
61 U_BOOT_CMD_MKENT(common, CONFIG_SYS_MAXARGS, 1, do_ut_common, "", ""),
62 #if defined(CONFIG_UT_DM)
63 U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
65 #if defined(CONFIG_UT_ENV)
66 U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
68 U_BOOT_CMD_MKENT(exit, CONFIG_SYS_MAXARGS, 1, do_ut_exit, "", ""),
70 U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""),
72 #ifdef CONFIG_CONSOLE_TRUETYPE
73 U_BOOT_CMD_MKENT(font, CONFIG_SYS_MAXARGS, 1, do_ut_font, "", ""),
75 #ifdef CONFIG_UT_OPTEE
76 U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
78 #ifdef CONFIG_UT_OVERLAY
79 U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
82 U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
85 U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
87 U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
88 #if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_SETEXPR)
89 U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
92 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
94 U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
96 #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
97 U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
100 U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
102 U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
104 U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
106 U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
107 #ifdef CONFIG_CMD_ADDRMAP
108 U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
110 #ifdef CONFIG_CMD_LOADM
111 U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
115 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
122 for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
123 printf("----Running %s tests----\n", cmd_ut_sub[i].name);
124 retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
132 static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
135 printf("Test suites: %d\n", (int)ARRAY_SIZE(cmd_ut_sub));
136 printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT());
141 static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
146 return CMD_RET_USAGE;
148 /* drop initial "ut" arg */
152 cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
155 return cp->cmd(cmdtp, flag, argc, argv);
157 return CMD_RET_USAGE;
160 #ifdef CONFIG_SYS_LONGHELP
161 static char ut_help_text[] =
162 "[-r] [-f] [<suite>] - run unit tests\n"
163 " -r<runs> Number of times to run each test\n"
164 " -f Force 'manual' tests to run as well\n"
165 " <suite> Test suite to run, or all\n"
167 "\nOptions for <suite>:"
168 "\nall - execute all enabled tests"
169 "\ninfo - show info about tests"
170 #ifdef CONFIG_CMD_ADDRMAP
171 "\naddrmap - very basic test of addrmap command"
173 #ifdef CONFIG_SANDBOX
174 "\nbloblist - bloblist implementation"
176 #ifdef CONFIG_BOOTSTD
177 "\nbootstd - standard boot implementation"
179 #ifdef CONFIG_SANDBOX
180 "\ncompression - compressors and bootm decompression"
183 "\ndm - driver model"
186 "\nenv - environment"
188 #ifdef CONFIG_CMD_FDT
189 "\nfdt - fdt command"
191 #ifdef CONFIG_CONSOLE_TRUETYPE
192 "\nut font - font command\n"
194 #ifdef CONFIG_CMD_LOADM
195 "\nloadm - loadm command parameters and loading memory blob"
198 "\nlib - library functions"
201 "\nlog - logging functions"
203 "\nmem - memory-related commands"
204 #ifdef CONFIG_UT_OPTEE
205 "\noptee - test OP-TEE"
207 #ifdef CONFIG_UT_OVERLAY
208 "\noverlay - device tree overlays"
210 "\nprint - printing things to the console"
211 "\nsetexpr - setexpr command"
212 #ifdef CONFIG_SANDBOX
213 "\nstr - basic test of string functions"
215 #ifdef CONFIG_UT_TIME
216 "\ntime - very basic test of time functions"
218 #if defined(CONFIG_UT_UNICODE) && \
219 !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
220 "\nunicode - Unicode functions"
223 #endif /* CONFIG_SYS_LONGHELP */
226 ut, CONFIG_SYS_MAXARGS, 1, do_ut,
227 "unit tests", ut_help_text