diff --git a/tests/subsys/fs/fs_api/prj.conf b/tests/subsys/fs/fs_api/prj.conf index 47eb9e2362c5..d5feeed8bffa 100644 --- a/tests/subsys/fs/fs_api/prj.conf +++ b/tests/subsys/fs/fs_api/prj.conf @@ -1,2 +1,3 @@ CONFIG_FILE_SYSTEM=y CONFIG_ZTEST=y +CONFIG_ZTEST_NEW_API=y diff --git a/tests/subsys/fs/fs_api/src/main.c b/tests/subsys/fs/fs_api/src/main.c deleted file mode 100644 index 0e768fac694d..000000000000 --- a/tests/subsys/fs/fs_api/src/main.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "test_fs.h" - -/** - * @brief Test file system interface implemented in kernel - * - * @defgroup filesystem File System - * - * @ingroup all_test - * @{ - * @} - */ - -static void fs_setup(void) -{ - fs_register(TEST_FS_1, &temp_fs); -} - -static void dummy_teardown(void) -{ - return; -} - -static void dummy_setup(void) -{ - return; -} - -static void fs_teardown(void) -{ - fs_unregister(TEST_FS_1, &temp_fs); -} - -/** - * @brief Common file system operations through a general interface - * - * @details After register file system: - * - mount - * - statvfs - * - mkdir - * - opendir - * - readdir - * - closedir - * - open - * - write - * - read - * - lseek - * - tell - * - truncate - * - sync - * - close - * - rename - * - stat - * - unlink - * - unmount - * - unregister file system - * the order of test cases is critical, one case depend on the - * case before it. - * - * @ingroup filesystem - * - */ -void test_main(void) -{ - ztest_test_suite(fat_fs_basic_test, - ztest_unit_test(test_fs_register), - ztest_unit_test_setup_teardown(test_mount, - fs_setup, - dummy_teardown), - ztest_unit_test(test_fs_file_t_init), - ztest_unit_test(test_fs_dir_t_init), - ztest_unit_test(test_file_statvfs), - ztest_unit_test(test_mkdir), - ztest_unit_test(test_opendir), - ztest_unit_test(test_closedir), - ztest_unit_test(test_opendir_closedir), - ztest_unit_test(test_lsdir), - ztest_unit_test(test_file_open), - ztest_unit_test(test_file_write), - ztest_unit_test(test_file_read), - ztest_unit_test(test_file_seek), - ztest_unit_test(test_file_truncate), - ztest_unit_test(test_file_close), - ztest_unit_test(test_file_sync), - ztest_unit_test(test_file_rename), - ztest_unit_test(test_file_stat), - ztest_unit_test(test_file_unlink), - ztest_unit_test(test_unmount), - ztest_unit_test_setup_teardown(test_mount_flags, - dummy_setup, - fs_teardown) - ); - ztest_run_test_suite(fat_fs_basic_test); -} diff --git a/tests/subsys/fs/fs_api/src/test_fs.h b/tests/subsys/fs/fs_api/src/test_fs.h index 235e224abcd1..2b1ab08a6fff 100644 --- a/tests/subsys/fs/fs_api/src/test_fs.h +++ b/tests/subsys/fs/fs_api/src/test_fs.h @@ -33,27 +33,4 @@ struct test_fs_data { }; void mock_opendir_result(int ret); - -void test_opendir_closedir(void); -void test_fs_dir_t_init(void); -void test_fs_file_t_init(void); -void test_fs_register(void); -void test_mount(void); -void test_file_statvfs(void); -void test_mkdir(void); -void test_opendir(void); -void test_closedir(void); -void test_lsdir(void); -void test_file_open(void); -void test_file_write(void); -void test_file_read(void); -void test_file_seek(void); -void test_file_truncate(void); -void test_file_close(void); -void test_file_sync(void); -void test_file_rename(void); -void test_file_stat(void); -void test_file_unlink(void); -void test_unmount(void); -void test_mount_flags(void); #endif diff --git a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c index f08daa13f6b4..0b7798b6e707 100644 --- a/tests/subsys/fs/fs_api/src/test_fs_dir_file.c +++ b/tests/subsys/fs/fs_api/src/test_fs_dir_file.c @@ -81,7 +81,7 @@ static const char test_str[] = "hello world!"; /** * @brief Test fs_file_t_init initializer */ -void test_fs_file_t_init(void) +ZTEST(fs_api_dir_file, test_fs_file_t_init) { struct fs_file_t fst; @@ -96,7 +96,7 @@ void test_fs_file_t_init(void) /** * @brief Test fs_dir_t_init initializer */ -void test_fs_dir_t_init(void) +ZTEST(fs_api_dir_file, test_fs_dir_t_init) { struct fs_dir_t dirp; @@ -149,6 +149,7 @@ void test_mount(void) zassert_not_equal(ret, 0, "Mount to a mounted dir"); fs_unregister(TEST_FS_2, &temp_fs); + memset(&null_fs, 0, sizeof(null_fs)); fs_register(TEST_FS_2, &null_fs); TC_PRINT("Mount a file system has no interface implemented\n"); @@ -191,6 +192,10 @@ void test_unmount(void) TC_PRINT("unmount a file system has no unmount functionality\n"); ret = fs_unmount(&test_fs_mnt_no_op); zassert_not_equal(ret, 0, "Unmount a fs has no unmount functionality"); + /* assign a unmount interface to null_fs to unmount it */ + null_fs.unmount = temp_fs.unmount; + ret = fs_unmount(&test_fs_mnt_no_op); + zassert_equal(ret, 0, "file system should be unmounted"); /* TEST_FS_2 is registered in test_mount(), unregister it here */ fs_unregister(TEST_FS_2, &null_fs); } @@ -200,7 +205,7 @@ void test_unmount(void) * * @ingroup filesystem_api */ -void test_file_statvfs(void) +ZTEST(fs_api_dir_file, test_file_statvfs) { struct fs_statvfs stat; int ret; @@ -640,7 +645,7 @@ static int _test_file_sync(void) * * @ingroup filesystem_api */ -void test_file_sync(void) +ZTEST(fs_api_dir_file, test_file_sync) { zassert_true(_test_file_sync() == TC_PASS, NULL); } @@ -910,7 +915,7 @@ void test_file_close(void) * * @ingroup filesystem_api */ -void test_file_rename(void) +ZTEST(fs_api_dir_file, test_file_rename) { int ret = TC_FAIL; @@ -955,7 +960,7 @@ void test_file_rename(void) * * @ingroup filesystem_api */ -void test_file_stat(void) +ZTEST(fs_api_dir_file, test_file_stat) { int ret; struct fs_dirent entry; @@ -992,7 +997,7 @@ void test_file_stat(void) * * @ingroup filesystem_api */ -void test_file_unlink(void) +ZTEST(fs_api_dir_file, test_file_unlink) { int ret; @@ -1031,3 +1036,53 @@ void test_file_unlink(void) TC_PRINT("File (%s) deleted successfully!\n", TEST_FILE_RN); } + +static void *fs_api_setup(void) +{ + fs_register(TEST_FS_1, &temp_fs); + fs_mount(&test_fs_mnt_1); + memset(&null_fs, 0, sizeof(null_fs)); + null_fs.mount = temp_fs.mount; + null_fs.unmount = temp_fs.unmount; + fs_register(TEST_FS_2, &null_fs); + fs_mount(&test_fs_mnt_no_op); + return NULL; +} + +static void fs_api_teardown(void *fixtrue) +{ + fs_unmount(&test_fs_mnt_no_op); + fs_unregister(TEST_FS_2, &null_fs); + fs_unmount(&test_fs_mnt_1); + fs_unregister(TEST_FS_1, &temp_fs); +} + +ZTEST(fs_api_dir_file, test_fs_dir) +{ + test_mkdir(); + test_opendir(); + test_closedir(); + test_opendir_closedir(); + test_lsdir(); +} + +ZTEST(fs_api_dir_file, test_file_ops) +{ + test_file_open(); + test_file_write(); + test_file_read(); + test_file_seek(); + test_file_truncate(); + test_file_close(); +} + +ZTEST(fs_api_register_mount, test_mount_unmount) +{ + fs_register(TEST_FS_1, &temp_fs); + test_mount(); + test_unmount(); + fs_unregister(TEST_FS_1, &temp_fs); +} + +ZTEST_SUITE(fs_api_register_mount, NULL, NULL, NULL, NULL, NULL); +ZTEST_SUITE(fs_api_dir_file, NULL, fs_api_setup, NULL, NULL, fs_api_teardown); diff --git a/tests/subsys/fs/fs_api/src/test_multi_fs.c b/tests/subsys/fs/fs_api/src/test_multi_fs.c index 8c7594c707db..a0a72b36e60a 100644 --- a/tests/subsys/fs/fs_api/src/test_multi_fs.c +++ b/tests/subsys/fs/fs_api/src/test_multi_fs.c @@ -123,7 +123,7 @@ static int test_fs_external(void) *@{ */ -void test_fs_register(void) +ZTEST(fs_api_register_mount, test_fs_register) { zassert_true(test_fs_init() == 0, "Failed to register filesystems"); zassert_true(test_fs_readmount() == 0, "Failed to readmount");