Source code for the Trusted Boot Module.
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.
 
 
 
tbm-mcu/source/tests/ftl/read_page_group.c

95 lines
2.2 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 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);
}