[U-Boot] [PATCH v2 76/80] dm: test: Allow 'dm test' to select a particular test to run

Simon Glass sjg at chromium.org
Wed Mar 25 19:23:04 CET 2015


As well as running all tests, it is useful to be able to run a selected test.

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

Changes in v2: None

 include/dm/test.h   |  7 ++++---
 test/dm/cmd_dm.c    | 11 ++++++++---
 test/dm/test-main.c |  7 +++++--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/include/dm/test.h b/include/dm/test.h
index b310e5f..9c4b8d3 100644
--- a/include/dm/test.h
+++ b/include/dm/test.h
@@ -205,12 +205,13 @@ void dm_leak_check_start(struct dm_test_state *dms);
 
 
 /**
- * dm_test_main() - Run all the tests
+ * dm_test_main() - Run all or one of the tests
  *
- * This runs all available driver model tests
+ * This runs all available driver model tests, or a selected one
  *
+ * @test_name:	Name of test to run, or NULL for all
  * @return 0 if OK, -ve on error
  */
-int dm_test_main(void);
+int dm_test_main(const char *test_name);
 
 #endif
diff --git a/test/dm/cmd_dm.c b/test/dm/cmd_dm.c
index 62e065c..2f527e9 100644
--- a/test/dm/cmd_dm.c
+++ b/test/dm/cmd_dm.c
@@ -113,7 +113,12 @@ static int do_dm_dump_uclass(cmd_tbl_t *cmdtp, int flag, int argc,
 static int do_dm_test(cmd_tbl_t *cmdtp, int flag, int argc,
 			  char * const argv[])
 {
-	return dm_test_main();
+	const char *test_name = NULL;
+
+	if (argc > 0)
+		test_name = argv[0];
+
+	return dm_test_main(test_name);
 }
 #define TEST_HELP "\ndm test         Run tests"
 #else
@@ -133,7 +138,7 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	cmd_tbl_t *test_cmd;
 	int ret;
 
-	if (argc != 2)
+	if (argc < 2)
 		return CMD_RET_USAGE;
 	test_cmd = find_cmd_tbl(argv[1], test_commands,
 				ARRAY_SIZE(test_commands));
@@ -148,7 +153,7 @@ static int do_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-	dm,	2,	1,	do_dm,
+	dm,	3,	1,	do_dm,
 	"Driver model low level access",
 	"tree         Dump driver model tree ('*' = activated)\n"
 	"dm uclass        Dump list of instances for each uclass"
diff --git a/test/dm/test-main.c b/test/dm/test-main.c
index 90ca810..a47bb37 100644
--- a/test/dm/test-main.c
+++ b/test/dm/test-main.c
@@ -65,7 +65,7 @@ static int dm_test_destroy(struct dm_test_state *dms)
 	return 0;
 }
 
-int dm_test_main(void)
+int dm_test_main(const char *test_name)
 {
 	struct dm_test *tests = ll_entry_start(struct dm_test, dm_test);
 	const int n_ents = ll_entry_count(struct dm_test, dm_test);
@@ -83,9 +83,12 @@ int dm_test_main(void)
 		ut_assert(gd->fdt_blob);
 	}
 
-	printf("Running %d driver model tests\n", n_ents);
+	if (!test_name)
+		printf("Running %d driver model tests\n", n_ents);
 
 	for (test = tests; test < tests + n_ents; test++) {
+		if (test_name && strcmp(test_name, test->name))
+			continue;
 		printf("Test: %s\n", test->name);
 		ut_assertok(dm_test_init(dms));
 
-- 
2.2.0.rc0.207.ga3a616c



More information about the U-Boot mailing list