pmic: pca9450: permit config on all bucks and LDOs
[platform/kernel/u-boot.git] / test / cmd_ut.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * (C) Copyright 2015
4  * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5  */
6
7 #include <common.h>
8 #include <command.h>
9 #include <console.h>
10 #include <test/suites.h>
11 #include <test/test.h>
12 #include <test/ut.h>
13
14 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
15                      char *const argv[]);
16
17 int cmd_ut_category(const char *name, const char *prefix,
18                     struct unit_test *tests, int n_ents,
19                     int argc, char *const argv[])
20 {
21         int ret;
22
23         ret = ut_run_list(name, prefix, tests, n_ents,
24                           argc > 1 ? argv[1] : NULL);
25
26         return ret ? CMD_RET_FAILURE : 0;
27 }
28
29 static struct cmd_tbl cmd_ut_sub[] = {
30         U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
31 #ifdef CONFIG_BOOTSTD
32         U_BOOT_CMD_MKENT(bootstd, CONFIG_SYS_MAXARGS, 1, do_ut_bootstd,
33                          "", ""),
34 #endif
35         U_BOOT_CMD_MKENT(common, CONFIG_SYS_MAXARGS, 1, do_ut_common, "", ""),
36 #if defined(CONFIG_UT_DM)
37         U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
38 #endif
39 #if defined(CONFIG_UT_ENV)
40         U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
41 #endif
42 #ifdef CONFIG_UT_OPTEE
43         U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
44 #endif
45 #ifdef CONFIG_UT_OVERLAY
46         U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
47 #endif
48 #ifdef CONFIG_UT_LIB
49         U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
50 #endif
51 #ifdef CONFIG_UT_LOG
52         U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
53 #endif
54         U_BOOT_CMD_MKENT(mem, CONFIG_SYS_MAXARGS, 1, do_ut_mem, "", ""),
55 #ifdef CONFIG_CMD_SETEXPR
56         U_BOOT_CMD_MKENT(setexpr, CONFIG_SYS_MAXARGS, 1, do_ut_setexpr, "",
57                          ""),
58 #endif
59         U_BOOT_CMD_MKENT(print, CONFIG_SYS_MAXARGS, 1, do_ut_print, "", ""),
60 #ifdef CONFIG_UT_TIME
61         U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
62 #endif
63 #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD)
64         U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""),
65 #endif
66 #ifdef CONFIG_SANDBOX
67         U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
68                          "", ""),
69         U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
70                          "", ""),
71         U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""),
72 #endif
73         U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),
74 #ifdef CONFIG_CMD_ADDRMAP
75         U_BOOT_CMD_MKENT(addrmap, CONFIG_SYS_MAXARGS, 1, do_ut_addrmap, "", ""),
76 #endif
77 #ifdef CONFIG_CMD_LOADM
78         U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
79 #endif
80 };
81
82 static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
83                      char *const argv[])
84 {
85         int i;
86         int retval;
87         int any_fail = 0;
88
89         for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
90                 printf("----Running %s tests----\n", cmd_ut_sub[i].name);
91                 retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
92                 if (!any_fail)
93                         any_fail = retval;
94         }
95
96         return any_fail;
97 }
98
99 static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
100 {
101         struct cmd_tbl *cp;
102
103         if (argc < 2)
104                 return CMD_RET_USAGE;
105
106         /* drop initial "ut" arg */
107         argc--;
108         argv++;
109
110         cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
111
112         if (cp)
113                 return cp->cmd(cmdtp, flag, argc, argv);
114
115         return CMD_RET_USAGE;
116 }
117
118 #ifdef CONFIG_SYS_LONGHELP
119 static char ut_help_text[] =
120         "all - execute all enabled tests\n"
121 #ifdef CONFIG_SANDBOX
122         "ut bloblist - Test bloblist implementation\n"
123         "ut compression - Test compressors and bootm decompression\n"
124 #endif
125 #ifdef CONFIG_BOOTSTD
126         "ut bootstd - Test standard boot implementation\n"
127 #endif
128 #ifdef CONFIG_UT_DM
129         "ut dm [test-name]\n"
130 #endif
131 #ifdef CONFIG_UT_ENV
132         "ut env [test-name]\n"
133 #endif
134 #ifdef CONFIG_UT_LIB
135         "ut lib [test-name] - test library functions\n"
136 #endif
137 #ifdef CONFIG_UT_LOG
138         "ut log [test-name] - test logging functions\n"
139 #endif
140         "ut mem [test-name] - test memory-related commands\n"
141 #ifdef CONFIG_UT_OPTEE
142         "ut optee [test-name]\n"
143 #endif
144 #ifdef CONFIG_UT_OVERLAY
145         "ut overlay [test-name]\n"
146 #endif
147         "ut print [test-name]  - test printing\n"
148         "ut setexpr [test-name] - test setexpr command\n"
149 #ifdef CONFIG_SANDBOX
150         "ut str - Basic test of string functions\n"
151 #endif
152 #ifdef CONFIG_UT_TIME
153         "ut time - Very basic test of time functions\n"
154 #endif
155 #if defined(CONFIG_UT_UNICODE) && \
156         !defined(CONFIG_SPL_BUILD) && !defined(API_BUILD)
157         "ut unicode [test-name] - test Unicode functions\n"
158 #endif
159 #ifdef CONFIG_CMD_ADDRMAP
160         "ut addrmap - Very basic test of addrmap command\n"
161 #endif
162 #ifdef CONFIG_CMD_LOADM
163         "ut loadm [test-name]- test of parameters and load memory blob\n"
164 #endif
165         ;
166 #endif /* CONFIG_SYS_LONGHELP */
167
168 U_BOOT_CMD(
169         ut, CONFIG_SYS_MAXARGS, 1, do_ut,
170         "unit tests", ut_help_text
171 );