Sfoglia il codice sorgente

cmd_ut: add a parameter prefix to the function cmd_ut_category

There is black magic in the file conftest.py that list
all the test unit. Then, all those test unit are called
in pytest. This call is done with the end of the name
(for example checksum if the full name is bloblist_test_checksum).

The result is that only test for dm are really executed.
by pytest, all others tests are listed but never executed.

This behaviour happens because the dm test unit only check
the end of the name and others tests checks the full name.

To fix this issue, I've added a prefix to the function
cmd_ut_category, and this prefix is removed when looking
for the unit test.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Philippe Reynes 4 anni fa
parent
commit
4ad4edfe77

+ 3 - 1
include/test/suites.h

@@ -13,6 +13,7 @@ struct unit_test;
  * cmd_ut_category() - Run a category of unit tests
  *
  * @name:	Category name
+ * @prefix:	Prefix of test name
  * @tests:	List of tests to run
  * @n_ents:	Number of tests in @tests
  * @argc:	Argument count provided. Must be >= 1. If this is 1 then all
@@ -20,7 +21,8 @@ struct unit_test;
  * @argv:	Arguments: argv[1] is the test to run (if @argc >= 2)
  * @return 0 if OK, CMD_RET_FAILURE on failure
  */
-int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
+int cmd_ut_category(const char *name, const char *prefix,
+		    struct unit_test *tests, int n_ents,
 		    int argc, char * const argv[]);
 
 int do_ut_bloblist(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);

+ 2 - 1
test/bloblist.c

@@ -183,5 +183,6 @@ int do_ut_bloblist(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 						 bloblist_test);
 	const int n_ents = ll_entry_count(struct unit_test, bloblist_test);
 
-	return cmd_ut_category("bloblist", tests, n_ents, argc, argv);
+	return cmd_ut_category("bloblist", "bloblist_test_",
+			       tests, n_ents, argc, argv);
 }

+ 10 - 2
test/cmd_ut.c

@@ -11,17 +11,25 @@
 
 static int do_ut_all(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
-int cmd_ut_category(const char *name, struct unit_test *tests, int n_ents,
+int cmd_ut_category(const char *name, const char *prefix,
+		    struct unit_test *tests, int n_ents,
 		    int argc, char * const argv[])
 {
 	struct unit_test_state uts = { .fail_count = 0 };
 	struct unit_test *test;
+	int prefix_len = prefix ? strlen(prefix) : 0;
 
 	if (argc == 1)
 		printf("Running %d %s tests\n", n_ents, name);
 
 	for (test = tests; test < tests + n_ents; test++) {
-		if (argc > 1 && strcmp(argv[1], test->name))
+		const char *test_name = test->name;
+
+		/* Remove the prefix */
+		if (!strncmp(test_name, prefix, prefix_len))
+			test_name += prefix_len;
+
+		if (argc > 1 && strcmp(argv[1], test_name))
 			continue;
 		printf("Test: %s\n", test->name);
 

+ 2 - 1
test/compression.c

@@ -540,5 +540,6 @@ int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 						 compression_test);
 	const int n_ents = ll_entry_count(struct unit_test, compression_test);
 
-	return cmd_ut_category("compression", tests, n_ents, argc, argv);
+	return cmd_ut_category("compression", "compression_test_",
+			       tests, n_ents, argc, argv);
 }

+ 2 - 1
test/env/cmd_ut_env.c

@@ -15,5 +15,6 @@ int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct unit_test *tests = ll_entry_start(struct unit_test, env_test);
 	const int n_ents = ll_entry_count(struct unit_test, env_test);
 
-	return cmd_ut_category("environment", tests, n_ents, argc, argv);
+	return cmd_ut_category("environment", "env_test_",
+			       tests, n_ents, argc, argv);
 }

+ 1 - 1
test/lib/cmd_ut_lib.c

@@ -16,5 +16,5 @@ int do_ut_lib(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct unit_test *tests = ll_entry_start(struct unit_test, lib_test);
 	const int n_ents = ll_entry_count(struct unit_test, lib_test);
 
-	return cmd_ut_category("lib", tests, n_ents, argc, argv);
+	return cmd_ut_category("lib", "lib_test_", tests, n_ents, argc, argv);
 }

+ 3 - 3
test/optee/cmd_ut_optee.c

@@ -129,20 +129,20 @@ int do_ut_optee(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	ut_assertok(optee_copy_fdt_nodes(fdt_no_optee, fdt));
 
 	expect_success = false;
-	ret = cmd_ut_category("optee", tests, n_ents, argc, argv);
+	ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
 
 	/* (2) Try to copy optee nodes from prefilled dt */
 	ut_assertok(optee_copy_fdt_nodes(fdt_optee, fdt));
 
 	expect_success = true;
-	ret = cmd_ut_category("optee", tests, n_ents, argc, argv);
+	ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
 
 	/* (3) Try to copy OP-TEE nodes into a already filled DT */
 	ut_assertok(fdt_open_into(fdt_optee, fdt, FDT_COPY_SIZE));
 	ut_assertok(optee_copy_fdt_nodes(fdt_optee, fdt));
 
 	expect_success = true;
-	ret = cmd_ut_category("optee", tests, n_ents, argc, argv);
+	ret = cmd_ut_category("optee", "", tests, n_ents, argc, argv);
 
 	free(fdt);
 	return ret;

+ 1 - 1
test/overlay/cmd_ut_overlay.c

@@ -272,7 +272,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	/* Apply the stacked overlay */
 	ut_assertok(fdt_overlay_apply(fdt, fdt_overlay_stacked_copy));
 
-	ret = cmd_ut_category("overlay", tests, n_ents, argc, argv);
+	ret = cmd_ut_category("overlay", "", tests, n_ents, argc, argv);
 
 	free(fdt_overlay_stacked_copy);
 err3:

+ 2 - 1
test/unicode_ut.c

@@ -585,5 +585,6 @@ int do_ut_unicode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	struct unit_test *tests = ll_entry_start(struct unit_test, unicode_test);
 	const int n_ents = ll_entry_count(struct unit_test, unicode_test);
 
-	return cmd_ut_category("Unicode", tests, n_ents, argc, argv);
+	return cmd_ut_category("Unicode", "unicode_test_",
+			       tests, n_ents, argc, argv);
 }