[PATCH v2 35/44] test: Drop conditional compilation for suites

Simon Glass sjg at chromium.org
Mon Jan 20 22:25:57 CET 2025


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 at chromium.org>
---

Changes in v2:
- Show a message when a suite is not compiled in

 test/cmd_ut.c               | 81 +++++++++++++++++--------------------
 test/py/tests/test_suite.py | 11 ++++-
 2 files changed, 45 insertions(+), 47 deletions(-)

diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 181cdb43152..16490e00ab3 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -120,78 +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
-#if CONFIG_IS_ENABLED(BLOBLIST)
 	SUITE(bloblist),
 	SUITE(bootm),
-#endif
-#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[])
@@ -224,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;
@@ -236,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);
@@ -253,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);
 		}
 	}
@@ -297,6 +284,10 @@ static int do_ut(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		if (!ste) {
 			printf("Suite '%s' not found\n", argv[0]);
 			return CMD_RET_FAILURE;
+		} else if (!has_tests(ste)) {
+			/* perhaps a Kconfig option needs to be set? */
+			printf("Suite '%s' is not enabled\n", argv[0]);
+			return CMD_RET_FAILURE;
 		}
 
 		ret = run_suite(ste, cmdtp, flag, argc, argv);
diff --git a/test/py/tests/test_suite.py b/test/py/tests/test_suite.py
index 20cdf022536..a4d7391ce5f 100644
--- a/test/py/tests/test_suite.py
+++ b/test/py/tests/test_suite.py
@@ -128,7 +128,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'
@@ -141,6 +141,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'):
@@ -154,7 +155,13 @@ def test_suite(u_boot_console):
     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'):
-- 
2.43.0



More information about the U-Boot mailing list