blob: 6b24f463f3329d2eb300e1999e94a636cfb89ab0 [file] [log] [blame]
Joe Hershbergerc617ede2015-05-20 14:27:28 -05001/*
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>
Simon Glass4d869c12017-11-25 11:57:29 -070011#include <test/test.h>
Joe Hershbergerc617ede2015-05-20 14:27:28 -050012
13static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
14
Simon Glass4d869c12017-11-25 11:57:29 -070015int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
16 int argc, char * const argv[])
17{
18 struct unit_test_state uts = { .fail_count = 0 };
19 struct unit_test *test;
20
21 if (argc == 1)
22 printf("Running %d %s tests\n", n_ents, name);
23
24 for (test = tests; test < tests + n_ents; test++) {
25 if (argc > 1 && strcmp(argv[1], test->name))
26 continue;
27 printf("Test: %s\n", test->name);
28
29 uts.start = mallinfo();
30
31 test->func(&uts);
32 }
33
34 printf("Failures: %d\n", uts.fail_count);
35
36 return uts.fail_count ? CMD_RET_FAILURE : 0;
37}
38
Joe Hershbergerc617ede2015-05-20 14:27:28 -050039static cmd_tbl_t cmd_ut_sub[] = {
40 U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""),
Joe Hershberger40441e02015-05-20 14:27:29 -050041#if defined(CONFIG_UT_DM)
42 U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""),
43#endif
Joe Hershberger421f86f2015-05-20 14:27:36 -050044#if defined(CONFIG_UT_ENV)
45 U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""),
46#endif
Maxime Ripardf2a99422016-07-05 10:26:46 +020047#ifdef CONFIG_UT_OVERLAY
48 U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""),
49#endif
Joe Hershbergerc812f722015-05-20 14:27:30 -050050#ifdef CONFIG_UT_TIME
51 U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
52#endif
Simon Glass0aac10f2017-11-25 11:57:33 -070053#ifdef CONFIG_SANDBOX
54 U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression,
55 "", ""),
56#endif
Joe Hershbergerc617ede2015-05-20 14:27:28 -050057};
58
59static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
60{
61 int i;
62 int retval;
63 int any_fail = 0;
64
65 for (i = 1; i < ARRAY_SIZE(cmd_ut_sub); i++) {
66 printf("----Running %s tests----\n", cmd_ut_sub[i].name);
67 retval = cmd_ut_sub[i].cmd(cmdtp, flag, 1, &cmd_ut_sub[i].name);
68 if (!any_fail)
69 any_fail = retval;
70 }
71
72 return any_fail;
73}
74
75static int do_ut(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
76{
77 cmd_tbl_t *cp;
78
79 if (argc < 2)
80 return CMD_RET_USAGE;
81
82 /* drop initial "ut" arg */
83 argc--;
84 argv++;
85
86 cp = find_cmd_tbl(argv[0], cmd_ut_sub, ARRAY_SIZE(cmd_ut_sub));
87
88 if (cp)
89 return cp->cmd(cmdtp, flag, argc, argv);
90
91 return CMD_RET_USAGE;
92}
93
94#ifdef CONFIG_SYS_LONGHELP
95static char ut_help_text[] =
96 "all - execute all enabled tests\n"
Joe Hershberger40441e02015-05-20 14:27:29 -050097#ifdef CONFIG_UT_DM
98 "ut dm [test-name]\n"
99#endif
Joe Hershberger421f86f2015-05-20 14:27:36 -0500100#ifdef CONFIG_UT_ENV
101 "ut env [test-name]\n"
102#endif
Maxime Ripardf2a99422016-07-05 10:26:46 +0200103#ifdef CONFIG_UT_OVERLAY
104 "ut overlay [test-name]\n"
105#endif
Joe Hershbergerc812f722015-05-20 14:27:30 -0500106#ifdef CONFIG_UT_TIME
107 "ut time - Very basic test of time functions\n"
108#endif
Simon Glass0aac10f2017-11-25 11:57:33 -0700109#ifdef CONFIG_SANDBOX
110 "ut compression - Test compressors and bootm decompression\n"
111#endif
Joe Hershbergerc617ede2015-05-20 14:27:28 -0500112 ;
113#endif
114
115U_BOOT_CMD(
116 ut, CONFIG_SYS_MAXARGS, 1, do_ut,
117 "unit tests", ut_help_text
118);