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>
This commit is contained in:
Philippe Reynes 2019-12-17 19:07:04 +01:00 committed by Tom Rini
parent 5677fe9d6b
commit 4ad4edfe77
9 changed files with 26 additions and 12 deletions

View File

@ -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[]);

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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:

View File

@ -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);
}