| 1 |
|
| 2 |
|
| 3 |
#include <commonlib/bsd/helpers.h> |
| 4 |
#include <tests/test.h> |
| 5 |
|
| 6 |
static void func(void) |
| 7 |
{ |
| 8 |
function_called(); |
| 9 |
} |
| 10 |
|
| 11 |
static void test_genmask(void **state) |
| 12 |
{ |
| 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 |
|
| 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); |
| 22 |
} |
| 23 |
|
| 24 |
static void test_retry(void **state) |
| 25 |
{ |
| 26 |
int count; |
| 27 |
|
| 28 |
|
| 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)); |
| 35 |
|
| 36 |
|
| 37 |
expect_function_calls(func, 9); |
| 38 |
assert_null(retry(10, NULL, func())); |
| 39 |
|
| 40 |
assert_int_equal(retry(10, 999, func()), 999); |
| 41 |
|
| 42 |
count = 0; |
| 43 |
expect_function_calls(func, 3); |
| 44 |
assert_true(retry(10, ++count == 4, func())); |
| 45 |
} |
| 46 |
|
| 47 |
int main(void) |
| 48 |
{ |
| 49 |
const struct CMUnitTest tests[] = { |
| 50 |
cmocka_unit_test(test_genmask), |
| 51 |
cmocka_unit_test(test_retry), |
| 52 |
}; |
| 53 |
|
| 54 |
return cb_run_group_tests(tests, NULL, NULL); |
| 55 |
} |