[PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()

Lorenzo Stoakes (Oracle) posted 6 patches 1 month ago
[PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by Lorenzo Stoakes (Oracle) 1 month ago
Now we have helpers which test singular VMA flags - vma_flags_test() and
vma_desc_test() - add a test to explicitly assert that these behave as
expected.

Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
---
 tools/testing/vma/tests/vma.c | 36 +++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
index f031e6dfb474..1aa94dd7e74a 100644
--- a/tools/testing/vma/tests/vma.c
+++ b/tools/testing/vma/tests/vma.c
@@ -159,6 +159,41 @@ static bool test_vma_flags_word(void)
 	return true;
 }
 
+/* Ensure that vma_flags_test() and friends works correctly. */
+static bool test_vma_flags_test(void)
+{
+	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
+					       VMA_EXEC_BIT, 64, 65);
+	struct vm_area_desc desc;
+
+	desc.vma_flags = flags;
+
+#define do_test(_flag)					\
+	ASSERT_TRUE(vma_flags_test(&flags, _flag));	\
+	ASSERT_TRUE(vma_desc_test(&desc, _flag))
+
+#define do_test_false(_flag)				\
+	ASSERT_FALSE(vma_flags_test(&flags, _flag));	\
+	ASSERT_FALSE(vma_desc_test(&desc, _flag))
+
+	do_test(VMA_READ_BIT);
+	do_test(VMA_WRITE_BIT);
+	do_test(VMA_EXEC_BIT);
+#if NUM_VMA_FLAG_BITS > 64
+	do_test(64);
+	do_test(65);
+#endif
+	do_test_false(VMA_MAYWRITE_BIT);
+#if NUM_VMA_FLAG_BITS > 64
+	do_test_false(66);
+#endif
+
+#undef do_test
+#undef do_test_false
+
+	return true;
+}
+
 /* Ensure that vma_flags_test_any() and friends works correctly. */
 static bool test_vma_flags_test_any(void)
 {
@@ -334,6 +369,7 @@ static void run_vma_tests(int *num_tests, int *num_fail)
 	TEST(vma_flags_unchanged);
 	TEST(vma_flags_cleared);
 	TEST(vma_flags_word);
+	TEST(vma_flags_test);
 	TEST(vma_flags_test_any);
 	TEST(vma_flags_clear);
 }
-- 
2.53.0
Re: [PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by Pedro Falcato 2 weeks, 1 day ago
On Thu, Mar 05, 2026 at 10:50:19AM +0000, Lorenzo Stoakes (Oracle) wrote:
> Now we have helpers which test singular VMA flags - vma_flags_test() and
> vma_desc_test() - add a test to explicitly assert that these behave as
> expected.
> 
> Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>

Reviewed-by: Pedro Falcato <pfalcato@suse.de>

-- 
Pedro
Re: [PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by David Hildenbrand (Arm) 1 month ago
On 3/5/26 11:50, Lorenzo Stoakes (Oracle) wrote:
> Now we have helpers which test singular VMA flags - vma_flags_test() and
> vma_desc_test() - add a test to explicitly assert that these behave as
> expected.
> 
> Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> ---
>  tools/testing/vma/tests/vma.c | 36 +++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 
> diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
> index f031e6dfb474..1aa94dd7e74a 100644
> --- a/tools/testing/vma/tests/vma.c
> +++ b/tools/testing/vma/tests/vma.c
> @@ -159,6 +159,41 @@ static bool test_vma_flags_word(void)
>  	return true;
>  }
>  
> +/* Ensure that vma_flags_test() and friends works correctly. */
> +static bool test_vma_flags_test(void)
> +{
> +	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
> +					       VMA_EXEC_BIT, 64, 65);

When already using numbers, I was wondering whether you'd want to stick
to numbers only here.

> +	struct vm_area_desc desc;


struct vm_area_desc desc = {
	.vma_flags = flags,
};

?


-- 
Cheers,

David
Re: [PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by Lorenzo Stoakes (Oracle) 1 month ago
On Thu, Mar 05, 2026 at 02:52:20PM +0100, David Hildenbrand (Arm) wrote:
> On 3/5/26 11:50, Lorenzo Stoakes (Oracle) wrote:
> > Now we have helpers which test singular VMA flags - vma_flags_test() and
> > vma_desc_test() - add a test to explicitly assert that these behave as
> > expected.
> >
> > Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
> > ---
> >  tools/testing/vma/tests/vma.c | 36 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 36 insertions(+)
> >
> > diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
> > index f031e6dfb474..1aa94dd7e74a 100644
> > --- a/tools/testing/vma/tests/vma.c
> > +++ b/tools/testing/vma/tests/vma.c
> > @@ -159,6 +159,41 @@ static bool test_vma_flags_word(void)
> >  	return true;
> >  }
> >
> > +/* Ensure that vma_flags_test() and friends works correctly. */
> > +static bool test_vma_flags_test(void)
> > +{
> > +	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
> > +					       VMA_EXEC_BIT, 64, 65);
>
> When already using numbers, I was wondering whether you'd want to stick
> to numbers only here.

Numbers are for flags > 64 bits, we currently don't define any, it's to make
sure everything works at higher bitmap sizes, the tests currently set the bitmap
size to 128 bits.

>
> > +	struct vm_area_desc desc;
>
>
> struct vm_area_desc desc = {
> 	.vma_flags = flags,
> };
>
> ?

Ack can do, fix-patch for Andrew below :)

