diff --git a/include/test/test.h b/include/test/test.h index 2facf5b3675..5ae90e39e00 100644 --- a/include/test/test.h +++ b/include/test/test.h @@ -96,6 +96,7 @@ struct ut_arg { * @args: Parsed argument values for current test * @arg_count: Number of parsed arguments * @arg_error: Set if ut_str/int/bool() detects a type mismatch + * @keep_record: Preserve console recording when ut_fail() is called * @priv: Private data for tests to use as needed */ struct unit_test_state { @@ -126,6 +127,7 @@ struct unit_test_state { struct ut_arg args[UT_MAX_ARGS]; int arg_count; bool arg_error; + bool keep_record; char priv[UT_PRIV_SIZE]; }; diff --git a/test/cmd_ut.c b/test/cmd_ut.c index adc96fcbcdc..6358f27a64f 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -252,6 +252,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) struct unit_test_state uts; bool show_suites = false; bool force_run = false; + bool keep_record = false; int runs_per_text = 1; struct suite *ste; char *name; @@ -276,6 +277,9 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (!strchr(test_insert, ':')) return CMD_RET_USAGE; break; + case 'R': + keep_record = true; + break; case 's': show_suites = true; break; @@ -288,6 +292,7 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; ut_init_state(&uts); + uts.keep_record = keep_record; name = argv[0]; select_name = cmd_arg1(argc, argv); @@ -333,10 +338,11 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } U_BOOT_LONGHELP(ut, - "[-rs] [-f] [-I:] [ [...]] - run unit tests\n" + "[-rs] [-f] [-R] [-I:] [ [...]] - run unit tests\n" " -r Number of times to run each test\n" " -f Force 'manual' tests to run as well\n" " -I Test to run after other tests have run\n" + " -R Preserve console recording on test failure\n" " -s Show all suites with ut info\n" " Test suite to run (or comma-separated list)\n" " Specific test to run (optional)\n" diff --git a/test/ut.c b/test/ut.c index fe9a177ab53..0677e3fbee9 100644 --- a/test/ut.c +++ b/test/ut.c @@ -23,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; void ut_fail(struct unit_test_state *uts, const char *fname, int line, const char *func, const char *cond) { - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); printf("%s:%d, %s(): %s\n", fname, line, func, cond); uts->cur.fail_count++; } @@ -33,7 +33,7 @@ void ut_failf(struct unit_test_state *uts, const char *fname, int line, { va_list args; - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + ut_unsilence_console(uts); printf("%s:%d, %s(): %s: ", fname, line, func, cond); va_start(args, fmt); vprintf(fmt, args); @@ -286,7 +286,8 @@ void ut_silence_console(struct unit_test_state *uts) void ut_unsilence_console(struct unit_test_state *uts) { - gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); + if (!uts->keep_record) + gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD); } void ut_set_skip_delays(struct unit_test_state *uts, bool skip_delays)