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/ftl_read.c

80 lines
1.9 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>
static void test_basic_read(void **state)
{
char data[24];
struct ftl_map map;
int ret;
(void)state;
map.log2_page_size = ilog2(4 * KIB);
map.outstanding.flags = 0;
expect_value(__wrap_trace_path, map, &map);
expect_value(__wrap_trace_path, new_page_desc, NULL);
expect_not_value(__wrap_trace_path, page, NULL);
expect_value(__wrap_trace_path, va, 4);
will_return(__wrap_trace_path, NULL);
will_return(__wrap_trace_path, 42);
will_return(__wrap_trace_path, 0);
expect_value(__wrap_flash_read, addr, 42 << 12 | 0x321);
expect_value(__wrap_flash_read, len, 24);
will_return(__wrap_flash_read, 24);
will_return(__wrap_flash_read, NULL);
ret = ftl_read(&map, data, 24, 0x4321);
assert_int_equal(ret, 24);
}
static void test_boundary(void **state)
{
char data[32];
struct ftl_map map;
int ret;
(void)state;
map.log2_page_size = ilog2(4 * KIB);
map.outstanding.flags = 0;
expect_value(__wrap_trace_path, map, &map);
expect_value(__wrap_trace_path, new_page_desc, NULL);
expect_not_value(__wrap_trace_path, page, NULL);
expect_value(__wrap_trace_path, va, 4);
will_return(__wrap_trace_path, NULL);
will_return(__wrap_trace_path, 42);
will_return(__wrap_trace_path, 0);
expect_value(__wrap_flash_read, addr, 42 << 12 | 0xff0);
expect_value(__wrap_flash_read, len, 16);
will_return(__wrap_flash_read, 16);
will_return(__wrap_flash_read, NULL);
ret = ftl_read(&map, data, 32, 0x4ff0);
assert_int_equal(ret, 16);
}
int test_ftl_read(void)
{
const struct CMUnitTest tests[] = {
{ "ftl_read: basic read", test_basic_read, NULL, NULL, NULL },
{ "ftl_read: boundary", test_boundary, NULL, NULL, NULL },
};
return cmocka_run_group_tests_name("ftl_read", tests, NULL, NULL);
}