tools/testing/vma: add unit tests for vma_flags_[empty, diff_pair, and]()
Subsystems (11)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Lorenzo Stoakes (Oracle)
maintainerPATCH 2/20 tools/testing/vma: add unit tests for vma_flags_[empty, diff_pair, and]()
Add VMA unit tests to assert that:
* vma_flags_empty()
* vma_flags_diff_pair()
* vma_flags_and_mask()
* vma_flags_and()
All function as expected.
In additional to the added tests, in order to make testing easier, add vma_flags_same_mask() and vma_flags_same() for testing only. If/when these are required in kernel code, they can be moved over.
Also add ASSERT_FLAGS_[NOT_]SAME[_MASK](), ASSERT_FLAGS_[NON]EMPTY() test helpers to make asserting flag state easier and more convenient.
--- tools/testing/vma/include/custom.h | 12 +++ tools/testing/vma/shared.h | 18 ++++ tools/testing/vma/tests/vma.c | 137 +++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+)
tools/testing/vma/include/custom.h +12 -0
@@ -118,3 +118,15 @@ static __always_inline vma_flags_t __mk_vma_flags(size_t count,vma_flags_set_flag (&flags, bits[i]);return flags; } + +/* Place here until needed in the kernel code. */ +static __always_inline bool vma_flags_same_mask(vma_flags_t *flags, +vma_flags_t flags_other) +{ +const unsigned long *bitmap = flags->__vma_flags; +const unsigned long *bitmap_other = flags_other.__vma_flags; + +return bitmap_equal (bitmap, bitmap_other,NUM_VMA_FLAG_BITS ); +} +#define vma_flags_same (flags, ...) \ + vma_flags_same_mask(flags, mk_vma_flags(__VA_ARGS__))
tools/testing/vma/shared.h +18 -0
@@ -35,6 +35,24 @@#define ASSERT_EQ (_val1, _val2) ASSERT_TRUE((_val1) == (_val2))#define ASSERT_NE (_val1, _val2) ASSERT_TRUE((_val1) != (_val2)) +#define ASSERT_FLAGS_SAME_MASK (_flags, _flags_other) \ + ASSERT_TRUE(vma_flags_same_mask((_flags), (_flags_other))) + +#define ASSERT_FLAGS_NOT_SAME_MASK (_flags, _flags_other) \ + ASSERT_FALSE(vma_flags_same_mask((_flags), (_flags_other))) + +#define ASSERT_FLAGS_SAME (_flags, ...) \ + ASSERT_TRUE(vma_flags_same(_flags, __VA_ARGS__)) + +#define ASSERT_FLAGS_NOT_SAME (_flags, ...) \ + ASSERT_FALSE(vma_flags_same(_flags, __VA_ARGS__)) + +#define ASSERT_FLAGS_EMPTY (_flags) \ + ASSERT_TRUE(vma_flags_empty(_flags)) + +#define ASSERT_FLAGS_NONEMPTY (_flags) \ + ASSERT_FALSE(vma_flags_empty(_flags)) +#define IS_SET (_val, _flags) ((_val & _flags) == _flags)extern bool fail_prealloc;
tools/testing/vma/tests/vma.c +137 -0
147 lines not on this page · raw message
Signature · 1 line
2.53.0
Lorenzo Stoakes (Oracle)
maintainer(Please ignore this patch, it was sent by mistake, the correct 2/20 is [0])