Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 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> |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 11 | #include <test/test.h> |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 12 | |
| 13 | static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
| 14 | |
Simon Glass | 81cbe1c | 2017-11-25 11:57:29 -0700 | [diff] [blame] | 15 | int 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 Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 39 | static cmd_tbl_t cmd_ut_sub[] = { |
| 40 | U_BOOT_CMD_MKENT(all, CONFIG_SYS_MAXARGS, 1, do_ut_all, "", ""), |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 41 | #if defined(CONFIG_UT_DM) |
| 42 | U_BOOT_CMD_MKENT(dm, CONFIG_SYS_MAXARGS, 1, do_ut_dm, "", ""), |
| 43 | #endif |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 44 | #if defined(CONFIG_UT_ENV) |
| 45 | U_BOOT_CMD_MKENT(env, CONFIG_SYS_MAXARGS, 1, do_ut_env, "", ""), |
| 46 | #endif |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_UT_OVERLAY |
| 48 | U_BOOT_CMD_MKENT(overlay, CONFIG_SYS_MAXARGS, 1, do_ut_overlay, "", ""), |
| 49 | #endif |
Joe Hershberger | ee20efe | 2015-05-20 14:27:30 -0500 | [diff] [blame] | 50 | #ifdef CONFIG_UT_TIME |
| 51 | U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""), |
| 52 | #endif |
Simon Glass | 1edaed0 | 2017-11-25 11:57:33 -0700 | [diff] [blame] | 53 | #ifdef CONFIG_SANDBOX |
| 54 | U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression, |
| 55 | "", ""), |
| 56 | #endif |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | static 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 | |
| 75 | static 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 |
| 95 | static char ut_help_text[] = |
| 96 | "all - execute all enabled tests\n" |
Joe Hershberger | 9dc1d71 | 2015-05-20 14:27:29 -0500 | [diff] [blame] | 97 | #ifdef CONFIG_UT_DM |
| 98 | "ut dm [test-name]\n" |
| 99 | #endif |
Joe Hershberger | 26e038f | 2015-05-20 14:27:36 -0500 | [diff] [blame] | 100 | #ifdef CONFIG_UT_ENV |
| 101 | "ut env [test-name]\n" |
| 102 | #endif |
Maxime Ripard | 0e31a11 | 2016-07-05 10:26:46 +0200 | [diff] [blame] | 103 | #ifdef CONFIG_UT_OVERLAY |
| 104 | "ut overlay [test-name]\n" |
| 105 | #endif |
Joe Hershberger | ee20efe | 2015-05-20 14:27:30 -0500 | [diff] [blame] | 106 | #ifdef CONFIG_UT_TIME |
| 107 | "ut time - Very basic test of time functions\n" |
| 108 | #endif |
Simon Glass | 1edaed0 | 2017-11-25 11:57:33 -0700 | [diff] [blame] | 109 | #ifdef CONFIG_SANDBOX |
| 110 | "ut compression - Test compressors and bootm decompression\n" |
| 111 | #endif |
Joe Hershberger | 11dd7cc | 2015-05-20 14:27:28 -0500 | [diff] [blame] | 112 | ; |
| 113 | #endif |
| 114 | |
| 115 | U_BOOT_CMD( |
| 116 | ut, CONFIG_SYS_MAXARGS, 1, do_ut, |
| 117 | "unit tests", ut_help_text |
| 118 | ); |