1 // SPDX-License-Identifier: GPL-2.0+ 1 2 /* 3 * Test cases for functions and macros in bits 4 */ 5 6 #include <kunit/test.h> 7 #include <linux/bits.h> 8 9 10 static void genmask_test(struct kunit *test) 11 { 12 KUNIT_EXPECT_EQ(test, 1ul, GENMASK(0, 13 KUNIT_EXPECT_EQ(test, 3ul, GENMASK(1, 14 KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 15 KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GE 16 17 #ifdef TEST_GENMASK_FAILURES 18 /* these should fail compilation */ 19 GENMASK(0, 1); 20 GENMASK(0, 10); 21 GENMASK(9, 10); 22 #endif 23 24 25 } 26 27 static void genmask_ull_test(struct kunit *tes 28 { 29 KUNIT_EXPECT_EQ(test, 1ull, GENMASK_UL 30 KUNIT_EXPECT_EQ(test, 3ull, GENMASK_UL 31 KUNIT_EXPECT_EQ(test, 0x000000ffffe000 32 KUNIT_EXPECT_EQ(test, 0xffffffffffffff 33 34 #ifdef TEST_GENMASK_FAILURES 35 /* these should fail compilation */ 36 GENMASK_ULL(0, 1); 37 GENMASK_ULL(0, 10); 38 GENMASK_ULL(9, 10); 39 #endif 40 } 41 42 static void genmask_input_check_test(struct ku 43 { 44 unsigned int x, y; 45 int z, w; 46 47 /* Unknown input */ 48 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 49 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 50 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 51 52 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 53 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 54 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 55 56 /* Valid input */ 57 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 58 KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT 59 } 60 61 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), 66 {} 67 }; 68 69 static struct kunit_suite bits_test_suite = { 70 .name = "bits-test", 71 .test_cases = bits_test_cases, 72 }; 73 kunit_test_suite(bits_test_suite); 74 75 MODULE_DESCRIPTION("Test cases for functions a 76 MODULE_LICENSE("GPL"); 77
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.