Skip to content

Commit

Permalink
tests: fs_api: move to new ztest API
Browse files Browse the repository at this point in the history
all test cases in tests/subsys/fs/fs_api are moved to new ztest API

Signed-off-by: Meng xianglin <[email protected]>
  • Loading branch information
mengxianglinx authored and carlescufi committed Sep 6, 2022
1 parent 6b760b3 commit 26f0a4f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 130 deletions.
1 change: 1 addition & 0 deletions tests/subsys/fs/fs_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
CONFIG_FILE_SYSTEM=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
99 changes: 0 additions & 99 deletions tests/subsys/fs/fs_api/src/main.c

This file was deleted.

23 changes: 0 additions & 23 deletions tests/subsys/fs/fs_api/src/test_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
69 changes: 62 additions & 7 deletions tests/subsys/fs/fs_api/src/test_fs_dir_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
2 changes: 1 addition & 1 deletion tests/subsys/fs/fs_api/src/test_multi_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 26f0a4f

Please sign in to comment.