soc/intel/pantherlake: Enable CPU feature programming in coreboot
[coreboot.git] / tests / lib / lib-test.c
blob826c6c563a94481104234a7104e381067d7d3506
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <lib.h>
4 #include <tests/test.h>
6 void test_popcnt(void **state)
8 assert_int_equal(popcnt(0x0), 0);
9 assert_int_equal(popcnt(0x10), 1);
10 assert_int_equal(popcnt(0x10010010), 3);
11 assert_int_equal(popcnt(0xffffffff), 32);
14 void test_clz(void **state)
16 assert_int_equal(clz(0x0), 32);
17 assert_int_equal(clz(0xf), 28);
18 assert_int_equal(clz(0x80000000), 0);
19 assert_int_equal(clz(0xffffffff), 0);
22 void test_log2(void **state)
24 assert_int_equal(log2(0x0), -1);
25 assert_int_equal(log2(0x1), 0);
26 assert_int_equal(log2(0x5), 2);
27 assert_int_equal(log2(0x80000000), 31);
28 assert_int_equal(log2(0xffffffff), 31);
31 void test_ffs(void **state)
33 assert_int_equal(__ffs(0x0), -1);
34 assert_int_equal(__ffs(0x1), 0);
35 assert_int_equal(__ffs(0x1010), 4);
36 assert_int_equal(__ffs(0x10000000), 28);
37 assert_int_equal(__ffs(0xffffffff), 0);
40 void test_fls(void **state)
42 assert_int_equal(__fls(0x0), -1);
43 assert_int_equal(__fls(0x1), 0);
44 assert_int_equal(__fls(0x5), 2);
45 assert_int_equal(__fls(0x80000000), 31);
46 assert_int_equal(__fls(0xffffffff), 31);
49 void test_log2_ceil(void **state)
51 assert_int_equal(log2_ceil(0x0), -1);
52 assert_int_equal(log2_ceil(0x1), 0);
53 assert_int_equal(log2_ceil(0x5), 3);
54 assert_int_equal(log2_ceil(0x80000000), 31);
55 assert_int_equal(log2_ceil(0xffffffff), 32);
58 int main(void)
60 const struct CMUnitTest tests[] = {
61 cmocka_unit_test(test_popcnt),
62 cmocka_unit_test(test_clz),
63 cmocka_unit_test(test_log2),
64 cmocka_unit_test(test_ffs),
65 cmocka_unit_test(test_fls),
66 cmocka_unit_test(test_log2_ceil),
69 return cb_run_group_tests(tests, NULL, NULL);