Cheers, Lorenzo

----8<----
From 5cc64e6c1884aaf995ce6398e36d5844c246352d Mon Sep 17 00:00:00 2001
From: "Lorenzo Stoakes (Oracle)" <ljs@kernel.org>
Date: Thu, 5 Mar 2026 14:59:58 +0000
Subject: [PATCH] fix

Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
---
 tools/testing/vma/tests/vma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
index 1aa94dd7e74a..f6edd44f4e9e 100644
--- a/tools/testing/vma/tests/vma.c
+++ b/tools/testing/vma/tests/vma.c
@@ -164,9 +164,9 @@ static bool test_vma_flags_test(void)
 {
 	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
 					      VMA_EXEC_BIT, 64, 65);
-	struct vm_area_desc desc;
-
-	desc.vma_flags = flags;
+	struct vm_area_desc desc = {
+		.vma_flags = flags,
+	};

 #define do_test(_flag)					\
 	ASSERT_TRUE(vma_flags_test(&flags, _flag));	\
--
2.53.0
Re: [PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by David Hildenbrand (Arm) 2 weeks, 1 day ago
On 3/5/26 16:01, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 05, 2026 at 02:52:20PM +0100, David Hildenbrand (Arm) wrote:
>> On 3/5/26 11:50, Lorenzo Stoakes (Oracle) wrote:
>>> Now we have helpers which test singular VMA flags - vma_flags_test() and
>>> vma_desc_test() - add a test to explicitly assert that these behave as
>>> expected.
>>>
>>> Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
>>> ---
>>>  tools/testing/vma/tests/vma.c | 36 +++++++++++++++++++++++++++++++++++
>>>  1 file changed, 36 insertions(+)
>>>
>>> diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
>>> index f031e6dfb474..1aa94dd7e74a 100644
>>> --- a/tools/testing/vma/tests/vma.c
>>> +++ b/tools/testing/vma/tests/vma.c
>>> @@ -159,6 +159,41 @@ static bool test_vma_flags_word(void)
>>>  	return true;
>>>  }
>>>
>>> +/* Ensure that vma_flags_test() and friends works correctly. */
>>> +static bool test_vma_flags_test(void)
>>> +{
>>> +	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
>>> +					       VMA_EXEC_BIT, 64, 65);
>>
>> When already using numbers, I was wondering whether you'd want to stick
>> to numbers only here.
> 
> Numbers are for flags > 64 bits, we currently don't define any, it's to make
> sure everything works at higher bitmap sizes, the tests currently set the bitmap
> size to 128 bits.
> 
>>
>>> +	struct vm_area_desc desc;
>>
>>
>> struct vm_area_desc desc = {
>> 	.vma_flags = flags,
>> };
>>
>> ?
> 
> Ack can do, fix-patch for Andrew below :)

Not sure if I provided a tag, but here it comes

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David
Re: [PATCH 6/6] tools/testing/vma: add test for vma_flags_test(), vma_desc_test()
Posted by David Hildenbrand (Arm) 1 month ago
On 3/5/26 16:01, Lorenzo Stoakes (Oracle) wrote:
> On Thu, Mar 05, 2026 at 02:52:20PM +0100, David Hildenbrand (Arm) wrote:
>> On 3/5/26 11:50, Lorenzo Stoakes (Oracle) wrote:
>>> Now we have helpers which test singular VMA flags - vma_flags_test() and
>>> vma_desc_test() - add a test to explicitly assert that these behave as
>>> expected.
>>>
>>> Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
>>> ---
>>>  tools/testing/vma/tests/vma.c | 36 +++++++++++++++++++++++++++++++++++
>>>  1 file changed, 36 insertions(+)
>>>
>>> diff --git a/tools/testing/vma/tests/vma.c b/tools/testing/vma/tests/vma.c
>>> index f031e6dfb474..1aa94dd7e74a 100644
>>> --- a/tools/testing/vma/tests/vma.c
>>> +++ b/tools/testing/vma/tests/vma.c
>>> @@ -159,6 +159,41 @@ static bool test_vma_flags_word(void)
>>>  	return true;
>>>  }
>>>
>>> +/* Ensure that vma_flags_test() and friends works correctly. */
>>> +static bool test_vma_flags_test(void)
>>> +{
>>> +	const vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
>>> +					       VMA_EXEC_BIT, 64, 65);
>>
>> When already using numbers, I was wondering whether you'd want to stick
>> to numbers only here.
> 
> Numbers are for flags > 64 bits, we currently don't define any, it's to make
> sure everything works at higher bitmap sizes, the tests currently set the bitmap
> size to 128 bits.

Right, I was just saying, purely using numbers would also work and make
the numbers 64/65 not stick out as much :)


> 
>>
>>> +	struct vm_area_desc desc;
>>
>>
>> struct vm_area_desc desc = {
>> 	.vma_flags = flags,
>> };
>>
>> ?
> 
> Ack can do, fix-patch for Andrew below :)

In case I missed it:

Acked-by: David Hildenbrand (Arm) <david@kernel.org>

-- 
Cheers,

David