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

70 lines
1.5 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 find_block_div(struct ftl_map *map);
static void test_4k_page_64k_block(void **state)
{
struct ftl_map map;
(void)state;
map.log2_block_size = ilog2(64 * KIB);
map.log2_page_size = ilog2(4 * KIB);
find_block_div(&map);
assert_int_equal(1 << map.log2_pages_per_group, 16);
assert_int_equal(1 << map.log2_groups_per_block, 1);
}
static void test_4k_page_16k_block(void **state)
{
struct ftl_map map;
(void)state;
map.log2_block_size = ilog2(16 * KIB);
map.log2_page_size = ilog2(4 * KIB);
find_block_div(&map);
assert_int_equal(1 << map.log2_pages_per_group, 4);
assert_int_equal(1 << map.log2_groups_per_block, 1);
}
static void test_1k_page_64k_block(void **state)
{
struct ftl_map map;
(void)state;
map.log2_block_size = ilog2(64 * KIB);
map.log2_page_size = ilog2(1 * KIB);
find_block_div(&map);
assert_int_equal(1 << map.log2_pages_per_group, 8);
assert_int_equal(1 << map.log2_groups_per_block, 8);
}
int test_find_block_div(void)
{
const struct CMUnitTest tests[] = {
{ "find_block_div: 4K page, 64K block", test_4k_page_64k_block, NULL, NULL, NULL },
{ "find_block_div: 4K page, 16K block", test_4k_page_16k_block, NULL, NULL, NULL },
{ "find_block_div: 1K page, 64K block", test_1k_page_64k_block, NULL, NULL, NULL },
};
return cmocka_run_group_tests_name("find_block_div", tests, NULL, NULL);
}