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.
157 lines
4.0 KiB
157 lines
4.0 KiB
7 years ago
|
#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>
|
||
|
|
||
|
uint32_t find_last_group(struct ftl_map *map, uint32_t block);
|
||
|
|
||
|
static void test_middle(void **state)
|
||
|
{
|
||
|
struct ftl_map map;
|
||
|
uint32_t ret;
|
||
|
|
||
|
(void)state;
|
||
|
|
||
|
map.log2_groups_per_block = ilog2(8);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 3);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 4);
|
||
|
will_return(__wrap_is_group_erased, 1);
|
||
|
|
||
|
ret = find_last_group(&map, 4);
|
||
|
assert_int_equal(ret, 32 + 3);
|
||
|
}
|
||
|
|
||
|
static void test_first(void **state)
|
||
|
{
|
||
|
struct ftl_map map;
|
||
|
uint32_t ret;
|
||
|
|
||
|
(void)state;
|
||
|
|
||
|
map.log2_groups_per_block = ilog2(8);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 3);
|
||
|
will_return(__wrap_is_group_erased, 1);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 1);
|
||
|
will_return(__wrap_is_group_erased, 1);
|
||
|
|
||
|
ret = find_last_group(&map, 4);
|
||
|
assert_int_equal(ret, 32);
|
||
|
}
|
||
|
|
||
|
static void test_last(void **state)
|
||
|
{
|
||
|
struct ftl_map map;
|
||
|
uint32_t ret;
|
||
|
|
||
|
(void)state;
|
||
|
|
||
|
map.log2_groups_per_block = ilog2(8);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 3);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 4);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 5);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 6);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 6);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 7);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
ret = find_last_group(&map, 4);
|
||
|
assert_int_equal(ret, 32 + 7);
|
||
|
}
|
||
|
|
||
|
static void test_left_right(void **state)
|
||
|
{
|
||
|
struct ftl_map map;
|
||
|
uint32_t ret;
|
||
|
|
||
|
(void)state;
|
||
|
|
||
|
map.log2_groups_per_block = ilog2(8);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 3);
|
||
|
will_return(__wrap_is_group_erased, 1);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 1);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 2);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
ret = find_last_group(&map, 4);
|
||
|
assert_int_equal(ret, 32 + 2);
|
||
|
}
|
||
|
|
||
|
static void test_right_left(void **state)
|
||
|
{
|
||
|
struct ftl_map map;
|
||
|
uint32_t ret;
|
||
|
|
||
|
(void)state;
|
||
|
|
||
|
map.log2_groups_per_block = ilog2(8);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 3);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 4);
|
||
|
will_return(__wrap_is_group_erased, 0);
|
||
|
|
||
|
expect_value(__wrap_is_group_erased, map, &map);
|
||
|
expect_value(__wrap_is_group_erased, group, 32 + 5);
|
||
|
will_return(__wrap_is_group_erased, 1);
|
||
|
|
||
|
ret = find_last_group(&map, 4);
|
||
|
assert_int_equal(ret, 32 + 4);
|
||
|
}
|
||
|
|
||
|
int test_find_last_group(void)
|
||
|
{
|
||
|
const struct CMUnitTest tests[] = {
|
||
|
{ "find_last_group: middle", test_middle, NULL, NULL, NULL },
|
||
|
{ "find_last_group: first", test_first, NULL, NULL, NULL },
|
||
|
{ "find_last_group: last", test_last, NULL, NULL, NULL },
|
||
|
{ "find_last_group: left right", test_left_right, NULL, NULL, NULL },
|
||
|
{ "find_last_group: right left", test_right_left, NULL, NULL, NULL },
|
||
|
};
|
||
|
|
||
|
return cmocka_run_group_tests_name("find_last_group", tests, NULL, NULL);
|
||
|
}
|