test: ftl: add tests for next_upage()
This commit is contained in:
parent
e84226657c
commit
a63e7656fe
4 changed files with 129 additions and 1 deletions
|
@ -46,7 +46,7 @@ static int is_group_erased(struct ftl_map *map, uint32_t group)
|
||||||
* possible pages on the devices, the page number of the very first user page
|
* possible pages on the devices, the page number of the very first user page
|
||||||
* is returned instead.
|
* is returned instead.
|
||||||
*/
|
*/
|
||||||
static uint32_t next_upage(struct ftl_map *map, uint32_t p)
|
uint32_t next_upage(struct ftl_map *map, uint32_t p)
|
||||||
{
|
{
|
||||||
size_t log2_pages_per_block = map->log2_pages_per_group +
|
size_t log2_pages_per_block = map->log2_pages_per_group +
|
||||||
map->log2_groups_per_block;
|
map->log2_groups_per_block;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
test-obj-y += source/tests/main.o
|
test-obj-y += source/tests/main.o
|
||||||
test-obj-y += source/tests/ftl/find_block_div.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
|
test-obj-y += source/tests/ftl/read_page_desc.o
|
||||||
|
|
125
source/tests/ftl/next_upage.c
Normal file
125
source/tests/ftl/next_upage.c
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_find_block_div(void);
|
int test_find_block_div(void);
|
||||||
|
int test_next_upage(void);
|
||||||
int test_read_page_desc(void);
|
int test_read_page_desc(void);
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -35,6 +36,7 @@ int main(void)
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
count += test_find_block_div();
|
count += test_find_block_div();
|
||||||
|
count += test_next_upage();
|
||||||
count += test_read_page_desc();
|
count += test_read_page_desc();
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
|
Loading…
Add table
Reference in a new issue