xref: /rk3399_rockchip-uboot/test/cmd_ut.c (revision c812f722f8bdf2785cfebf4fd272afe2117d6469)
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 #if defined(CONFIG_UT_DM)
17 	U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
18 #endif
19 #ifdef CONFIG_UT_TIME
20 	U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
21 #endif
22 };
23 
24 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
25 {
26 	int i;
27 	int retval;
28 	int any_fail = 0;
29 
30 	for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
31 		printf("----Running %s tests----\n", cmd_ut_sub[i].name);
32 		retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
33 		if (!any_fail)
34 			any_fail = retval;
35 	}
36 
37 	return any_fail;
38 }
39 
40 static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
41 {
42 	cmd_tbl_t *cp;
43 
44 	if (argc < 2)
45 		return CMD_RET_USAGE;
46 
47 	/* drop initial "ut" arg */
48 	argc--;
49 	argv++;
50 
51 	cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
52 
53 	if (cp)
54 		return cp->cmd(cmdtp, flag, argc, argv);
55 
56 	return CMD_RET_USAGE;
57 }
58 
59 #ifdef CONFIG_SYS_LONGHELP
60 static char ut_help_text[] =
61 	"all - execute all enabled tests\n"
62 #ifdef CONFIG_UT_DM
63 	"ut dm [test-name]\n"
64 #endif
65 #ifdef CONFIG_UT_TIME
66 	"ut time - Very basic test of time functions\n"
67 #endif
68 	;
69 #endif
70 
71 U_BOOT_CMD(
72 	ut, CONFIG_SYS_MAXARGS, 1, do_ut,
73 	"unit tests", ut_help_text
74 );
75