blob: 11c219b48acc59e1dbbd3cdf75d243ace5b5865c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Joe Hershberger11dd7cc2015-05-20 14:27:28 -05002/*
3 * (C) Copyright 2015
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
Joe Hershberger11dd7cc2015-05-20 14:27:28 -05005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass6db8ea52020-07-28 19:41:13 -06009#include <console.h>
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050010#include <test/suites.h>
Simon Glass81cbe1c2017-11-25 11:57:29 -070011#include <test/test.h>
Simon Glass5722fb22021-03-07 17:34:47 -070012#include <test/ut.h>
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050013
Simon Glassed38aef2020-05-10 11:40:03 -060014static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[]);
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050016
Philippe Reynes1f99f842019-12-17 19:07:04 +010017int cmd_ut_category(const char *name, const char *prefix,
18 struct unit_test *tests, int n_ents,
Simon Glassed38aef2020-05-10 11:40:03 -060019 int argc, char *const argv[])
Simon Glass81cbe1c2017-11-25 11:57:29 -070020{
Simon Glass91a187b2022-08-01 07:58:45 -060021 int runs_per_text = 1;
Simon Glass5722fb22021-03-07 17:34:47 -070022 int ret;
Simon Glass81cbe1c2017-11-25 11:57:29 -070023
Simon Glass91a187b2022-08-01 07:58:45 -060024 if (argc > 1 && !strncmp("-r", argv[1], 2)) {
25 runs_per_text = dectoul(argv[1] + 2, NULL);
26 argv++;
27 argc++;
28 }
29
Simon Glass5722fb22021-03-07 17:34:47 -070030 ret = ut_run_list(name, prefix, tests, n_ents,
Simon Glass91a187b2022-08-01 07:58:45 -060031 argc > 1 ? argv[1] : NULL, runs_per_text);
Simon Glass81cbe1c2017-11-25 11:57:29 -070032
Simon Glass5722fb22021-03-07 17:34:47 -070033 return ret ? CMD_RET_FAILURE : 0;
Simon Glass81cbe1c2017-11-25 11:57:29 -070034}
35
Simon Glassed38aef2020-05-10 11:40:03 -060036static struct cmd_tbl cmd_ut_sub[] = {
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050037 U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
Simon Glassb255efc2022-04-24 23:31:24 -060038#ifdef CONFIG_BOOTSTD
39 U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
40 "", ""),
41#endif
Steffen Jaeckele1788f92021-07-08 15:57:40 +020042 U_BOOT_CMD_MKENT(common, CONFIG_SYS_MAXARGS, 1, do_ut_common, "", ""),
Joe Hershberger9dc1d712015-05-20 14:27:29 -050043#if defined(CONFIG_UT_DM)
44 U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
45#endif
Joe Hershberger26e038f2015-05-20 14:27:36 -050046#if defined(CONFIG_UT_ENV)
47 U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
48#endif
Simon Glassf3c6a1d2022-07-13 06:06:59 -060049#ifdef CONFIG_CMD_FDT
50 U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""),
51#endif
Heiko Stuebner1c9bb9b2019-10-23 16:46:41 +020052#ifdef CONFIG_UT_OPTEE
53 U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
54#endif
Maxime Ripard0e31a112016-07-05 10:26:46 +020055#ifdef CONFIG_UT_OVERLAY
56 U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
57#endif
Heinrich Schuchardtf77a6352019-01-30 07:53:31 +010058#ifdef CONFIG_UT_LIB
59 U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
60#endif
Heinrich Schuchardtf433d502020-02-26 21:48:18 +010061#ifdef CONFIG_UT_LOG
62 U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
63#endif
Simon Glass573c0fa2020-07-28 19:41:14 -060064 U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
Heinrich Schuchardtc33f85e2021-02-17 12:58:14 +010065#ifdef CONFIG_CMD_SETEXPR
Simon Glass663a2c12020-11-01 14:15:35 -070066 U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
67 ""),
Heinrich Schuchardtc33f85e2021-02-17 12:58:14 +010068#endif
Simon Glassd2423682021-05-08 06:59:58 -060069 U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
Joe Hershbergeree20efe2015-05-20 14:27:30 -050070#ifdef CONFIG_UT_TIME
71 U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
72#endif
Heinrich Schuchardtb8b6c812018-08-31 21:31:28 +020073#if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
74 U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
75#endif
Simon Glass1edaed02017-11-25 11:57:33 -070076#ifdef CONFIG_SANDBOX
77 U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
78 "", ""),
Simon Glass78b0ef52018-11-15 18:43:53 -070079 U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
80 "", ""),
Simon Glass07a88862020-11-05 10:33:38 -070081 U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
Simon Glass1edaed02017-11-25 11:57:33 -070082#endif
Heinrich Schuchardt92111812021-01-18 00:17:34 +010083 U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
Bin Meng261fc062021-02-25 17:22:35 +080084#ifdef CONFIG_CMD_ADDRMAP
85 U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
86#endif
Rui Miguel Silva433f15a2022-05-11 10:55:40 +010087#ifdef CONFIG_CMD_LOADM
88 U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
89#endif
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050090};
91
Simon Glassed38aef2020-05-10 11:40:03 -060092static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
93 char *const argv[])
Joe Hershberger11dd7cc2015-05-20 14:27:28 -050094{
95 int i;
96 int retval;
97 int any_fail = 0;
98
99 for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
100 printf("----Running %s tests----\n", cmd_ut_sub[i].name);
101 retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
102 if (!any_fail)
103 any_fail = retval;
104 }
105
106 return any_fail;
107}
108
Simon Glassed38aef2020-05-10 11:40:03 -0600109static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Joe Hershberger11dd7cc2015-05-20 14:27:28 -0500110{
Simon Glassed38aef2020-05-10 11:40:03 -0600111 struct cmd_tbl *cp;
Joe Hershberger11dd7cc2015-05-20 14:27:28 -0500112
113 if (argc < 2)
114 return CMD_RET_USAGE;
115
116 /* drop initial "ut" arg */
117 argc--;
118 argv++;
119
120 cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
121
122 if (cp)
123 return cp->cmd(cmdtp, flag, argc, argv);
124
125 return CMD_RET_USAGE;
126}
127
128#ifdef CONFIG_SYS_LONGHELP
129static char ut_help_text[] =
130 "all - execute all enabled tests\n"
Heinrich Schuchardtb8b6c812018-08-31 21:31:28 +0200131#ifdef CONFIG_SANDBOX
Simon Glass78b0ef52018-11-15 18:43:53 -0700132 "ut bloblist - Test bloblist implementation\n"
Heinrich Schuchardtb8b6c812018-08-31 21:31:28 +0200133 "ut compression - Test compressors and bootm decompression\n"
134#endif
Simon Glassb255efc2022-04-24 23:31:24 -0600135#ifdef CONFIG_BOOTSTD
136 "ut bootstd - Test standard boot implementation\n"
137#endif
Joe Hershberger9dc1d712015-05-20 14:27:29 -0500138#ifdef CONFIG_UT_DM
139 "ut dm [test-name]\n"
140#endif
Joe Hershberger26e038f2015-05-20 14:27:36 -0500141#ifdef CONFIG_UT_ENV
142 "ut env [test-name]\n"
143#endif
Simon Glassf3c6a1d2022-07-13 06:06:59 -0600144#ifdef CONFIG_CMD_FDT
145 "ut fdt [test-name] - test of the fdt command\n"
146#endif
Heinrich Schuchardtf77a6352019-01-30 07:53:31 +0100147#ifdef CONFIG_UT_LIB
148 "ut lib [test-name] - test library functions\n"
149#endif
Heinrich Schuchardtf433d502020-02-26 21:48:18 +0100150#ifdef CONFIG_UT_LOG
151 "ut log [test-name] - test logging functions\n"
152#endif
Simon Glass573c0fa2020-07-28 19:41:14 -0600153 "ut mem [test-name] - test memory-related commands\n"
Heiko Stuebner1c9bb9b2019-10-23 16:46:41 +0200154#ifdef CONFIG_UT_OPTEE
155 "ut optee [test-name]\n"
156#endif
Maxime Ripard0e31a112016-07-05 10:26:46 +0200157#ifdef CONFIG_UT_OVERLAY
158 "ut overlay [test-name]\n"
159#endif
Simon Glassd2423682021-05-08 06:59:58 -0600160 "ut print [test-name] - test printing\n"
Simon Glass663a2c12020-11-01 14:15:35 -0700161 "ut setexpr [test-name] - test setexpr command\n"
Simon Glassd0509282020-04-08 08:32:55 -0600162#ifdef CONFIG_SANDBOX
163 "ut str - Basic test of string functions\n"
164#endif
Joe Hershbergeree20efe2015-05-20 14:27:30 -0500165#ifdef CONFIG_UT_TIME
166 "ut time - Very basic test of time functions\n"
167#endif
Heinrich Schuchardtb8b6c812018-08-31 21:31:28 +0200168#if defined(CONFIG_UT_UNICODE) && \
169 !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
170 "ut unicode [test-name] - test Unicode functions\n"
Simon Glass1edaed02017-11-25 11:57:33 -0700171#endif
Bin Meng261fc062021-02-25 17:22:35 +0800172#ifdef CONFIG_CMD_ADDRMAP
173 "ut addrmap - Very basic test of addrmap command\n"
174#endif
Rui Miguel Silva433f15a2022-05-11 10:55:40 +0100175#ifdef CONFIG_CMD_LOADM
176 "ut loadm [test-name]- test of parameters and load memory blob\n"
177#endif
Simon Glass91a187b2022-08-01 07:58:45 -0600178 "All commands accept an optional [-r<runs>] flag before [test-name], to\n"
179 "run each test multiple times (<runs> is in decimal)";
Heinrich Schuchardtb8b6c812018-08-31 21:31:28 +0200180#endif /* CONFIG_SYS_LONGHELP */
Joe Hershberger11dd7cc2015-05-20 14:27:28 -0500181
182U_BOOT_CMD(
183 ut, CONFIG_SYS_MAXARGS, 1, do_ut,
184 "unit tests", ut_help_text
185);