mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] test: self: mmu: skip false positive test fail when no RAM at address 0
@ 2023-11-09 15:29 Ahmad Fatoum
  2023-11-10 13:29 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-11-09 15:29 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] test: self: mmu: skip false positive test fail when no RAM at address 0
  2023-11-09 15:29 [PATCH] test: self: mmu: skip false positive test fail when no RAM at address 0 Ahmad Fatoum
@ 2023-11-10 13:29 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-11-10 13:29 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Nov 09, 2023 at 04:29:46PM +0100, Ahmad Fatoum wrote:
> 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@pengutronix.de>
> ---
>  test/self/mmu.c | 33 ++++++++++++++++++++++++++++++---
>  1 file changed, 30 insertions(+), 3 deletions(-)

Applied, thanks

Sascha

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

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-10 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-09 15:29 [PATCH] test: self: mmu: skip false positive test fail when no RAM at address 0 Ahmad Fatoum
2023-11-10 13:29 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox