dm: test: Add support for running tests with livetree
It is useful to run the driver model tests with both livetree and flat
tree in case something is different between the two. Add this feature to
the test runner.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 10d2706..88ef267 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -22,7 +22,7 @@
static struct dm_test_state _global_priv_dm_test_state;
/* Get ready for testing */
-static int dm_test_init(struct unit_test_state *uts)
+static int dm_test_init(struct unit_test_state *uts, bool of_live)
{
struct dm_test_state *dms = uts->priv;
@@ -31,7 +31,11 @@
memset(dm_testdrv_op_count, '\0', sizeof(dm_testdrv_op_count));
state_reset_for_test(state_get_current());
- ut_assertok(dm_init(false));
+#ifdef CONFIG_OF_LIVE
+ /* Determine whether to make the live tree available */
+ gd->of_root = of_live ? uts->of_root : NULL;
+#endif
+ ut_assertok(dm_init(of_live));
dms->root = dm_root();
return 0;
@@ -72,13 +76,15 @@
return 0;
}
-static int dm_do_test(struct unit_test_state *uts, struct unit_test *test)
+static int dm_do_test(struct unit_test_state *uts, struct unit_test *test,
+ bool of_live)
{
struct sandbox_state *state = state_get_current();
const char *fname = strrchr(test->file, '/') + 1;
- printf("Test: %s: %s\n", test->name, fname);
- ut_assertok(dm_test_init(uts));
+ printf("Test: %s: %s%s\n", test->name, fname,
+ !of_live ? " (flat tree)" : "");
+ ut_assertok(dm_test_init(uts, of_live));
uts->start = mallinfo();
if (test->flags & DM_TESTF_SCAN_PDATA)
@@ -109,10 +115,10 @@
struct unit_test *tests = ll_entry_start(struct unit_test, dm_test);
const int n_ents = ll_entry_count(struct unit_test, dm_test);
struct unit_test_state *uts = &global_dm_test_state;
- uts->priv = &_global_priv_dm_test_state;
struct unit_test *test;
int run_count;
+ uts->priv = &_global_priv_dm_test_state;
uts->fail_count = 0;
/*
@@ -129,6 +135,9 @@
printf("Running %d driver model tests\n", n_ents);
run_count = 0;
+#ifdef CONFIG_OF_LIVE
+ uts->of_root = gd->of_root;
+#endif
for (test = tests; test < tests + n_ents; test++) {
const char *name = test->name;
@@ -137,7 +146,7 @@
name += 8;
if (test_name && strcmp(test_name, name))
continue;
- ut_assertok(dm_do_test(uts, test));
+ ut_assertok(dm_do_test(uts, test, false));
run_count++;
}