[PATCH v2 23/40] test: Use ut_run_test() to run driver model tests
Simon Glass
sjg at chromium.org
Sun Jan 31 04:32:31 CET 2021
Instead of having a separate function for running driver model tests, use
the common one. Make the pre/post-run functions private since we don't
need these outside of test-main.c
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
include/test/ut.h | 20 --------------------
test/dm/test-dm.c | 11 +----------
test/test-main.c | 26 +++++++++++++++++++++++---
3 files changed, 24 insertions(+), 33 deletions(-)
diff --git a/include/test/ut.h b/include/test/ut.h
index 98f699cbba2..adef0b7e1cf 100644
--- a/include/test/ut.h
+++ b/include/test/ut.h
@@ -367,26 +367,6 @@ void ut_unsilence_console(struct unit_test_state *uts);
*/
void ut_set_skip_delays(struct unit_test_state *uts, bool skip_delays);
-/**
- * test_pre_run() - Handle any preparation needed to run a test
- *
- * @uts: Test state
- * @test: Test to prepare for
- * @return 0 if OK, -EAGAIN to skip this test since some required feature is not
- * available, other -ve on error (meaning that testing cannot likely
- * continue)
- */
-int test_pre_run(struct unit_test_state *uts, struct unit_test *test);
-
-/**
- * test_post_run() - Handle cleaning up after a test
- *
- * @uts: Test state
- * @test: Test to clean up after
- * @return 0 if OK, -ve on error (meaning that testing cannot likely continue)
- */
-int test_post_run(struct unit_test_state *uts, struct unit_test *test);
-
/**
* ut_run_test() - Run a single test
*
diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 90da143bc51..38505c2e7a0 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -24,17 +24,8 @@ struct unit_test_state global_dm_test_state;
static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
bool of_live)
{
- const char *fname = strrchr(test->file, '/') + 1;
-
- printf("Test: %s: %s%s\n", test->name, fname,
- !of_live ? " (flat tree)" : "");
uts->of_live = of_live;
-
- ut_assertok(test_pre_run(uts, test));
-
- test->func(uts);
-
- ut_assertok(test_post_run(uts, test));
+ ut_assertok(ut_run_test(uts, test, test->name));
return 0;
}
diff --git a/test/test-main.c b/test/test-main.c
index dee28d35d82..32c4d4b1996 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -80,7 +80,16 @@ static int do_autoprobe(struct unit_test_state *uts)
return ret;
}
-int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
+/**
+ * test_pre_run() - Handle any preparation needed to run a test
+ *
+ * @uts: Test state
+ * @test: Test to prepare for
+ * @return 0 if OK, -EAGAIN to skip this test since some required feature is not
+ * available, other -ve on error (meaning that testing cannot likely
+ * continue)
+ */
+static int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
{
if (test->flags & UT_TESTF_DM)
ut_assertok(dm_test_pre_run(uts));
@@ -112,7 +121,14 @@ int test_pre_run(struct unit_test_state *uts, struct unit_test *test)
return 0;
}
-int test_post_run(struct unit_test_state *uts, struct unit_test *test)
+/**
+ * test_post_run() - Handle cleaning up after a test
+ *
+ * @uts: Test state
+ * @test: Test to clean up after
+ * @return 0 if OK, -ve on error (meaning that testing cannot likely continue)
+ */
+static int test_post_run(struct unit_test_state *uts, struct unit_test *test)
{
ut_unsilence_console(uts);
if (test->flags & UT_TESTF_DM)
@@ -124,9 +140,13 @@ int test_post_run(struct unit_test_state *uts, struct unit_test *test)
int ut_run_test(struct unit_test_state *uts, struct unit_test *test,
const char *test_name)
{
+ const char *fname = strrchr(test->file, '/') + 1;
+ const char *note = "";
int ret;
- printf("Test: %s\n", test_name);
+ if ((test->flags & UT_TESTF_DM) && !uts->of_live)
+ note = " (flat tree)";
+ printf("Test: %s: %s%s\n", test_name, fname, note);
ret = test_pre_run(uts, test);
if (ret == -EAGAIN)
--
2.30.0.365.g02bc693789-goog
More information about the U-Boot
mailing list