mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes
@ 2023-10-09 11:52 Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 2/4] test: self: mmu: reduce MMU test region size Ahmad Fatoum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-10-09 11:52 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

The code hardcodes the SZ_8M and SZ_2M constants for size and alignment
at a number of places. In preparation for making them smaller, factor
them out as TEST_BUFFER_SIZE and TEST_BUFFER_ALIGN.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/mmu.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/test/self/mmu.c b/test/self/mmu.c
index 4ca10affddd2..850c9f336f89 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -10,6 +10,9 @@
 #include <zero_page.h>
 #include <linux/sizes.h>
 
+#define TEST_BUFFER_SIZE		SZ_8M
+#define TEST_BUFFER_ALIGN		SZ_2M
+
 BSELFTEST_GLOBALS();
 
 #define __expect(ret, cond, fmt, ...) do { \
@@ -64,33 +67,33 @@ static void test_remap(void)
 	phys_addr_t buffer_phys;
 	int i, ret;
 
-	buffer = memalign(SZ_2M, SZ_8M);
+	buffer = memalign(TEST_BUFFER_ALIGN, TEST_BUFFER_SIZE);
 	if (WARN_ON(!buffer))
 		goto out;
 
 	buffer_phys = virt_to_phys(buffer);
 
-	mirror = memalign(SZ_2M, SZ_8M);
+	mirror = memalign(TEST_BUFFER_ALIGN, TEST_BUFFER_SIZE);
 	if (WARN_ON(!mirror))
 		goto out;
 
 	pr_debug("allocated buffer = 0x%p, mirror = 0x%p\n", buffer, mirror);
 
-	memtest(buffer, SZ_8M, "cached buffer");
-	memtest(mirror, SZ_8M, "cached mirror");
+	memtest(buffer, TEST_BUFFER_SIZE, "cached buffer");
+	memtest(mirror, TEST_BUFFER_SIZE, "cached mirror");
 
 	if (!arch_can_remap()) {
 		skipped_tests += 18;
 		goto out;
 	}
 
-	ret = remap_range(buffer, SZ_8M, MAP_UNCACHED);
-	memtest(buffer, SZ_8M, "uncached buffer");
+	ret = remap_range(buffer, TEST_BUFFER_SIZE, MAP_UNCACHED);
+	memtest(buffer, TEST_BUFFER_SIZE, "uncached buffer");
 
-	ret = remap_range(mirror, SZ_8M, MAP_UNCACHED);
-	memtest(mirror, SZ_8M, "uncached mirror");
+	ret = remap_range(mirror, TEST_BUFFER_SIZE, MAP_UNCACHED);
+	memtest(mirror, TEST_BUFFER_SIZE, "uncached mirror");
 
-	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
+	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
 		int m = i, b = i;
 		writel(0xDEADBEEF, &mirror[m]);
 		writel(i, &buffer[b]);
@@ -101,10 +104,10 @@ static void test_remap(void)
 
 	expect_success(ret, "asserting no mirror before remap");
 
-	ret = arch_remap_range(mirror, buffer_phys, SZ_8M, MAP_UNCACHED);
+	ret = arch_remap_range(mirror, buffer_phys, TEST_BUFFER_SIZE, MAP_UNCACHED);
 	expect_success(ret, "remapping with mirroring");
 
-	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
+	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
 		int m = i, b = i;
 		writel(0xDEADBEEF, &mirror[m]);
 		writel(i, &buffer[b]);
@@ -115,10 +118,11 @@ static void test_remap(void)
 
 	expect_success(ret, "asserting mirroring after remap");
 
-	ret = arch_remap_range(mirror, buffer_phys + SZ_4K, SZ_4M, MAP_UNCACHED);
+	ret = arch_remap_range(mirror, buffer_phys + SZ_4K,
+			       TEST_BUFFER_SIZE / 2, MAP_UNCACHED);
 	expect_success(ret, "remapping with mirroring (phys += 4K)");
 
