You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
4.4 KiB
182 lines
4.4 KiB
#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 __real_read_page_desc(struct ftl_map *map,
|
|
struct ftl_page_desc *page_desc, uint32_t upage);
|
|
|
|
static void test_upage0(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc page_desc, ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
memcpy(&page_desc.magic, "page", 4);
|
|
|
|
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB +
|
|
sizeof(struct ftl_page_group));
|
|
expect_value(__wrap_flash_read, len, sizeof page_desc);
|
|
will_return(__wrap_flash_read, sizeof page_desc);
|
|
will_return(__wrap_flash_read, &page_desc);
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 0);
|
|
|
|
assert_int_equal(ret, 0);
|
|
}
|
|
|
|
static void test_upage14(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc page_desc, ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
memcpy(&page_desc.magic, "page", 4);
|
|
|
|
expect_value(__wrap_flash_read, addr, (16 - 1) * 4 * KIB +
|
|
sizeof(struct ftl_page_group) + 14 * sizeof(struct ftl_page_desc));
|
|
expect_value(__wrap_flash_read, len, sizeof page_desc);
|
|
will_return(__wrap_flash_read, sizeof page_desc);
|
|
will_return(__wrap_flash_read, &page_desc);
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 14);
|
|
|
|
assert_int_equal(ret, 0);
|
|
}
|
|
|
|
static void test_upage15(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 15);
|
|
|
|
assert_int_equal(ret, -1);
|
|
}
|
|
|
|
static void test_upage16(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc page_desc, ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
memcpy(&page_desc.magic, "page", 4);
|
|
|
|
expect_value(__wrap_flash_read, addr, (32 - 1) * 4 * KIB +
|
|
sizeof(struct ftl_page_group));
|
|
expect_value(__wrap_flash_read, len, sizeof page_desc);
|
|
will_return(__wrap_flash_read, sizeof page_desc);
|
|
will_return(__wrap_flash_read, &page_desc);
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 16);
|
|
|
|
assert_int_equal(ret, 0);
|
|
}
|
|
|
|
static void test_upage30(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc page_desc, ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
memcpy(&page_desc.magic, "page", 4);
|
|
|
|
expect_value(__wrap_flash_read, addr, (32 - 1) * 4 * KIB +
|
|
sizeof(struct ftl_page_group) + 14 * sizeof(struct ftl_page_desc));
|
|
expect_value(__wrap_flash_read, len, sizeof page_desc);
|
|
will_return(__wrap_flash_read, sizeof page_desc);
|
|
will_return(__wrap_flash_read, &page_desc);
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 30);
|
|
|
|
assert_int_equal(ret, 0);
|
|
}
|
|
|
|
static void test_upage31(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 31);
|
|
|
|
assert_int_equal(ret, -1);
|
|
}
|
|
|
|
static void test_upage32(void **state)
|
|
{
|
|
struct ftl_map map;
|
|
struct ftl_page_desc page_desc, ret_page_desc;
|
|
size_t ret;
|
|
|
|
(void)state;
|
|
|
|
memcpy(&page_desc.magic, "page", 4);
|
|
|
|
expect_value(__wrap_flash_read, addr, (48 - 1) * 4 * KIB +
|
|
sizeof(struct ftl_page_group));
|
|
expect_value(__wrap_flash_read, len, sizeof page_desc);
|
|
will_return(__wrap_flash_read, sizeof page_desc);
|
|
will_return(__wrap_flash_read, &page_desc);
|
|
|
|
map.log2_pages_per_group = ilog2(16);
|
|
map.log2_page_size = ilog2(4 * KIB);
|
|
|
|
ret = __real_read_page_desc(&map, &ret_page_desc, 32);
|
|
|
|
assert_int_equal(ret, 0);
|
|
}
|
|
|
|
int test_read_page_desc(void)
|
|
{
|
|
const struct CMUnitTest tests[] = {
|
|
{ "read_page_desc: upage=0", test_upage0, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=14", test_upage14, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=15 (invalid)", test_upage15, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=16", test_upage16, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=30", test_upage30, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=31 (invalid)", test_upage31, NULL, NULL, NULL },
|
|
{ "read_page_desc: upage=32", test_upage32, NULL, NULL, NULL },
|
|
};
|
|
|
|
return cmocka_run_group_tests_name("read_page_desc", tests, NULL, NULL);
|
|
}
|
|
|