1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <commonlib/bsd/helpers.h>
4 #include <tests/test.h>
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);
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
)
30 assert_true(retry(3, ++count
== 1));
32 assert_true(retry(3, ++count
== 3));
34 assert_false(retry(3, ++count
== 4));
37 expect_function_calls(func
, 9);
38 assert_null(retry(10, NULL
, func()));
40 assert_int_equal(retry(10, 999, func()), 999);
43 expect_function_calls(func
, 3);
44 assert_true(retry(10, ++count
== 4, func()));
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
);