test: ftl: add tests for ftl_is_mapped()
This commit is contained in:
parent
5004fed4aa
commit
f3eb5df644
5 changed files with 98 additions and 0 deletions
|
@ -447,6 +447,11 @@ int ftl_resume_map(struct ftl_map *map)
|
|||
* depth until we have either found that there is no further subtree to
|
||||
* traverse or until we have found the actual user page.
|
||||
*/
|
||||
#ifdef trace_path
|
||||
#undef trace_path
|
||||
#define trace_path __real_trace_path
|
||||
#endif
|
||||
|
||||
int trace_path(struct ftl_map *map, struct ftl_page_desc *new_page_desc,
|
||||
uint32_t *page, uint32_t va)
|
||||
{
|
||||
|
|
|
@ -16,6 +16,8 @@ test-obj-y += source/tests/ftl/read_page_desc.o
|
|||
test-obj-y += source/tests/ftl/write_page_desc.o
|
||||
test-obj-y += source/tests/ftl/write_upage.o
|
||||
|
||||
test-obj-y += source/tests/ftl/ftl_is_mapped.o
|
||||
|
||||
TEST_CFLAGS += -Dflash_read=__wrap_flash_read
|
||||
TEST_CFLAGS += -Dflash_write=__wrap_flash_write
|
||||
TEST_CFLAGS += -Dflash_is_erased=__wrap_flash_is_erased
|
||||
|
@ -25,3 +27,4 @@ TEST_CFLAGS += -Dfind_block=__wrap_find_block
|
|||
TEST_CFLAGS += -Dprepare_head=__wrap_prepare_head
|
||||
TEST_CFLAGS += -Dread_page_desc=__wrap_read_page_desc
|
||||
TEST_CFLAGS += -Dwrite_page_desc=__wrap_write_page_desc
|
||||
TEST_CFLAGS += -Dtrace_path=__wrap_trace_path
|
||||
|
|
62
source/tests/ftl/ftl_is_mapped.c
Normal file
62
source/tests/ftl/ftl_is_mapped.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
#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>
|
||||
|
||||
static void test_unmapped(void **state)
|
||||
{
|
||||
struct ftl_map map;
|
||||
int ret;
|
||||
|
||||
(void)state;
|
||||
|
||||
expect_value(__wrap_trace_path, map, &map);
|
||||
expect_value(__wrap_trace_path, new_page_desc, NULL);
|
||||
expect_value(__wrap_trace_path, page, NULL);
|
||||
expect_value(__wrap_trace_path, va, 42);
|
||||
will_return(__wrap_trace_path, NULL);
|
||||
will_return(__wrap_trace_path, 0);
|
||||
will_return(__wrap_trace_path, -1);
|
||||
|
||||
ret = ftl_is_mapped(&map, 42);
|
||||
|
||||
assert_int_equal(ret, 0);
|
||||
}
|
||||
|
||||
static void test_mapped(void **state)
|
||||
{
|
||||
struct ftl_map map;
|
||||
int ret;
|
||||
|
||||
(void)state;
|
||||
|
||||
expect_value(__wrap_trace_path, map, &map);
|
||||
expect_value(__wrap_trace_path, new_page_desc, NULL);
|
||||
expect_value(__wrap_trace_path, page, NULL);
|
||||
expect_value(__wrap_trace_path, va, 42);
|
||||
will_return(__wrap_trace_path, NULL);
|
||||
will_return(__wrap_trace_path, 0);
|
||||
will_return(__wrap_trace_path, 0);
|
||||
|
||||
ret = ftl_is_mapped(&map, 42);
|
||||
|
||||
assert_int_equal(ret, 1);
|
||||
}
|
||||
|
||||
int test_ftl_is_mapped(void)
|
||||
{
|
||||
const struct CMUnitTest tests[] = {
|
||||
{ "ftl_is_mapped: unmapped", test_unmapped, NULL, NULL, NULL },
|
||||
{ "ftl_is_mapped: mapped", test_mapped, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests_name("ftl_is_unmapped", tests, NULL, NULL);
|
||||
}
|
|
@ -23,6 +23,8 @@ int test_read_page_desc(void);
|
|||
int test_write_page_desc(void);
|
||||
int test_write_upage(void);
|
||||
|
||||
int test_ftl_is_mapped(void);
|
||||
|
||||
int test_ftl(void)
|
||||
{
|
||||
int count = 0;
|
||||
|
@ -39,5 +41,7 @@ int test_ftl(void)
|
|||
count += test_write_page_desc();
|
||||
count += test_write_upage();
|
||||
|
||||
count += test_ftl_is_mapped();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
|
@ -61,3 +61,27 @@ int __wrap_write_page_desc(struct ftl_map *map,
|
|||
|
||||
return mock_type(int);
|
||||
}
|
||||
|
||||
int __wrap_trace_path(struct ftl_map *map, struct ftl_page_desc *new_page_desc,
|
||||
uint32_t *page, uint32_t va)
|
||||
{
|
||||
struct ftl_page_desc *ret_page_desc;
|
||||
uint32_t ret_page;
|
||||
|
||||
check_expected_ptr(map);
|
||||
check_expected_ptr(new_page_desc);
|
||||
check_expected_ptr(page);
|
||||
check_expected(va);
|
||||
|
||||
ret_page_desc = mock_type(struct ftl_page_desc *);
|
||||
|
||||
if (new_page_desc)
|
||||
memcpy(new_page_desc, ret_page_desc, sizeof *new_page_desc);
|
||||
|
||||
ret_page = mock_type(uint32_t);
|
||||
|
||||
if (page)
|
||||
*page = ret_page;
|
||||
|
||||
return mock_type(int);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue