
This is not needed anymore. If a test suite is not built, then it will have no linker-list entries. So we can just check for that and know that the suite is not present.
This allows removal of the #ifdefs and the need to keep them in sync with the associated Makefile rules, which has actually failed, since the help does not match what commands are actually present.
Signed-off-by: Simon Glass sjg@chromium.org ---
test/cmd_ut.c | 75 ++++++++++++++++--------------------- test/py/tests/test_suite.py | 19 +++++++--- 2 files changed, 46 insertions(+), 48 deletions(-)
diff --git a/test/cmd_ut.c b/test/cmd_ut.c index 798710972e5..2ba99a26c63 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -120,76 +120,55 @@ SUITE_DECL(seama); SUITE_DECL(upl);
static struct suite suites[] = { -#ifdef CONFIG_CMD_BDI SUITE(bdinfo), -#endif #ifdef CONFIG_UT_BOOTSTD SUITE_CMD(bootstd, do_ut_bootstd), #endif -#ifdef CONFIG_CMDLINE SUITE(cmd), -#endif SUITE(common), -#if defined(CONFIG_UT_DM) SUITE(dm), -#endif -#if defined(CONFIG_UT_ENV) SUITE(env), -#endif SUITE(exit), -#ifdef CONFIG_CMD_FDT SUITE(fdt), -#endif -#ifdef CONFIG_CONSOLE_TRUETYPE SUITE(font), -#endif #ifdef CONFIG_UT_OPTEE SUITE_CMD(optee, do_ut_optee), #endif #ifdef CONFIG_UT_OVERLAY SUITE_CMD(overlay, do_ut_overlay), #endif -#ifdef CONFIG_UT_LIB SUITE(lib), -#endif -#ifdef CONFIG_UT_LOG SUITE(log), -#endif -#if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_MBR) && defined(CONFIG_CMD_MMC) \ - && defined(CONFIG_MMC_SANDBOX) && defined(CONFIG_MMC_WRITE) SUITE(mbr), -#endif SUITE(mem), -#if defined(CONFIG_SANDBOX) && defined(CONFIG_CMD_SETEXPR) SUITE(setexpr), -#endif -#ifdef CONFIG_MEASURED_BOOT SUITE(measurement), -#endif -#ifdef CONFIG_SANDBOX SUITE(bloblist), SUITE(bootm), -#endif -#ifdef CONFIG_CMD_ADDRMAP SUITE(addrmap), -#endif -#if CONFIG_IS_ENABLED(HUSH_PARSER) SUITE(hush), -#endif -#ifdef CONFIG_CMD_LOADM SUITE(loadm), -#endif -#ifdef CONFIG_CMD_PCI_MPS SUITE(pci_mps), -#endif -#ifdef CONFIG_CMD_SEAMA SUITE(seama), -#endif -#ifdef CONFIG_CMD_UPL SUITE(upl), -#endif };
+/** + * has_tests() - Check if a suite has tests, i.e. is supported in this build + * + * If the suite is run using a command, we have to assume that tests may be + * present, since we have no visibility + * + * @ste: Suite to check + * Return: true if supported, false if not + */ +static bool has_tests(struct suite *ste) +{ + int n_ents = ste->end - ste->start; + + return n_ents || ste->cmd; +} + /** run_suite() - Run a suite of tests */ static int run_suite(struct suite *ste, struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -222,10 +201,12 @@ static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc, struct suite *ste = &suites[i]; char *const argv[] = {(char *)ste->name, NULL};
- printf("----Running %s tests----\n", ste->name); - retval = run_suite(ste, cmdtp, flag, 1, argv); - if (!any_fail) - any_fail = retval; + if (has_tests(ste)) { + printf("----Running %s tests----\n", ste->name); + retval = run_suite(ste, cmdtp, flag, 1, argv); + if (!any_fail) + any_fail = retval; + } }
return any_fail; @@ -234,9 +215,17 @@ static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc, static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + int suite_count, i; const char *flags;
- printf("Test suites: %d\n", (int)ARRAY_SIZE(suites)); + for (suite_count = 0, i = 0; i < ARRAY_SIZE(suites); i++) { + struct suite *ste = &suites[i]; + + if (has_tests(ste)) + suite_count++; + } + + printf("Test suites: %d\n", suite_count); printf("Total tests: %d\n", (int)UNIT_TEST_ALL_COUNT());
flags = cmd_arg1(argc, argv); @@ -251,7 +240,7 @@ static int do_ut_info(struct cmd_tbl *cmdtp, int flag, int argc,
if (n_ent) printf("%5ld %s\n", n_ent, ste->name); - else + else if (ste->cmd) printf("%5s %s\n", "?", ste->name); } } diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py index 938dfb468f6..1c248602199 100644 --- a/test/py/tests/test_suite.py +++ b/test/py/tests/test_suite.py @@ -106,7 +106,7 @@ def process_ut_info(cons, output): test_count = {} for line in output.splitlines(): if DEBUG_ME: - cons.log.info(f'line: {line}') + cons.log.info(f'line: {line.rstrip()}') m = re.match(r'Test suites: (.*)', line) if m: suite_count = int(m.group(1)) @@ -122,7 +122,7 @@ def process_ut_info(cons, output): @pytest.mark.buildconfigspec('sandbox') @pytest.mark.notbuildconfigspec('sandbox_spl') @pytest.mark.notbuildconfigspec('sandbox64') -def test_suite(u_boot_console): +def test_suite(u_boot_console, u_boot_config): """Perform various checks on the unit tests, including:
- The number of suites matches that reported by the 'ut info' @@ -135,6 +135,7 @@ def test_suite(u_boot_console):
""" cons = u_boot_console + buildconfig = u_boot_config.buildconfig with cons.log.section('Run all unit tests'): # ut hush hush_test_simple_dollar prints "Unknown command" on purpose. with u_boot_console.disable_check('unknown_command'): @@ -144,9 +145,17 @@ def test_suite(u_boot_console): with cons.log.section('Check output'): suites, all_tests, exp_test_count, missing, extra = collect_info(cons, output) + cons.log.info(f'missing {missing}') + cons.log.info(f'extra {extra}')
# Make sure we got a test count for each suite - assert suites - exp_test_count.keys() == set() + assert not (suites - exp_test_count.keys()) + + # Deal with missing suites + with cons.log.section('Check missing suites'): + if 'config_cmd_seama' not in buildconfig: + cons.log.info("CMD_SEAMA not enabled: Ignoring suite 'seama'") + missing.discard('seama')
# Run 'ut info' and compare with the log results with cons.log.section('Check suite test-counts'): @@ -160,8 +169,8 @@ def test_suite(u_boot_console): cons.log.error(f'missing: {sorted(list(missing))}') cons.log.error(f'extra: {sorted(list(extra))}')
- assert not missing - assert not extra + assert not missing, f'Missing suites {missing}' + assert not extra, f'Extra suites {extra}'
cons.log.info(str(exp_test_count)) for suite in EXPECTED_SUITES: