test: Allow running a selection of suites

Enhance the ut command to accept a comma-separated list of test suites
to run. Report the summary information for these at the end.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2025-02-07 11:30:57 -07:00 committed by Tom Rini
parent 32aba887e3
commit fa0b68d22a
3 changed files with 26 additions and 13 deletions

View file

@ -218,7 +218,6 @@ static int do_ut_all(struct unit_test_state *uts, struct cmd_tbl *cmdtp,
update_stats(uts, ste); update_stats(uts, ste);
} }
} }
ut_report(&uts->total, uts->run_count);
return any_fail; return any_fail;
} }
@ -282,7 +281,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{ {
struct unit_test_state uts; struct unit_test_state uts;
struct suite *ste; struct suite *ste;
const char *name; char *name;
int ret; int ret;
if (argc < 2) if (argc < 2)
@ -299,17 +298,26 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
} else if (!strcmp(name, "info")) { } else if (!strcmp(name, "info")) {
ret = do_ut_info(cmdtp, flag, argc, argv); ret = do_ut_info(cmdtp, flag, argc, argv);
} else { } else {
ste = find_suite(argv[0]); int any_fail = 0;
if (!ste) { const char *p;
printf("Suite '%s' not found\n", argv[0]);
return CMD_RET_FAILURE;
} else if (!has_tests(ste)) {
/* perhaps a Kconfig option needs to be set? */
printf("Suite '%s' is not enabled\n", argv[0]);
return CMD_RET_FAILURE;
}
ret = run_suite(&uts, ste, cmdtp, flag, argc, argv); for (; p = strsep(&name, ","), p; name = NULL) {
ste = find_suite(p);
if (!ste) {
printf("Suite '%s' not found\n", p);
return CMD_RET_FAILURE;
} else if (!has_tests(ste)) {
/* perhaps a Kconfig option needs to be set? */
printf("Suite '%s' is not enabled\n", p);
return CMD_RET_FAILURE;
}
ret = run_suite(&uts, ste, cmdtp, flag, argc, argv);
if (!any_fail)
any_fail = ret;
update_stats(&uts, ste);
}
ret = any_fail;
} }
show_stats(&uts); show_stats(&uts);
if (ret) if (ret)

View file

@ -187,3 +187,8 @@ def xtest_suite(u_boot_console, u_boot_config):
assert suite_count == len(EXPECTED_SUITES) assert suite_count == len(EXPECTED_SUITES)
assert total_test_count == len(all_tests) assert total_test_count == len(all_tests)
# Run three suites
with cons.log.section('Check multiple suites'):
output = cons.run_command('ut bloblist,setexpr,mem')
assert 'Suites run: 3' in output

View file

@ -683,7 +683,7 @@ static int ut_run_tests(struct unit_test_state *uts, const char *prefix,
void ut_report(struct ut_stats *stats, int run_count) void ut_report(struct ut_stats *stats, int run_count)
{ {
if (run_count > 1) if (run_count > 1)
printf("Total tests"); printf("Suites run: %d, total tests", run_count);
else else
printf("Tests"); printf("Tests");
printf(" run: %d, ", stats->test_count); printf(" run: %d, ", stats->test_count);