[PATCH] test: self: mmu: skip false positive test fail when no RAM at address 0

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Nov 9 07:29:46 PST 2023


Testing zero_page_access only makes sense if we actually have RAM at
address 0 that we may read from. If it happens to I/O memory, the SoC
may hang or a data abort may be raised, which would make the test fail.

Avoid this by explicitly checking for that case and skipping the test
without running.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 test/self/mmu.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/test/self/mmu.c b/test/self/mmu.c
index ca58d718ffb3..58961daaab95 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -9,6 +9,7 @@
 #include <abort.h>
 #include <zero_page.h>
 #include <linux/sizes.h>
+#include <memory.h>
 
 #define TEST_BUFFER_SIZE		SZ_1M
 #define TEST_BUFFER_ALIGN		SZ_4K
@@ -171,6 +172,34 @@ static void test_remap(void)
 	free(mirror);
 }
 
+static bool zero_page_access_ok(void)
+{
+	struct memory_bank *bank;
+	const char *reason;
+	struct resource null_res = {
+		.name = "null",
+		.flags = IORESOURCE_MEM,
+		.start = 0,
+		.end = sizeof(int) - 1,
+	};
+
+	if (!IS_ENABLED(CONFIG_ARCH_HAS_ZERO_PAGE)) {
+		reason = "CONFIG_ARCH_HAS_ZERO_PAGE=n";
+		goto not_ok;
+	}
+
+	for_each_memory_bank(bank) {
+		if (resource_contains(bank->res, &null_res))
+			return true;
+	}
+
+	reason = "no memory at address zero";
+
+not_ok:
+	pr_info("skipping rest of zero page tests because %s\n", reason);
+	return false;
+}
+
 static void test_zero_page(void)
 {
 	void __iomem *null = NULL;
@@ -197,9 +226,7 @@ static void test_zero_page(void)
 		failed_tests++;
 	}
 
-	if (!IS_ENABLED(CONFIG_ARCH_HAS_ZERO_PAGE)) {
-		pr_info("skipping %s because %s=n\n",
-			"CONFIG_ARCH_HAS_ZERO_PAGE", __func__);
+	if (!zero_page_access_ok()) {
 		skipped_tests += 2;
 		return;
 	}
-- 
2.39.2




More information about the barebox mailing list