test: ftl: add tests for read_page_group()
This commit is contained in:
parent
3e0df6537a
commit
ed49402e3b
3 changed files with 100 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
test-obj-y += source/tests/main.o
|
||||
test-obj-y += source/tests/ftl/find_block_div.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_desc.o
|
||||
test-obj-y += source/tests/ftl/write_page_desc.o
|
||||
|
||||
|
|
97
source/tests/ftl/read_page_group.c
Normal file
97
source/tests/ftl/read_page_group.c
Normal file
|
@ -0,0 +1,97 @@
|
|||
#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>
|
||||
|
||||
size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
|
||||
void *data, size_t len) __attribute__((used));
|
||||
int read_page_group(struct ftl_map *map,
|
||||
struct ftl_page_group *group, uint32_t upage);
|
||||
|
||||
static void test_magic(void **state)
|
||||
{
|
||||
struct ftl_map map;
|
||||
struct ftl_page_group group, ret_group;
|
||||
size_t ret;
|
||||
|
||||
(void)state;
|
||||
|
||||
memcpy(&group.magic, "FtL", 3);
|
||||
|
||||
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB);
|
||||
expect_value(__wrap_flash_read, len, sizeof group);
|
||||
will_return(__wrap_flash_read, sizeof group);
|
||||
will_return(__wrap_flash_read, &group);
|
||||
|
||||
map.log2_pages_per_group = ilog2(16);
|
||||
map.log2_page_size = ilog2(4 * KIB);
|
||||
|
||||
ret = read_page_group(&map, &ret_group, 0);
|
||||
|
||||
assert_int_equal(ret, -1);
|
||||
}
|
||||
|
||||
static void test_group0(void **state)
|
||||
{
|
||||
struct ftl_map map;
|
||||
struct ftl_page_group group, ret_group;
|
||||
size_t ret;
|
||||
|
||||
(void)state;
|
||||
|
||||
memcpy(&group.magic, "FTL", 3);
|
||||
|
||||
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB);
|
||||
expect_value(__wrap_flash_read, len, sizeof group);
|
||||
will_return(__wrap_flash_read, sizeof group);
|
||||
will_return(__wrap_flash_read, &group);
|
||||
|
||||
map.log2_pages_per_group = ilog2(16);
|
||||
map.log2_page_size = ilog2(4 * KIB);
|
||||
|
||||
ret = read_page_group(&map, &ret_group, 0);
|
||||
|
||||
assert_int_equal(ret, 0);
|
||||
}
|
||||
|
||||
static void test_group1(void **state)
|
||||
{
|
||||
struct ftl_map map;
|
||||
struct ftl_page_group group, ret_group;
|
||||
size_t ret;
|
||||
|
||||
(void)state;
|
||||
|
||||
memcpy(&group.magic, "FTL", 3);
|
||||
|
||||
expect_value(__wrap_flash_read, addr, (2 * 16 - 1) * 4 * KIB);
|
||||
expect_value(__wrap_flash_read, len, sizeof group);
|
||||
will_return(__wrap_flash_read, sizeof group);
|
||||
will_return(__wrap_flash_read, &group);
|
||||
|
||||
map.log2_pages_per_group = ilog2(16);
|
||||
map.log2_page_size = ilog2(4 * KIB);
|
||||
|
||||
ret = read_page_group(&map, &ret_group, 1);
|
||||
|
||||
assert_int_equal(ret, 0);
|
||||
}
|
||||
|
||||
int test_read_page_group(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
{ "read_page_group: invalid magic", test_magic, NULL, NULL, NULL },
|
||||
{ "read_page_group: group=0", test_group0, NULL, NULL, NULL },
|
||||
{ "read_page_group: group=1", test_group1, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests_name("read_page_group", tests, NULL, NULL);
|
||||
}
|
|
@ -74,6 +74,7 @@ int __wrap_flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len)
|
|||
|
||||
int test_find_block_div(void);
|
||||
int test_next_upage(void);
|
||||
int test_read_page_group(void);
|
||||
int test_read_page_desc(void);
|
||||
int test_write_page_desc(void);
|
||||
|
||||
|
@ -83,6 +84,7 @@ int main(void)
|
|||
|
||||
count += test_find_block_div();
|
||||
count += test_next_upage();
|
||||
count += test_read_page_group();
|
||||
count += test_read_page_desc();
|
||||
count += test_write_page_desc();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue