sconfig: Move (WEAK_)DEV_PTR from device.h to static.h
[coreboot.git] / tests / commonlib / bsd / helpers-test.c
blob6fae331fd7c5e901e2d47948fc87217474c05d2a
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/bsd/helpers.h>
4 #include <tests/test.h>
6 static void func(void)
8 function_called();
11 static void test_genmask(void **state)
13 assert_int_equal(GENMASK(4, 4), 0x10);
14 assert_int_equal(GENMASK(4, 3), 0x18);
15 assert_int_equal(GENMASK(4, 0), 0x1f);
16 /* Edge cases */
17 assert_int_equal(GENMASK(0, 0), 1);
18 assert_int_equal(GENMASK(31, 31), 0x80000000);
19 assert_int_equal(GENMASK(31, 0), 0xffffffff);
20 assert_int_equal(GENMASK(63, 63), 0x8000000000000000);
21 assert_int_equal(GENMASK(63, 0), 0xffffffffffffffff);
24 static void test_retry(void **state)
26 int count;
28 /* 2-argument form */
29 count = 0;
30 assert_true(retry(3, ++count == 1));
31 count = 0;
32 assert_true(retry(3, ++count == 3));
33 count = 0;
34 assert_false(retry(3, ++count == 4));
36 /* 3-argument form */
37 expect_function_calls(func, 9);
38 assert_null(retry(10, NULL, func()));
40 assert_int_equal(retry(10, 999, func()), 999);
42 count = 0;
43 expect_function_calls(func, 3);
44 assert_true(retry(10, ++count == 4, func()));
47 int main(void)
49 const struct CMUnitTest tests[] = {
50 cmocka_unit_test(test_genmask),
51 cmocka_unit_test(test_retry),
54 return cb_run_group_tests(tests, NULL, NULL);