1 // SPDX-License-Identifier: GPL-2.0+
3 * Test cases for functions and macros in bits.h
6 #include <kunit/test.h>
7 #include <linux/bits.h>
10 static void genmask_test(struct kunit
*test
)
12 KUNIT_EXPECT_EQ(test
, 1ul, GENMASK(0, 0));
13 KUNIT_EXPECT_EQ(test
, 3ul, GENMASK(1, 0));
14 KUNIT_EXPECT_EQ(test
, 6ul, GENMASK(2, 1));
15 KUNIT_EXPECT_EQ(test
, 0xFFFFFFFFul
, GENMASK(31, 0));
17 #ifdef TEST_GENMASK_FAILURES
18 /* these should fail compilation */
27 static void genmask_ull_test(struct kunit
*test
)
29 KUNIT_EXPECT_EQ(test
, 1ull, GENMASK_ULL(0, 0));
30 KUNIT_EXPECT_EQ(test
, 3ull, GENMASK_ULL(1, 0));
31 KUNIT_EXPECT_EQ(test
, 0x000000ffffe00000ull
, GENMASK_ULL(39, 21));
32 KUNIT_EXPECT_EQ(test
, 0xffffffffffffffffull
, GENMASK_ULL(63, 0));
34 #ifdef TEST_GENMASK_FAILURES
35 /* these should fail compilation */
42 static void genmask_input_check_test(struct kunit
*test
)
48 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(x
, 0));
49 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(0, x
));
50 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(x
, y
));
52 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(z
, 0));
53 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(0, z
));
54 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(z
, w
));
57 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(1, 1));
58 KUNIT_EXPECT_EQ(test
, 0, GENMASK_INPUT_CHECK(39, 21));
62 static struct kunit_case bits_test_cases
[] = {
63 KUNIT_CASE(genmask_test
),
64 KUNIT_CASE(genmask_ull_test
),
65 KUNIT_CASE(genmask_input_check_test
),
69 static struct kunit_suite bits_test_suite
= {
71 .test_cases
= bits_test_cases
,
73 kunit_test_suite(bits_test_suite
);
75 MODULE_LICENSE("GPL");