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

125 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 next_upage(struct ftl_map *map, uint32_t p);
static void test_upage0(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 0);
assert_int_equal(ret, 1);
}
static void test_upage14(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 14);
assert_int_equal(ret, 16);
}
static void test_upage15(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 15);
assert_int_equal(ret, 16);
}
static void test_upage16(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 16);
assert_int_equal(ret, 17);
}
static void test_upage62(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 62);
assert_int_equal(ret, 0);
}
static void test_upage63(void **state)
{
struct ftl_map map;
uint32_t ret;
(void)state;
map.log2_pages_per_group = ilog2(16);
map.log2_groups_per_block = ilog2(1);
map.nblocks = 4;
ret = next_upage(&map, 63);
assert_int_equal(ret, 0);
}
int test_next_upage(void)
{
const struct CMUnitTest tests[] = {
{ "next_upage: upage=0", test_upage0, NULL, NULL, NULL },
{ "next_upage: upage=14", test_upage14, NULL, NULL, NULL },
{ "next_upage: upage=15", test_upage15, NULL, NULL, NULL },
{ "next_upage: upage=16", test_upage16, NULL, NULL, NULL },
{ "next_upage: upage=62 (wraparound)", test_upage62, NULL, NULL, NULL },
{ "next_upage: upage=63 (wraparound)", test_upage63, NULL, NULL, NULL },
};
return cmocka_run_group_tests_name("next_upage", tests, NULL, NULL);
}