]> git.ipfire.org Git - people/ms/u-boot.git/blob - test/cmd_ut.c
test: Add a common unit test command
[people/ms/u-boot.git] / test / cmd_ut.c
1 /*
2 * (C) Copyright 2015
3 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
4 *
5 * SPDX-License-Identifier: GPL-2.0
6 */
7
8 #include <common.h>
9 #include <command.h>
10 #include <test/suites.h>
11
12 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
13
14 static cmd_tbl_t cmd_ut_sub[] = {
15 U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
16 };
17
18 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
19 {
20 int i;
21 int retval;
22 int any_fail = 0;
23
24 for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
25 printf("----Running %s tests----\n", cmd_ut_sub[i].name);
26 retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
27 if (!any_fail)
28 any_fail = retval;
29 }
30
31 return any_fail;
32 }
33
34 static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
35 {
36 cmd_tbl_t *cp;
37
38 if (argc < 2)
39 return CMD_RET_USAGE;
40
41 /* drop initial "ut" arg */
42 argc--;
43 argv++;
44
45 cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
46
47 if (cp)
48 return cp->cmd(cmdtp, flag, argc, argv);
49
50 return CMD_RET_USAGE;
51 }
52
53 #ifdef CONFIG_SYS_LONGHELP
54 static char ut_help_text[] =
55 "all - execute all enabled tests\n"
56 ;
57 #endif
58
59 U_BOOT_CMD(
60 ut, CONFIG_SYS_MAXARGS, 1, do_ut,
61 "unit tests", ut_help_text
62 );