test: ftl: add tests for find_head()
This commit is contained in:
parent
920a59499b
commit
6243dabea8
4 changed files with 108 additions and 1 deletions
|
@ -353,7 +353,7 @@ int find_root(struct ftl_map *map, uint32_t group)
|
|||
* within the page group, the first user page of the next page group should be
|
||||
* used as that page group should not be in use.
|
||||
*/
|
||||
static int find_head(struct ftl_map *map)
|
||||
int find_head(struct ftl_map *map)
|
||||
{
|
||||
size_t log2_pages_per_block = map->log2_pages_per_group +
|
||||
map->log2_groups_per_block;
|
||||
|
|
|
@ -4,6 +4,7 @@ test-obj-y += source/tests/ftl/find_block.o
|
|||
test-obj-y += source/tests/ftl/find_block_div.o
|
||||
test-obj-y += source/tests/ftl/find_last_block.o
|
||||
test-obj-y += source/tests/ftl/find_last_group.o
|
||||
test-obj-y += source/tests/ftl/find_head.o
|
||||
test-obj-y += source/tests/ftl/find_root.o
|
||||
test-obj-y += source/tests/ftl/next_upage.o
|
||||
test-obj-y += source/tests/ftl/read_page_group.o
|
||||
|
|
104
source/tests/ftl/find_head.c
Normal file
104
source/tests/ftl/find_head.c
Normal file
|
@ -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);
|
||||
}
|
|
@ -71,6 +71,7 @@ int test_find_block(void);
|
|||
int test_find_block_div(void);
|
||||
int test_find_last_block(void);
|
||||
int test_find_last_group(void);
|
||||
int test_find_head(void);
|
||||
int test_find_root(void);
|
||||
int test_next_upage(void);
|
||||
int test_read_page_group(void);
|
||||
|
@ -86,6 +87,7 @@ int main(void)
|
|||
count += test_find_block_div();
|
||||
count += test_find_last_block();
|
||||
count += test_find_last_group();
|
||||
count += test_find_head();
|
||||
count += test_find_root();
|
||||
count += test_next_upage();
|
||||
count += test_read_page_group();
|
||||
|
|
Loading…
Add table
Reference in a new issue