test: reorganise code
This commit is contained in:
parent
6243dabea8
commit
5004fed4aa
4 changed files with 117 additions and 78 deletions
|
@ -1,4 +1,8 @@
|
|||
test-obj-y += source/tests/main.o
|
||||
|
||||
test-obj-y += source/tests/flash/mock.o
|
||||
|
||||
test-obj-y += source/tests/ftl/main.o
|
||||
test-obj-y += source/tests/ftl/mock.o
|
||||
test-obj-y += source/tests/ftl/find_block.o
|
||||
test-obj-y += source/tests/ftl/find_block_div.o
|
||||
|
|
68
source/tests/flash/mock.c
Normal file
68
source/tests/flash/mock.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
#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>
|
||||
|
||||
size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
|
||||
void *data, size_t len)
|
||||
{
|
||||
const void *ret_data;
|
||||
size_t ret_len;
|
||||
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
ret_len = mock_type(size_t);
|
||||
ret_data = mock_type(const void *);
|
||||
|
||||
if (len > ret_len)
|
||||
len = ret_len;
|
||||
|
||||
if (len)
|
||||
memcpy(data, ret_data, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t __wrap_flash_write(struct flash_dev *dev, uint32_t addr,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
void *ret_data;
|
||||
size_t ret_len;
|
||||
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
ret_len = mock_type(size_t);
|
||||
ret_data = mock_type(void *);
|
||||
|
||||
if (len > ret_len)
|
||||
len = ret_len;
|
||||
|
||||
if (len)
|
||||
memcpy(ret_data, data, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int __wrap_flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len)
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
return mock_type(int);
|
||||
}
|
43
source/tests/ftl/main.c
Normal file
43
source/tests/ftl/main.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
#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 test_find_block(void);
|
||||
int test_find_block_div(void);
|
||||
int test_find_last_block(void);
|
||||
int test_find_last_group(void);
|
||||
int test_find_head(void);
|
||||
int test_find_root(void);
|
||||
int test_next_upage(void);
|
||||
int test_read_page_group(void);
|
||||
int test_read_page_desc(void);
|
||||
int test_write_page_desc(void);
|
||||
int test_write_upage(void);
|
||||
|
||||
int test_ftl(void)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
count += test_find_block();
|
||||
count += test_find_block_div();
|
||||
count += test_find_last_block();
|
||||
count += test_find_last_group();
|
||||
count += test_find_head();
|
||||
count += test_find_root();
|
||||
count += test_next_upage();
|
||||
count += test_read_page_group();
|
||||
count += test_read_page_desc();
|
||||
count += test_write_page_desc();
|
||||
count += test_write_upage();
|
||||
|
||||
return count;
|
||||
}
|
|
@ -11,89 +11,13 @@
|
|||
#include <ftl.h>
|
||||
#include <macros.h>
|
||||
|
||||
size_t __wrap_flash_read(struct flash_dev *dev, uint32_t addr,
|
||||
void *data, size_t len)
|
||||
{
|
||||
const void *ret_data;
|
||||
size_t ret_len;
|
||||
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
ret_len = mock_type(size_t);
|
||||
ret_data = mock_type(const void *);
|
||||
|
||||
if (len > ret_len)
|
||||
len = ret_len;
|
||||
|
||||
if (len)
|
||||
memcpy(data, ret_data, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t __wrap_flash_write(struct flash_dev *dev, uint32_t addr,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
void *ret_data;
|
||||
size_t ret_len;
|
||||
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
ret_len = mock_type(size_t);
|
||||
ret_data = mock_type(void *);
|
||||
|
||||
if (len > ret_len)
|
||||
len = ret_len;
|
||||
|
||||
if (len)
|
||||
memcpy(ret_data, data, len);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int __wrap_flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len)
|
||||
{
|
||||
(void)dev;
|
||||
|
||||
check_expected(addr);
|
||||
check_expected(len);
|
||||
|
||||
return mock_type(int);
|
||||
}
|
||||
|
||||
int test_find_block(void);
|
||||
int test_find_block_div(void);
|
||||
int test_find_last_block(void);
|
||||
int test_find_last_group(void);
|
||||
int test_find_head(void);
|
||||
int test_find_root(void);
|
||||
int test_next_upage(void);
|
||||
int test_read_page_group(void);
|
||||
int test_read_page_desc(void);
|
||||
int test_write_page_desc(void);
|
||||
int test_write_upage(void);
|
||||
int test_ftl(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
count += test_find_block();
|
||||
count += test_find_block_div();
|
||||
count += test_find_last_block();
|
||||
count += test_find_last_group();
|
||||
count += test_find_head();
|
||||
count += test_find_root();
|
||||
count += test_next_upage();
|
||||
count += test_read_page_group();
|
||||
count += test_read_page_desc();
|
||||
count += test_write_page_desc();
|
||||
count += test_write_upage();
|
||||
count += test_ftl();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue