~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/test_bits.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0+
  2 /*
  3  * Test cases for functions and macros in bits.h
  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, 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));
 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 *test)
 28 {
 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));
 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 kunit *test)
 43 {
 44         unsigned int x, y;
 45         int z, w;
 46 
 47         /* Unknown input */
 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));
 51 
 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));
 55 
 56         /* Valid input */
 57         KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1));
 58         KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21));
 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 and macros in bits.h");
 76 MODULE_LICENSE("GPL");
 77 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php