parent
e84226657c
commit
a63e7656fe
@ -1,3 +1,4 @@ |
||||
test-obj-y += source/tests/main.o
|
||||
test-obj-y += source/tests/ftl/find_block_div.o
|
||||
test-obj-y += source/tests/ftl/next_upage.o
|
||||
test-obj-y += source/tests/ftl/read_page_desc.o
|
||||
|
@ -0,0 +1,125 @@ |
||||
#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); |
||||
} |
Loading…
Reference in new issue