[PATCH v4 31/42] test: Move the devicetree check into ut_run_list()

Simon Glass sjg at chromium.org
Thu Mar 4 14:51:07 CET 2021


Add a check to ut_run_list() as to whether a list has driver model tests.
Move the logic for the test devicetree into that function, in an effort
to eventually remove all logic from dm_test_run().

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

(no changes since v1)

 test/dm/test-dm.c | 13 -------------
 test/test-main.c  | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/test/dm/test-dm.c b/test/dm/test-dm.c
index 54e6577b009..8cb99ed80cc 100644
--- a/test/dm/test-dm.c
+++ b/test/dm/test-dm.c
@@ -24,22 +24,9 @@ int dm_test_run(const char *test_name)
 {
 	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_s = { .fail_count = 0 }, *uts = &uts_s;
 	struct device_node *of_root;
 	int ret;
 
-	if (!CONFIG_IS_ENABLED(OF_PLATDATA)) {
-		/*
-		 * If we have no device tree, or it only has a root node, then
-		 * these * tests clearly aren't going to work...
-		 */
-		if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
-			puts("Please run with test device tree:\n"
-			     "    ./u-boot -d arch/sandbox/dts/test.dtb\n");
-			return CMD_RET_FAILURE;
-		}
-	}
-
 	of_root = gd_of_root();
 	ret = ut_run_list("driver model", "dm_test_", tests, n_ents, test_name);
 
diff --git a/test/test-main.c b/test/test-main.c
index 16c0d13ea55..8138fb43875 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -143,6 +143,25 @@ static bool test_matches(const char *prefix, const char *test_name,
 	return false;
 }
 
+/*
+ * ut_list_has_dm_tests() - Check if a list of tests has driver model ones
+ *
+ * @tests: List of tests to run
+ * @count: Number of tests to ru
+ * @return true if any of the tests have the UT_TESTF_DM flag
+ */
+static bool ut_list_has_dm_tests(struct unit_test *tests, int count)
+{
+	struct unit_test *test;
+
+	for (test = tests; test < tests + count; test++) {
+		if (test->flags & UT_TESTF_DM)
+			return true;
+	}
+
+	return false;
+}
+
 /**
  * test_pre_run() - Handle any preparation needed to run a test
  *
@@ -342,6 +361,19 @@ int ut_run_list(const char *category, const char *prefix,
 	struct unit_test_state uts = { .fail_count = 0 };
 	int ret;
 
+	if (!CONFIG_IS_ENABLED(OF_PLATDATA) &&
+	    ut_list_has_dm_tests(tests, count)) {
+		/*
+		 * If we have no device tree, or it only has a root node, then
+		 * these * tests clearly aren't going to work...
+		 */
+		if (!gd->fdt_blob || fdt_next_node(gd->fdt_blob, 0, NULL) < 0) {
+			puts("Please run with test device tree:\n"
+			     "    ./u-boot -d arch/sandbox/dts/test.dtb\n");
+			return CMD_RET_FAILURE;
+		}
+	}
+
 	if (!select_name)
 		printf("Running %d %s tests\n", count, category);
 
-- 
2.30.1.766.gb4fecdf3b7-goog



More information about the U-Boot mailing list