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

Lorenzo Stoakes (Oracle)
2026-03-05T10:50:52Z

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