cmd_ut: add a parameter prefix to the function cmd_ut_category
PATCH 1/1 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.
--- include/test/suites.h | 4 +++- test/bloblist.c | 3 ++- test/cmd_ut.c | 12 ++++++++++-- test/compression.c | 3 ++- test/env/cmd_ut_env.c | 3 ++- test/lib/cmd_ut_lib.c | 2 +- test/optee/cmd_ut_optee.c | 6 +++--- test/overlay/cmd_ut_overlay.c | 2 +- test/unicode_ut.c | 3 ++- 9 files changed, 26 insertions(+), 12 deletions(-)
include/test/suites.h +3 -1
@@ -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[]);
test/bloblist.c +2 -1
@@ -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); }
test/cmd_ut.c +10 -2
@@ -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);
test/compression.c +2 -1
@@ -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); }
test/env/cmd_ut_env.c +2 -1
@@ -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); }
test/lib/cmd_ut_lib.c +1 -1
@@ -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); }
test/optee/cmd_ut_optee.c +3 -3
@@ -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;
test/overlay/cmd_ut_overlay.c +1 -1
@@ -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:
test/unicode_ut.c +2 -1
@@ -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); }
Signature · 1 line
2.7.4
PATCH 1/1 cmd_ut: add a parameter prefix to the function cmd_ut_category
Quoted 11 lines · Philippe Reynes
There is black magic in the file
conftest.pythat 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 isbloblist_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.
Quoted 6 lines
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<[email protected]>---
I added a bug into the test/unicode_ut.c by inverting the logical condition of an assert.
The 'ut all' command inside the sandbox reports the error with and without this patch.
The problem was not reported without your patch when running 'make tests'. With the patch it is reported by 'make tests'.
Cc-ing Tom as maintainer of REST
PATCH 1/1 cmd_ut: add a parameter prefix to the function cmd_ut_category
In reply to Philippe ReynesQuoted 11 lines · Philippe Reynes
There is black magic in the file
conftest.pythat 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 isbloblist_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.
Quoted 6 lines
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 <[email protected]>Tested-by Heinrich Schuchardt <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200108/c4688f15/attachment.sig>