diff mbox series

selftests/mm: virtual_address_range: Switch to ksft_exit_fail_msg

Message ID 20240314122250.68534-1-dev.jain@arm.com (mailing list archive)
State Accepted
Commit 13e860961fd4505d7247ba69e8516f577c2dee5a
Headers show
Series selftests/mm: virtual_address_range: Switch to ksft_exit_fail_msg | expand

Commit Message

Dev Jain March 14, 2024, 12:22 p.m. UTC
mmap() must not succeed in validate_lower_address_hint(), for if it does, it
is a bug in mmap() itself. Reflect this behaviour with ksft_exit_fail_msg().
While at it, do some formatting changes.

Signed-off-by: Dev Jain <dev.jain@arm.com>
---
 tools/testing/selftests/mm/virtual_address_range.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Muhammad Usama Anjum March 14, 2024, 12:33 p.m. UTC | #1
Thanks for the patch. The patch should have been sent to a separate new thread.

On 3/14/24 5:22 PM, Dev Jain wrote:
> mmap() must not succeed in validate_lower_address_hint(), for if it does, it
> is a bug in mmap() itself. Reflect this behaviour with ksft_exit_fail_msg().
> While at it, do some formatting changes.
> 
> Signed-off-by: Dev Jain <dev.jain@arm.com>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>

> ---
>  tools/testing/selftests/mm/virtual_address_range.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
> index 7bcf8d48256a..426ddfc345fb 100644
> --- a/tools/testing/selftests/mm/virtual_address_range.c
> +++ b/tools/testing/selftests/mm/virtual_address_range.c
> @@ -85,7 +85,7 @@ static int validate_lower_address_hint(void)
>  	char *ptr;
>  
>  	ptr = mmap((void *) (1UL << 45), MAP_CHUNK_SIZE, PROT_READ |
> -			PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +		   PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
>  	if (ptr == MAP_FAILED)
>  		return 0;
> @@ -105,13 +105,11 @@ int main(int argc, char *argv[])
>  
>  	for (i = 0; i < NR_CHUNKS_LOW; i++) {
>  		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
> -					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +			      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
>  		if (ptr[i] == MAP_FAILED) {
> -			if (validate_lower_address_hint()) {
> -				ksft_test_result_skip("Memory constraint not fulfilled\n");
> -				ksft_finished();
> -			}
> +			if (validate_lower_address_hint())
> +				ksft_exit_fail_msg("mmap unexpectedly succeeded with hint\n");
>  			break;
>  		}
>  
> @@ -127,7 +125,7 @@ int main(int argc, char *argv[])
>  	for (i = 0; i < NR_CHUNKS_HIGH; i++) {
>  		hint = hind_addr();
>  		hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
> -					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +			       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>  
>  		if (hptr[i] == MAP_FAILED)
>  			break;
diff mbox series

Patch

diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c
index 7bcf8d48256a..426ddfc345fb 100644
--- a/tools/testing/selftests/mm/virtual_address_range.c
+++ b/tools/testing/selftests/mm/virtual_address_range.c
@@ -85,7 +85,7 @@  static int validate_lower_address_hint(void)
 	char *ptr;
 
 	ptr = mmap((void *) (1UL << 45), MAP_CHUNK_SIZE, PROT_READ |
-			PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+		   PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
 	if (ptr == MAP_FAILED)
 		return 0;
@@ -105,13 +105,11 @@  int main(int argc, char *argv[])
 
 	for (i = 0; i < NR_CHUNKS_LOW; i++) {
 		ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
-					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+			      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
 		if (ptr[i] == MAP_FAILED) {
-			if (validate_lower_address_hint()) {
-				ksft_test_result_skip("Memory constraint not fulfilled\n");
-				ksft_finished();
-			}
+			if (validate_lower_address_hint())
+				ksft_exit_fail_msg("mmap unexpectedly succeeded with hint\n");
 			break;
 		}
 
@@ -127,7 +125,7 @@  int main(int argc, char *argv[])
 	for (i = 0; i < NR_CHUNKS_HIGH; i++) {
 		hint = hind_addr();
 		hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE,
-					MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+			       MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
 		if (hptr[i] == MAP_FAILED)
 			break;