From 8a8ead3f90ea8d98cae11556e2fe89f7c12fc68c Mon Sep 17 00:00:00 2001 From: Yinfang Wang Date: Sat, 13 Aug 2022 00:34:13 +0800 Subject: [PATCH] tests: subsys: fs: move fcb to new ztest API Move fcb to new ztest API. Signed-off-by: Yinfang Wang --- tests/subsys/fs/fcb/prj.conf | 1 + tests/subsys/fs/fcb/prj_native_posix.conf | 1 + tests/subsys/fs/fcb/prj_native_posix_64.conf | 1 + tests/subsys/fs/fcb/prj_nucleo_h743zi.conf | 1 + tests/subsys/fs/fcb/prj_qemu_x86.conf | 1 + tests/subsys/fs/fcb/src/fcb_test_append.c | 2 +- .../subsys/fs/fcb/src/fcb_test_append_fill.c | 2 +- .../fs/fcb/src/fcb_test_append_too_big.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_empty_walk.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_init.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_last_of_n.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_len.c | 2 +- .../fs/fcb/src/fcb_test_multiple_scratch.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_reset.c | 2 +- tests/subsys/fs/fcb/src/fcb_test_rotate.c | 2 +- tests/subsys/fs/fcb/src/main.c | 62 ++----------------- 16 files changed, 21 insertions(+), 66 deletions(-) diff --git a/tests/subsys/fs/fcb/prj.conf b/tests/subsys/fs/fcb/prj.conf index 42d1dc6c03a..320c5f6195c 100644 --- a/tests/subsys/fs/fcb/prj.conf +++ b/tests/subsys/fs/fcb/prj.conf @@ -6,3 +6,4 @@ CONFIG_FLASH_MAP=y CONFIG_ARM_MPU=n CONFIG_FCB=y CONFIG_SOC_FLASH_NRF_EMULATE_ONE_BYTE_WRITE_ACCESS=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_native_posix.conf b/tests/subsys/fs/fcb/prj_native_posix.conf index 259f73e7719..085117add61 100644 --- a/tests/subsys/fs/fcb/prj_native_posix.conf +++ b/tests/subsys/fs/fcb/prj_native_posix.conf @@ -4,3 +4,4 @@ CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_FCB=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_native_posix_64.conf b/tests/subsys/fs/fcb/prj_native_posix_64.conf index 259f73e7719..085117add61 100644 --- a/tests/subsys/fs/fcb/prj_native_posix_64.conf +++ b/tests/subsys/fs/fcb/prj_native_posix_64.conf @@ -4,3 +4,4 @@ CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_FCB=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf b/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf index 7b589964d62..1ebb84de014 100644 --- a/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf +++ b/tests/subsys/fs/fcb/prj_nucleo_h743zi.conf @@ -9,3 +9,4 @@ CONFIG_FCB=y CONFIG_MAIN_STACK_SIZE=4096 CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/prj_qemu_x86.conf b/tests/subsys/fs/fcb/prj_qemu_x86.conf index 58c6758a75d..e77670a1052 100644 --- a/tests/subsys/fs/fcb/prj_qemu_x86.conf +++ b/tests/subsys/fs/fcb/prj_qemu_x86.conf @@ -5,3 +5,4 @@ CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_FCB=y CONFIG_FLASH_SIMULATOR_UNALIGNED_READ=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fcb/src/fcb_test_append.c b/tests/subsys/fs/fcb/src/fcb_test_append.c index db0c6e0dd49..428e75aa246 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_append.c +++ b/tests/subsys/fs/fcb/src/fcb_test_append.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_append(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_append) { int rc; struct fcb *fcb; diff --git a/tests/subsys/fs/fcb/src/fcb_test_append_fill.c b/tests/subsys/fs/fcb/src/fcb_test_append_fill.c index e1ed96dbcf7..14fb6783f1d 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_append_fill.c +++ b/tests/subsys/fs/fcb/src/fcb_test_append_fill.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_append_fill(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_append_fill) { struct fcb *fcb; int rc; diff --git a/tests/subsys/fs/fcb/src/fcb_test_append_too_big.c b/tests/subsys/fs/fcb/src/fcb_test_append_too_big.c index 73de02aa604..9e8a2f57db6 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_append_too_big.c +++ b/tests/subsys/fs/fcb/src/fcb_test_append_too_big.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void (test_fcb_append_too_big(void)) +ZTEST(fcb_test_with_2sectors_set, test_fcb_append_too_big) { struct fcb *fcb; int rc; diff --git a/tests/subsys/fs/fcb/src/fcb_test_empty_walk.c b/tests/subsys/fs/fcb/src/fcb_test_empty_walk.c index 1040bc475df..95e97347a69 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_empty_walk.c +++ b/tests/subsys/fs/fcb/src/fcb_test_empty_walk.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_empty_walk(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_empty_walk) { int rc; struct fcb *fcb; diff --git a/tests/subsys/fs/fcb/src/fcb_test_init.c b/tests/subsys/fs/fcb/src/fcb_test_init.c index 2a1e613c638..79798663815 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_init.c +++ b/tests/subsys/fs/fcb/src/fcb_test_init.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_init(void) +ZTEST(fcb_test_without_set, test_fcb_init) { int rc; struct fcb *fcb; diff --git a/tests/subsys/fs/fcb/src/fcb_test_last_of_n.c b/tests/subsys/fs/fcb/src/fcb_test_last_of_n.c index 6ac8499bd40..7722584547f 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_last_of_n.c +++ b/tests/subsys/fs/fcb/src/fcb_test_last_of_n.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_last_of_n(void) +ZTEST(fcb_test_with_4sectors_set, test_fcb_last_of_n) { const uint8_t ENTRIES = 5U; struct fcb *fcb; diff --git a/tests/subsys/fs/fcb/src/fcb_test_len.c b/tests/subsys/fs/fcb/src/fcb_test_len.c index ebfdaa9882a..00f551dc561 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_len.c +++ b/tests/subsys/fs/fcb/src/fcb_test_len.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_len(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_len) { uint8_t buf[3]; uint16_t len; diff --git a/tests/subsys/fs/fcb/src/fcb_test_multiple_scratch.c b/tests/subsys/fs/fcb/src/fcb_test_multiple_scratch.c index 2b93a445cee..9c16e9895f4 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_multiple_scratch.c +++ b/tests/subsys/fs/fcb/src/fcb_test_multiple_scratch.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_multi_scratch(void) +ZTEST(fcb_test_with_4sectors_set, test_fcb_multi_scratch) { struct fcb *fcb; int rc; diff --git a/tests/subsys/fs/fcb/src/fcb_test_reset.c b/tests/subsys/fs/fcb/src/fcb_test_reset.c index a8a8613e8f3..aeef2020b42 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_reset.c +++ b/tests/subsys/fs/fcb/src/fcb_test_reset.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_reset(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_reset) { struct fcb *fcb; int rc; diff --git a/tests/subsys/fs/fcb/src/fcb_test_rotate.c b/tests/subsys/fs/fcb/src/fcb_test_rotate.c index 6ee24e35609..67d0cd1804d 100644 --- a/tests/subsys/fs/fcb/src/fcb_test_rotate.c +++ b/tests/subsys/fs/fcb/src/fcb_test_rotate.c @@ -7,7 +7,7 @@ #include "fcb_test.h" -void test_fcb_rotate(void) +ZTEST(fcb_test_with_2sectors_set, test_fcb_rotate) { struct fcb *fcb; int rc; diff --git a/tests/subsys/fs/fcb/src/main.c b/tests/subsys/fs/fcb/src/main.c index 12c595fb075..fb7b8e6ad5f 100644 --- a/tests/subsys/fs/fcb/src/main.c +++ b/tests/subsys/fs/fcb/src/main.c @@ -128,26 +128,22 @@ void fcb_tc_pretest(int sectors) } } -void fcb_pretest_2_sectors(void) +static void fcb_pretest_2_sectors(void *data) { fcb_tc_pretest(2); } -void fcb_pretest_4_sectors(void) +static void fcb_pretest_4_sectors(void *data) { fcb_tc_pretest(4); } -void teardown_nothing(void) -{ -} - /* * This actually is not a test; the function gets erase value from flash * parameters, of the flash device that is used by tests, and stores it in * global fcb_test_erase_value. */ -void test_get_flash_erase_value(void) +ZTEST(fcb_test_without_set, test_get_flash_erase_value) { const struct flash_area *fa; const struct flash_parameters *fp; @@ -168,52 +164,6 @@ void test_get_flash_erase_value(void) fcb_test_erase_value = fp->erase_value; } -void test_fcb_len(void); -void test_fcb_init(void); -void test_fcb_empty_walk(void); -void test_fcb_append(void); -void test_fcb_append_too_big(void); -void test_fcb_append_fill(void); -void test_fcb_reset(void); -void test_fcb_rotate(void); -void test_fcb_multi_scratch(void); -void test_fcb_last_of_n(void); - -void test_main(void) -{ - ztest_test_suite(test_fcb, - ztest_unit_test(test_get_flash_erase_value), - ztest_unit_test_setup_teardown(test_fcb_len, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test(test_fcb_init), - ztest_unit_test_setup_teardown(test_fcb_empty_walk, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_append, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_append_too_big, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_append_fill, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_rotate, - fcb_pretest_2_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_multi_scratch, - fcb_pretest_4_sectors, - teardown_nothing), - ztest_unit_test_setup_teardown(test_fcb_last_of_n, - fcb_pretest_4_sectors, - teardown_nothing), - /* Finally, run one that leaves behind a - * flash.bin file without any random content */ - ztest_unit_test_setup_teardown(test_fcb_reset, - fcb_pretest_2_sectors, - teardown_nothing) - ); - - ztest_run_test_suite(test_fcb); -} +ZTEST_SUITE(fcb_test_without_set, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(fcb_test_with_2sectors_set, NULL, NULL, fcb_pretest_2_sectors, NULL, NULL); +ZTEST_SUITE(fcb_test_with_4sectors_set, NULL, NULL, fcb_pretest_4_sectors, NULL, NULL);