diff mbox series

[v4,13/42] test: Call test_pre/post_run() from driver model tests

Message ID 20210304135118.643277-13-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show
Series test: Refactor tests to have a single test runner | expand

Commit Message

Simon Glass March 4, 2021, 1:50 p.m. UTC
Ultimately we want to get rid of the special driver model test init and
use test_pre_run() and test_post_run() for all tests. As a first step,
use those function to handle console recording.

For now we need a special case for setting uts->start, but that wil go
away once all init is in one place.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 include/dm/test.h |  2 +-
 test/dm/test-dm.c | 10 +++++-----
 test/test-main.c  |  8 +++++++-
 3 files changed, 13 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/include/dm/test.h b/include/dm/test.h
index dfbc82c756d..c0b463cc0f1 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -144,7 +144,7 @@  struct dm_test_state {
 
 /* Declare a new driver model test */
 #define DM_TEST(_name, _flags) \
-	UNIT_TEST(_name, UT_TESTF_DM | (_flags), dm_test)
+	UNIT_TEST(_name, UT_TESTF_DM | UT_TESTF_CONSOLE_REC | (_flags), dm_test)
 
 /*
  * struct sandbox_sdl_plat - Platform data for the SDL video driver
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 71e9cf6e5da..69a0349d04c 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -97,14 +97,14 @@  static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
 	    (test->flags & UT_TESTF_SCAN_FDT))
 		ut_assertok(dm_extended_scan(false));
 
-	/*
-	 * Silence the console and rely on console recording to get
-	 * our output.
-	 */
-	console_record_reset_enable();
+	ut_assertok(test_pre_run(uts, test));
+
 	if (!state->show_test_output)
 		gd->flags |= GD_FLG_SILENT;
 	test->func(uts);
+
+	ut_assertok(test_post_run(uts, test));
+
 	gd->flags &= ~(GD_FLG_SILENT | GD_FLG_RECORD);
 	state_set_skip_delays(false);
 
diff --git a/test/test-main.c b/test/test-main.c
index 7961fd8aa3e..9c600094740 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -8,9 +8,13 @@ 
 #include <console.h>
 #include <test/test.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 {
-	uts->start = mallinfo();
+	/* DM tests have already done this */
+	if (!(test->flags & UT_TESTF_DM))
+		uts->start = mallinfo();
 
 	if (test->flags & UT_TESTF_CONSOLE_REC) {
 		int ret = console_record_reset_enable();
@@ -26,6 +30,8 @@  int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
 
 int test_post_run(struct unit_test_state *uts, struct unit_test *test)
 {
+	gd->flags &= ~GD_FLG_RECORD;
+
 	return 0;
 }