parent
920a59499b
commit
6243dabea8
@ -0,0 +1,104 @@ |
||||
#include <stdarg.h> |
||||
#include <stddef.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <setjmp.h> |
||||
|
||||
#include <cmocka.h> |
||||
|
||||
#include <bitops.h> |
||||
#include <flash.h> |
||||
#include <ftl.h> |
||||
#include <macros.h> |
||||
|
||||
int find_head(struct ftl_map *map); |
||||
|
||||
static void test_erased(void **state) |
||||
{ |
||||
struct ftl_map map; |
||||
int ret; |
||||
|
||||
(void)state; |
||||
|
||||
map.log2_pages_per_group = ilog2(16); |
||||
map.log2_groups_per_block = ilog2(1); |
||||
map.nblocks = 4; |
||||
map.root = 4; |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 5); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 1); |
||||
|
||||
ret = find_head(&map); |
||||
|
||||
assert_int_equal(ret, 0); |
||||
assert_int_equal(map.head, 5); |
||||
} |
||||
|
||||
static void test_end_of_block(void **state) |
||||
{ |
||||
struct ftl_map map; |
||||
int ret; |
||||
|
||||
(void)state; |
||||
|
||||
map.log2_pages_per_group = ilog2(16); |
||||
map.log2_groups_per_block = ilog2(1); |
||||
map.nblocks = 4; |
||||
map.root = 4; |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 5); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 6); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 7); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 8); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 9); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 10); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 11); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 12); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 13); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
expect_value(__wrap_flash_is_erased, addr, 14); |
||||
expect_value(__wrap_flash_is_erased, len, 1); |
||||
will_return(__wrap_flash_is_erased, 0); |
||||
|
||||
ret = find_head(&map); |
||||
|
||||
assert_int_equal(ret, 0); |
||||
assert_int_equal(map.head, 16); |
||||
} |
||||
|
||||
int test_find_head(void) |
||||
{ |
||||
const struct CMUnitTest tests[] = { |
||||
{ "find_head: erased", test_erased, NULL, NULL, NULL }, |
||||
{ "find_head: end of block", test_end_of_block, NULL, NULL, NULL }, |
||||
}; |
||||
|
||||
return cmocka_run_group_tests_name("find_head", tests, NULL, NULL); |
||||
} |
Loading…
Reference in new issue