Skip to content

Commit e289b48

Browse files
vincent-mailholYuryNorov
authored andcommitted
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>
1 parent 0405eef commit e289b48

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/tests/test_bits.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99

1010
#define assert_type(t, x) _Generic(x, t: x, default: 0)
1111

12+
static_assert(assert_type(u8, BIT_U8(0)) == 1u);
13+
static_assert(assert_type(u16, BIT_U16(0)) == 1u);
14+
static_assert(assert_type(u32, BIT_U32(0)) == 1u);
15+
static_assert(assert_type(u64, BIT_U64(0)) == 1ull);
16+
17+
static_assert(assert_type(u8, BIT_U8(7)) == 0x80u);
18+
static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u);
19+
static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u);
20+
static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull);
21+
1222
static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX);
1323
static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX);
1424
static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX);

0 commit comments

Comments
 (0)