aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorVincent Mailhol <mailhol.vincent@wanadoo.fr>2025-03-26 01:00:01 +0900
committerYury Norov <yury.norov@gmail.com>2025-04-29 15:58:38 -0400
commite289b488256107425591d8e6a402de8fcf6d088c (patch)
tree349b9e8807d07f23c7ee16c77b78c24d57d43528
parenttest_bits: add tests for GENMASK_U*() (diff)
downloadwireguard-linux-e289b488256107425591d8e6a402de8fcf6d088c.tar.xz
wireguard-linux-e289b488256107425591d8e6a402de8fcf6d088c.zip
test_bits: add tests for BIT_U*()
Add some additional tests in lib/tests/test_bits.c to cover the expected results of the fixed type BIT_U*() macros. Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Yury Norov <yury.norov@gmail.com>
-rw-r--r--lib/tests/test_bits.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
index f443476f3265..47325b41515f 100644
--- a/lib/tests/test_bits.c
+++ b/lib/tests/test_bits.c
@@ -9,6 +9,16 @@
#define assert_type(t, x) _Generic(x, t: x, default: 0)
+static_assert(assert_type(u8, BIT_U8(0)) == 1u);
+static_assert(assert_type(u16, BIT_U16(0)) == 1u);
+static_assert(assert_type(u32, BIT_U32(0)) == 1u);
+static_assert(assert_type(u64, BIT_U64(0)) == 1ull);
+
+static_assert(assert_type(u8, BIT_U8(7)) == 0x80u);
+static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u);
+static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u);
+static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull);
+
static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX);
static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX);
static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX);