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.1 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_next_upage1(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_next_upage2(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_next_upage3(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_next_upage4(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_next_upage5(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_next_upage6(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[] = {
cmocka_unit_test(test_next_upage1),
cmocka_unit_test(test_next_upage2),
cmocka_unit_test(test_next_upage3),
cmocka_unit_test(test_next_upage4),
cmocka_unit_test(test_next_upage5),
cmocka_unit_test(test_next_upage6),
};
return cmocka_run_group_tests_name("next_upage", tests, NULL, NULL);
}