mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
tools/testing/vma: test vma_flags_count,vma[_flags]_test_single_mask
Update the VMA tests to assert that vma_flags_count() behaves as expected, as well as vma_flags_test_single_mask() and vma_test_single_mask(). For the test functions we can simply update the existing vma_test(), et al. test to also test the single_mask variants. We also add some explicit testing of an empty VMA flag to this test to ensure this is handled properly. In order to test vma_flags_count() we simply take an existing set of flags and gradually remove flags ensuring the count remains as expected throughout. We also update the vma[_flags]_test_all() tests to make clear the semantics that we expect vma[_flags]_test_all(..., EMPTY_VMA_FLAGS) to return true, as trivially, all flags of none are always set in VMA flags. Link: https://lkml.kernel.org/r/4af95d559cd2af0ba3388de1e1386b9f94c0e009.1774034900.git.ljs@kernel.org Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com> Cc: "Borislav Petkov (AMD)" <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Christian Borntraeger <borntraeger@linux.ibm.com> Cc: Christian Brauner <brauner@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jan Kara <jack@suse.cz> Cc: Jann Horn <jannh@google.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Kees Cook <kees@kernel.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Ondrej Mosnacek <omosnace@redhat.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Pedro Falcato <pfalcato@suse.de> Cc: Richard Weinberger <richard@nod.at> Cc: Russell King <linux@armlinux.org.uk> Cc: Stephen Smalley <stephen.smalley.work@gmail.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Vlastimil Babka (SUSE) <vbabka@kernel.org> Cc: WANG Xuerui <kernel@xen0n.name> Cc: Will Deacon <will@kernel.org> Cc: xu xin <xu.xin16@zte.com.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
e79d1c500f
commit
bbbc17cb02
@@ -174,10 +174,10 @@ static bool test_vma_flags_word(void)
|
||||
/* 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
|
||||
vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
struct vm_area_desc desc = {
|
||||
@@ -187,14 +187,18 @@ static bool test_vma_flags_test(void)
|
||||
.flags = flags,
|
||||
};
|
||||
|
||||
#define do_test(_flag) \
|
||||
ASSERT_TRUE(vma_flags_test(&flags, _flag)); \
|
||||
ASSERT_TRUE(vma_test(&vma, _flag)); \
|
||||
#define do_test(_flag) \
|
||||
ASSERT_TRUE(vma_flags_test(&flags, _flag)); \
|
||||
ASSERT_TRUE(vma_flags_test_single_mask(&flags, mk_vma_flags(_flag))); \
|
||||
ASSERT_TRUE(vma_test(&vma, _flag)); \
|
||||
ASSERT_TRUE(vma_test_single_mask(&vma, mk_vma_flags(_flag))); \
|
||||
ASSERT_TRUE(vma_desc_test(&desc, _flag))
|
||||
|
||||
#define do_test_false(_flag) \
|
||||
ASSERT_FALSE(vma_flags_test(&flags, _flag)); \
|
||||
ASSERT_FALSE(vma_test(&vma, _flag)); \
|
||||
#define do_test_false(_flag) \
|
||||
ASSERT_FALSE(vma_flags_test(&flags, _flag)); \
|
||||
ASSERT_FALSE(vma_flags_test_single_mask(&flags, mk_vma_flags(_flag))); \
|
||||
ASSERT_FALSE(vma_test(&vma, _flag)); \
|
||||
ASSERT_FALSE(vma_test_single_mask(&vma, mk_vma_flags(_flag))); \
|
||||
ASSERT_FALSE(vma_desc_test(&desc, _flag))
|
||||
|
||||
do_test(VMA_READ_BIT);
|
||||
@@ -212,6 +216,15 @@ static bool test_vma_flags_test(void)
|
||||
#undef do_test
|
||||
#undef do_test_false
|
||||
|
||||
/* We define the _single_mask() variants to return false if empty. */
|
||||
ASSERT_FALSE(vma_flags_test_single_mask(&flags, EMPTY_VMA_FLAGS));
|
||||
ASSERT_FALSE(vma_test_single_mask(&vma, EMPTY_VMA_FLAGS));
|
||||
/* Even when both flags and tested flag mask are empty! */
|
||||
flags = EMPTY_VMA_FLAGS;
|
||||
vma.flags = EMPTY_VMA_FLAGS;
|
||||
ASSERT_FALSE(vma_flags_test_single_mask(&flags, EMPTY_VMA_FLAGS));
|
||||
ASSERT_FALSE(vma_test_single_mask(&vma, EMPTY_VMA_FLAGS));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -309,6 +322,10 @@ static bool test_vma_flags_test_any(void)
|
||||
do_test(VMA_READ_BIT, VMA_WRITE_BIT, VMA_EXEC_BIT, 64, 65);
|
||||
#endif
|
||||
|
||||
/* Testing all flags against none trivially succeeds. */
|
||||
ASSERT_TRUE(vma_flags_test_all_mask(&flags, EMPTY_VMA_FLAGS));
|
||||
ASSERT_TRUE(vma_test_all_mask(&vma, EMPTY_VMA_FLAGS));
|
||||
|
||||
#undef do_test
|
||||
#undef do_test_all_true
|
||||
#undef do_test_all_false
|
||||
@@ -592,6 +609,33 @@ static bool test_append_vma_flags(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Assert that vma_flags_count() behaves as expected. */
|
||||
static bool test_vma_flags_count(void)
|
||||
{
|
||||
vma_flags_t flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
|
||||
VMA_EXEC_BIT
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
, 64, 65
|
||||
#endif
|
||||
);
|
||||
|
||||
#if NUM_VMA_FLAG_BITS > 64
|
||||
ASSERT_EQ(vma_flags_count(&flags), 5);
|
||||
vma_flags_clear(&flags, 64);
|
||||
ASSERT_EQ(vma_flags_count(&flags), 4);
|
||||
vma_flags_clear(&flags, 65);
|
||||
#endif
|
||||
ASSERT_EQ(vma_flags_count(&flags), 3);
|
||||
vma_flags_clear(&flags, VMA_EXEC_BIT);
|
||||
ASSERT_EQ(vma_flags_count(&flags), 2);
|
||||
vma_flags_clear(&flags, VMA_WRITE_BIT);
|
||||
ASSERT_EQ(vma_flags_count(&flags), 1);
|
||||
vma_flags_clear(&flags, VMA_READ_BIT);
|
||||
ASSERT_EQ(vma_flags_count(&flags), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void run_vma_tests(int *num_tests, int *num_fail)
|
||||
{
|
||||
TEST(copy_vma);
|
||||
@@ -607,4 +651,5 @@ static void run_vma_tests(int *num_tests, int *num_fail)
|
||||
TEST(vma_flags_diff);
|
||||
TEST(vma_flags_and);
|
||||
TEST(append_vma_flags);
|
||||
TEST(vma_flags_count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user