Skip to content

Commit dcb23e1

Browse files
vincent-mailholYuryNorov
authored andcommitted
test_bits: add tests for __GENMASK() and __GENMASK_ULL()
The definitions of GENMASK() and GENMASK_ULL() do not depend any more on __GENMASK() and __GENMASK_ULL(). Duplicate the existing unit tests so that __GENMASK{,ULL}() are still covered. Because __GENMASK() and __GENMASK_ULL() do use GENMASK_INPUT_CHECK(), drop the TEST_GENMASK_FAILURES negative tests. It would be good to have a small assembly test case for GENMASK*() in case somebody decides to unify both in the future. However, I lack expertise in assembly to do so. Instead add a FIXME message to highlight the absence of the asm unit test. Signed-off-by: Vincent Mailhol <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Signed-off-by: Yury Norov (NVIDIA) <[email protected]>
1 parent 104ea1c commit dcb23e1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/tests/test_bits.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ static_assert(assert_type(u16, GENMASK_U16(15, 0)) == U16_MAX);
2626
static_assert(assert_type(u32, GENMASK_U32(31, 0)) == U32_MAX);
2727
static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX);
2828

29+
/* FIXME: add a test case written in asm for GENMASK() and GENMASK_ULL() */
30+
31+
static void __genmask_test(struct kunit *test)
32+
{
33+
KUNIT_EXPECT_EQ(test, 1ul, __GENMASK(0, 0));
34+
KUNIT_EXPECT_EQ(test, 3ul, __GENMASK(1, 0));
35+
KUNIT_EXPECT_EQ(test, 6ul, __GENMASK(2, 1));
36+
KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, __GENMASK(31, 0));
37+
}
38+
39+
static void __genmask_ull_test(struct kunit *test)
40+
{
41+
KUNIT_EXPECT_EQ(test, 1ull, __GENMASK_ULL(0, 0));
42+
KUNIT_EXPECT_EQ(test, 3ull, __GENMASK_ULL(1, 0));
43+
KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, __GENMASK_ULL(39, 21));
44+
KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, __GENMASK_ULL(63, 0));
45+
}
2946

3047
static void genmask_test(struct kunit *test)
3148
{
@@ -123,6 +140,8 @@ static void genmask_input_check_test(struct kunit *test)
123140

124141

125142
static struct kunit_case bits_test_cases[] = {
143+
KUNIT_CASE(__genmask_test),
144+
KUNIT_CASE(__genmask_ull_test),
126145
KUNIT_CASE(genmask_test),
127146
KUNIT_CASE(genmask_ull_test),
128147
KUNIT_CASE(genmask_u128_test),

0 commit comments

Comments
 (0)