test: ftl: add tests for find_root()

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent b8426f12f2
commit 920a59499b
  1. 2
      source/ftl/map.c
  2. 1
      source/tests/Makefile
  3. 153
      source/tests/ftl/find_root.c
  4. 2
      source/tests/main.c

@ -331,7 +331,7 @@ uint32_t find_last_group(struct ftl_map *map, uint32_t block)
return low; return low;
} }
static int find_root(struct ftl_map *map, uint32_t group) int find_root(struct ftl_map *map, uint32_t group)
{ {
struct ftl_page_desc page_desc; struct ftl_page_desc page_desc;
uint32_t upage; uint32_t upage;

@ -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_block_div.o
test-obj-y += source/tests/ftl/find_last_block.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_last_group.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/next_upage.o
test-obj-y += source/tests/ftl/read_page_group.o test-obj-y += source/tests/ftl/read_page_group.o
test-obj-y += source/tests/ftl/read_page_desc.o test-obj-y += source/tests/ftl/read_page_desc.o

@ -0,0 +1,153 @@
#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_root(struct ftl_map *map, uint32_t group);
static void test_group0_upage0(void **state)
{
struct ftl_map map;
struct ftl_page_desc page_desc;
int ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 0);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, -1);
ret = find_root(&map, 0);
assert_int_equal(ret, -1);
}
static void test_group0_upage5(void **state)
{
struct ftl_map map;
struct ftl_page_desc page_desc;
int ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 0);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 1);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 2);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 3);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 4);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 5);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 6);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, -1);
ret = find_root(&map, 0);
assert_int_equal(ret, 0);
assert_int_equal(map.root, 5);
}
static void test_group1_upage5(void **state)
{
struct ftl_map map;
struct ftl_page_desc page_desc;
int ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 1);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 2);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 3);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 4);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 5);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, 0);
expect_value(__wrap_read_page_desc, map, &map);
expect_value(__wrap_read_page_desc, upage, 16 + 6);
will_return(__wrap_read_page_desc, &page_desc);
will_return(__wrap_read_page_desc, -1);
ret = find_root(&map, 1);
assert_int_equal(ret, 0);
assert_int_equal(map.root, 16 + 5);
}
int test_find_root(void)
{
const struct CMUnitTest tests[] = {
{ "find_root: group=0, upage=0 (no root)", test_group0_upage0, NULL, NULL, NULL },
{ "find_root: group=0, upage=5", test_group0_upage5, NULL, NULL, NULL },
{ "find_root: group=1, upage=5", test_group1_upage5, NULL, NULL, NULL },
};
return cmocka_run_group_tests_name("find_root", tests, NULL, NULL);
}

@ -71,6 +71,7 @@ int test_find_block(void);
int test_find_block_div(void); int test_find_block_div(void);
int test_find_last_block(void); int test_find_last_block(void);
int test_find_last_group(void); int test_find_last_group(void);
int test_find_root(void);
int test_next_upage(void); int test_next_upage(void);
int test_read_page_group(void); int test_read_page_group(void);
int test_read_page_desc(void); int test_read_page_desc(void);
@ -85,6 +86,7 @@ int main(void)
count += test_find_block_div(); count += test_find_block_div();
count += test_find_last_block(); count += test_find_last_block();
count += test_find_last_group(); count += test_find_last_group();
count += test_find_root();
count += test_next_upage(); count += test_next_upage();
count += test_read_page_group(); count += test_read_page_group();
count += test_read_page_desc(); count += test_read_page_desc();

Loading…
Cancel
Save