-	for (i = 0; i < SZ_4M; i += sizeof(u32)) {
+	for (i = 0; i < TEST_BUFFER_SIZE / 2; i += sizeof(u32)) {
 		int m = i, b = i + SZ_4K;
 		writel(0xDEADBEEF, &mirror[m]);
 		writel(i, &buffer[b]);
@@ -129,10 +133,11 @@ static void test_remap(void)
 
 	expect_success(ret, "asserting mirroring after remap (phys += 4K)");
 
-	ret = arch_remap_range(mirror + SZ_4K, buffer_phys, SZ_4M, MAP_UNCACHED);
+	ret = arch_remap_range(mirror + SZ_4K, buffer_phys,
+			       TEST_BUFFER_SIZE / 2, MAP_UNCACHED);
 	expect_success(ret, "remapping with mirroring (virt += 4K)");
 
-	for (i = 0; i < SZ_4M; i += sizeof(u32)) {
+	for (i = 0; i < TEST_BUFFER_SIZE / 2; i += sizeof(u32)) {
 		int m = i + SZ_4K, b = i;
 		writel(0xDEADBEEF, &mirror[m]);
 		writel(i, &buffer[b]);
@@ -143,15 +148,15 @@ static void test_remap(void)
 
 	expect_success(ret, "asserting mirroring after remap (virt += 4K)");
 
-	ret = remap_range(buffer, SZ_8M, MAP_DEFAULT);
+	ret = remap_range(buffer, TEST_BUFFER_SIZE, MAP_DEFAULT);
 	expect_success(ret, "remapping buffer with default attrs");
-	memtest(buffer, SZ_8M, "newly cached buffer");
+	memtest(buffer, TEST_BUFFER_SIZE, "newly cached buffer");
 
-	ret = remap_range(mirror, SZ_8M, MAP_DEFAULT);
+	ret = remap_range(mirror, TEST_BUFFER_SIZE, MAP_DEFAULT);
 	expect_success(ret, "remapping mirror with default attrs");
-	memtest(mirror, SZ_8M, "newly cached mirror");
+	memtest(mirror, TEST_BUFFER_SIZE, "newly cached mirror");
 
-	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
+	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
 		int m = i, b = i;
 		writel(0xDEADBEEF, &mirror[m]);
 		writel(i, &buffer[b]);
-- 
2.39.2




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

* [PATCH 2/4] test: self: mmu: reduce MMU test region size
  2023-10-09 11:52 [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Ahmad Fatoum
@ 2023-10-09 11:52 ` Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 3/4] test: self: have SELFTEST_ENABLE_ALL select all tests Ahmad Fatoum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-10-09 11:52 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This reduces runtime of the tests and additionally may help to catch
future alignment issues by decreasing the alignment to the minimum
required.

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

diff --git a/test/self/mmu.c b/test/self/mmu.c
index 850c9f336f89..ca58d718ffb3 100644
--- a/test/self/mmu.c
+++ b/test/self/mmu.c
@@ -10,8 +10,8 @@
 #include <zero_page.h>
 #include <linux/sizes.h>
 
-#define TEST_BUFFER_SIZE		SZ_8M
-#define TEST_BUFFER_ALIGN		SZ_2M
+#define TEST_BUFFER_SIZE		SZ_1M
+#define TEST_BUFFER_ALIGN		SZ_4K
 
 BSELFTEST_GLOBALS();
 
-- 
2.39.2




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

* [PATCH 3/4] test: self: have SELFTEST_ENABLE_ALL select all tests
  2023-10-09 11:52 [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 2/4] test: self: mmu: reduce MMU test region size Ahmad Fatoum
@ 2023-10-09 11:52 ` Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 4/4] test: self: warn and exit if device tree parsing fails Ahmad Fatoum
  2023-10-13  9:19 ` [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-10-09 11:52 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

CONFIG_SELFTEST_ENABLE_ALL is meant as a toggle to just enable all
tests that are applicable. imply doesn't do what's expected, because
it won't enable an option that's explicitly disabled. Thus switch
over to using select instead and while at it add the missing
select for SELFTEST_TEST_COMMAND.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/Kconfig | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/test/self/Kconfig b/test/self/Kconfig
index 15e00f0244b5..e7da07491a91 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -33,16 +33,15 @@ config SELFTEST_ENABLE_ALL
 	select SELFTEST_PROGRESS_NOTIFIER
 	select SELFTEST_OF_MANIPULATION
 	select SELFTEST_ENVIRONMENT_VARIABLES if ENVIRONMENT_VARIABLES
-	imply SELFTEST_FS_RAMFS
-	imply SELFTEST_TFTP
-	imply SELFTEST_JSON
-	imply SELFTEST_DIGEST
-	imply SELFTEST_MMU
-	imply SELFTEST_STRING
-	imply SELFTEST_SETJMP
-	imply SELFTEST_REGULATOR
-	help
-	  Selects all self-tests compatible with current configuration
+	select SELFTEST_FS_RAMFS if FS_RAMFS
+	select SELFTEST_TFTP if FS_TFTP
+	select SELFTEST_JSON if JSMN
+	select SELFTEST_DIGEST if DIGEST
+	select SELFTEST_MMU if MMU
+	select SELFTEST_STRING
+	select SELFTEST_SETJMP if ARCH_HAS_SJLJ
+	select SELFTEST_REGULATOR if REGULATOR && OFDEVICE
+	select SELFTEST_TEST_COMMAND if CMD_TEST
 
 config SELFTEST_MALLOC
 	bool "malloc() selftest"
-- 
2.39.2




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

* [PATCH 4/4] test: self: warn and exit if device tree parsing fails
  2023-10-09 11:52 [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 2/4] test: self: mmu: reduce MMU test region size Ahmad Fatoum
  2023-10-09 11:52 ` [PATCH 3/4] test: self: have SELFTEST_ENABLE_ALL select all tests Ahmad Fatoum
@ 2023-10-09 11:52 ` Ahmad Fatoum
  2023-10-13  9:19 ` [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2023-10-09 11:52 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

selftest DTs are compiled into barebox, so it's not expected that they
fail to parse. Nevertheless, error conditions shouldn't be ignored,
so warn about it and early exit.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 test/self/of_manipulation.c | 2 ++
 test/self/regulator.c       | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index 64913ac1eab8..8d645b113732 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -121,6 +121,8 @@ static void __init test_of_manipulation(void)
 
 	expected = of_unflatten_dtb(__dtb_of_manipulation_start,
 				    __dtb_of_manipulation_end - __dtb_of_manipulation_start);
+	if (WARN_ON(IS_ERR(expected)))
+		return;
 
 	assert_equal(root, expected);
 
diff --git a/test/self/regulator.c b/test/self/regulator.c
index 08073cfc9158..bcbcbe33e12f 100644
--- a/test/self/regulator.c
+++ b/test/self/regulator.c
@@ -175,6 +175,8 @@ static void test_regulator(void)
 			return;
 
 		overlay = of_unflatten_dtb(__dtbo_test_regulator_start, INT_MAX);
+		if (WARN_ON(IS_ERR(overlay)))
+			return;
 		of_overlay_apply_tree(of_get_root_node(), overlay);
 		of_probe();
 
-- 
2.39.2




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

* Re: [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes
  2023-10-09 11:52 [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Ahmad Fatoum
                   ` (2 preceding siblings ...)
  2023-10-09 11:52 ` [PATCH 4/4] test: self: warn and exit if device tree parsing fails Ahmad Fatoum
@ 2023-10-13  9:19 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2023-10-13  9:19 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Oct 09, 2023 at 01:52:54PM +0200, Ahmad Fatoum wrote:
> The code hardcodes the SZ_8M and SZ_2M constants for size and alignment
> at a number of places. In preparation for making them smaller, factor
> them out as TEST_BUFFER_SIZE and TEST_BUFFER_ALIGN.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  test/self/mmu.c | 45 +++++++++++++++++++++++++--------------------
>  1 file changed, 25 insertions(+), 20 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/test/self/mmu.c b/test/self/mmu.c
> index 4ca10affddd2..850c9f336f89 100644
> --- a/test/self/mmu.c
> +++ b/test/self/mmu.c
> @@ -10,6 +10,9 @@
>  #include <zero_page.h>
>  #include <linux/sizes.h>
>  
> +#define TEST_BUFFER_SIZE		SZ_8M
> +#define TEST_BUFFER_ALIGN		SZ_2M
> +
>  BSELFTEST_GLOBALS();
>  
>  #define __expect(ret, cond, fmt, ...) do { \
> @@ -64,33 +67,33 @@ static void test_remap(void)
>  	phys_addr_t buffer_phys;
>  	int i, ret;
>  
> -	buffer = memalign(SZ_2M, SZ_8M);
> +	buffer = memalign(TEST_BUFFER_ALIGN, TEST_BUFFER_SIZE);
>  	if (WARN_ON(!buffer))
>  		goto out;
>  
>  	buffer_phys = virt_to_phys(buffer);
>  
> -	mirror = memalign(SZ_2M, SZ_8M);
> +	mirror = memalign(TEST_BUFFER_ALIGN, TEST_BUFFER_SIZE);
>  	if (WARN_ON(!mirror))
>  		goto out;
>  
>  	pr_debug("allocated buffer = 0x%p, mirror = 0x%p\n", buffer, mirror);
>  
> -	memtest(buffer, SZ_8M, "cached buffer");
> -	memtest(mirror, SZ_8M, "cached mirror");
> +	memtest(buffer, TEST_BUFFER_SIZE, "cached buffer");
> +	memtest(mirror, TEST_BUFFER_SIZE, "cached mirror");
>  
>  	if (!arch_can_remap()) {
>  		skipped_tests += 18;
>  		goto out;
>  	}
>  
> -	ret = remap_range(buffer, SZ_8M, MAP_UNCACHED);
> -	memtest(buffer, SZ_8M, "uncached buffer");
> +	ret = remap_range(buffer, TEST_BUFFER_SIZE, MAP_UNCACHED);
> +	memtest(buffer, TEST_BUFFER_SIZE, "uncached buffer");
>  
> -	ret = remap_range(mirror, SZ_8M, MAP_UNCACHED);
> -	memtest(mirror, SZ_8M, "uncached mirror");
> +	ret = remap_range(mirror, TEST_BUFFER_SIZE, MAP_UNCACHED);
> +	memtest(mirror, TEST_BUFFER_SIZE, "uncached mirror");
>  
> -	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
> +	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
>  		int m = i, b = i;
>  		writel(0xDEADBEEF, &mirror[m]);
>  		writel(i, &buffer[b]);
> @@ -101,10 +104,10 @@ static void test_remap(void)
>  
>  	expect_success(ret, "asserting no mirror before remap");
>  
> -	ret = arch_remap_range(mirror, buffer_phys, SZ_8M, MAP_UNCACHED);
> +	ret = arch_remap_range(mirror, buffer_phys, TEST_BUFFER_SIZE, MAP_UNCACHED);
>  	expect_success(ret, "remapping with mirroring");
>  
> -	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
> +	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
>  		int m = i, b = i;
>  		writel(0xDEADBEEF, &mirror[m]);
>  		writel(i, &buffer[b]);
> @@ -115,10 +118,11 @@ static void test_remap(void)
>  
>  	expect_success(ret, "asserting mirroring after remap");
>  
> -	ret = arch_remap_range(mirror, buffer_phys + SZ_4K, SZ_4M, MAP_UNCACHED);
> +	ret = arch_remap_range(mirror, buffer_phys + SZ_4K,
> +			       TEST_BUFFER_SIZE / 2, MAP_UNCACHED);
>  	expect_success(ret, "remapping with mirroring (phys += 4K)");
>  
> -	for (i = 0; i < SZ_4M; i += sizeof(u32)) {
> +	for (i = 0; i < TEST_BUFFER_SIZE / 2; i += sizeof(u32)) {
>  		int m = i, b = i + SZ_4K;
>  		writel(0xDEADBEEF, &mirror[m]);
>  		writel(i, &buffer[b]);
> @@ -129,10 +133,11 @@ static void test_remap(void)
>  
>  	expect_success(ret, "asserting mirroring after remap (phys += 4K)");
>  
> -	ret = arch_remap_range(mirror + SZ_4K, buffer_phys, SZ_4M, MAP_UNCACHED);
> +	ret = arch_remap_range(mirror + SZ_4K, buffer_phys,
> +			       TEST_BUFFER_SIZE / 2, MAP_UNCACHED);
>  	expect_success(ret, "remapping with mirroring (virt += 4K)");
>  
> -	for (i = 0; i < SZ_4M; i += sizeof(u32)) {
> +	for (i = 0; i < TEST_BUFFER_SIZE / 2; i += sizeof(u32)) {
>  		int m = i + SZ_4K, b = i;
>  		writel(0xDEADBEEF, &mirror[m]);
>  		writel(i, &buffer[b]);
> @@ -143,15 +148,15 @@ static void test_remap(void)
>  
>  	expect_success(ret, "asserting mirroring after remap (virt += 4K)");
>  
> -	ret = remap_range(buffer, SZ_8M, MAP_DEFAULT);
> +	ret = remap_range(buffer, TEST_BUFFER_SIZE, MAP_DEFAULT);
>  	expect_success(ret, "remapping buffer with default attrs");
> -	memtest(buffer, SZ_8M, "newly cached buffer");
> +	memtest(buffer, TEST_BUFFER_SIZE, "newly cached buffer");
>  
> -	ret = remap_range(mirror, SZ_8M, MAP_DEFAULT);
> +	ret = remap_range(mirror, TEST_BUFFER_SIZE, MAP_DEFAULT);
>  	expect_success(ret, "remapping mirror with default attrs");
> -	memtest(mirror, SZ_8M, "newly cached mirror");
> +	memtest(mirror, TEST_BUFFER_SIZE, "newly cached mirror");
>  
> -	for (i = 0; i < SZ_8M; i += sizeof(u32)) {
> +	for (i = 0; i < TEST_BUFFER_SIZE; i += sizeof(u32)) {
>  		int m = i, b = i;
>  		writel(0xDEADBEEF, &mirror[m]);
>  		writel(i, &buffer[b]);
> -- 
> 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] 5+ messages in thread

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 11:52 [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Ahmad Fatoum
2023-10-09 11:52 ` [PATCH 2/4] test: self: mmu: reduce MMU test region size Ahmad Fatoum
2023-10-09 11:52 ` [PATCH 3/4] test: self: have SELFTEST_ENABLE_ALL select all tests Ahmad Fatoum
2023-10-09 11:52 ` [PATCH 4/4] test: self: warn and exit if device tree parsing fails Ahmad Fatoum
2023-10-13  9:19 ` [PATCH 1/4] test: self: mmu: use constants for the hardcoded buffer sizes Sascha Hauer

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