tests/subsys/fs: Add fs_open flags tests to LittleFS
The addition of support for open flags, within fs_open, requires addition of new test cases. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
50aca03eef
commit
f2f4ba7452
5 changed files with 103 additions and 2 deletions
|
@ -157,17 +157,25 @@ void test_fs_open_flags(void)
|
|||
* operations on it.
|
||||
*/
|
||||
ZBEGIN("Attempt create new with no R/W access");
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZOPEN(&ts, FS_O_CREATE | 0, 0);
|
||||
ZWRITE(&ts, -EACCES);
|
||||
ZREAD(&ts, -EACCES);
|
||||
ZCLOSE(&ts);
|
||||
ZUNLINK(&ts);
|
||||
#else
|
||||
TC_PRINT("Bypassed test\n");
|
||||
#endif
|
||||
ZEND();
|
||||
|
||||
|
||||
ZBEGIN("Attempt create new with READ access");
|
||||
ZOPEN(&ts, FS_O_CREATE | FS_O_READ, 0);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZWRITE(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Write bypassed\n");
|
||||
#endif
|
||||
ZREAD(&ts, 0);
|
||||
ZCLOSE(&ts);
|
||||
ZUNLINK(&ts);
|
||||
|
@ -177,7 +185,11 @@ void test_fs_open_flags(void)
|
|||
ZBEGIN("Attempt create new with WRITE access");
|
||||
ZOPEN(&ts, FS_O_CREATE | FS_O_WRITE, 0);
|
||||
ZWRITE(&ts, ts.write_size);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZREAD(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Read bypassed\n");
|
||||
#endif
|
||||
ZCLOSE(&ts);
|
||||
ZUNLINK(&ts);
|
||||
ZEND();
|
||||
|
@ -195,10 +207,14 @@ void test_fs_open_flags(void)
|
|||
|
||||
ZBEGIN("Attempt open existing with no R/W access");
|
||||
ZMKEMPTY(&ts);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_RW_IS_DEFAULT
|
||||
ZOPEN(&ts, 0, 0);
|
||||
ZWRITE(&ts, -EACCES);
|
||||
ZREAD(&ts, -EACCES);
|
||||
ZCLOSE(&ts);
|
||||
#else
|
||||
TC_PRINT("Bypassed test\n");
|
||||
#endif
|
||||
ZUNLINK(&ts);
|
||||
ZEND();
|
||||
|
||||
|
@ -206,7 +222,11 @@ void test_fs_open_flags(void)
|
|||
ZBEGIN("Attempt open existing with READ access");
|
||||
ZMKEMPTY(&ts);
|
||||
ZOPEN(&ts, FS_O_READ, 0);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZWRITE(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Write bypassed\n");
|
||||
#endif
|
||||
/* File is empty */
|
||||
ZREAD(&ts, 0);
|
||||
ZCLOSE(&ts);
|
||||
|
@ -219,7 +239,11 @@ void test_fs_open_flags(void)
|
|||
ZOPEN(&ts, FS_O_WRITE, 0);
|
||||
ZCHKPOS(&ts, 0);
|
||||
ZWRITE(&ts, ts.write_size);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZREAD(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Read bypassed\n");
|
||||
#endif
|
||||
ZCLOSE(&ts);
|
||||
ZUNLINK(&ts);
|
||||
ZEND();
|
||||
|
@ -238,11 +262,15 @@ void test_fs_open_flags(void)
|
|||
|
||||
ZBEGIN("Attempt append existing with no R/W access");
|
||||
ZMKEMPTY(&ts);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_RW_IS_DEFAULT
|
||||
ZOPEN(&ts, FS_O_APPEND, 0);
|
||||
ZCHKPOS(&ts, 0);
|
||||
ZWRITE(&ts, -EACCES);
|
||||
ZREAD(&ts, -EACCES);
|
||||
ZCLOSE(&ts);
|
||||
#else
|
||||
TC_PRINT("Test bypassed\n");
|
||||
#endif
|
||||
ZUNLINK(&ts);
|
||||
ZEND();
|
||||
|
||||
|
@ -251,7 +279,11 @@ void test_fs_open_flags(void)
|
|||
ZMKEMPTY(&ts);
|
||||
ZOPEN(&ts, FS_O_APPEND | FS_O_READ, 0);
|
||||
ZCHKPOS(&ts, 0);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZWRITE(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Write bypassed\n");
|
||||
#endif
|
||||
/* File is empty */
|
||||
ZREAD(&ts, 0);
|
||||
ZCLOSE(&ts);
|
||||
|
@ -264,7 +296,11 @@ void test_fs_open_flags(void)
|
|||
ZOPEN(&ts, FS_O_APPEND | FS_O_WRITE, 0);
|
||||
ZCHKPOS(&ts, 0);
|
||||
ZWRITE(&ts, ts.write_size);
|
||||
#ifndef BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
ZREAD(&ts, -EACCES);
|
||||
#else
|
||||
TC_PRINT("Read bypassed\n");
|
||||
#endif
|
||||
ZCLOSE(&ts);
|
||||
ZUNLINK(&ts);
|
||||
ZEND();
|
||||
|
|
|
@ -5,4 +5,11 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|||
project(littlefs)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
||||
# LittleFS opens files for RW by default if no flags given and crashes,
|
||||
# instead of returning error when attempting to perform operation that
|
||||
# a file has not been opened for.
|
||||
target_compile_definitions(app PRIVATE
|
||||
BYPASS_FS_OPEN_FLAGS_LFS_ASSERT_CRASH
|
||||
BYPASS_FS_OPEN_FLAGS_LFS_RW_IS_DEFAULT
|
||||
)
|
||||
target_sources(app PRIVATE ${app_sources} ../common/test_fs_open_flags.c)
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <string.h>
|
||||
#include <ztest.h>
|
||||
#include "testfs_tests.h"
|
||||
#include "testfs_lfs.h"
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
|
@ -21,7 +22,8 @@ void test_main(void)
|
|||
ztest_unit_test(test_util_path_extend_overrun),
|
||||
ztest_unit_test(test_lfs_basic),
|
||||
ztest_unit_test(test_lfs_dirops),
|
||||
ztest_unit_test(test_lfs_perf)
|
||||
ztest_unit_test(test_lfs_perf),
|
||||
ztest_unit_test(test_fs_open_flags_lfs)
|
||||
);
|
||||
ztest_run_test_suite(littlefs_test);
|
||||
}
|
||||
|
|
53
tests/subsys/fs/littlefs/src/testfs_open_flags.c
Normal file
53
tests/subsys/fs/littlefs/src/testfs_open_flags.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2020 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <fs/littlefs.h>
|
||||
#include "testfs_tests.h"
|
||||
#include "testfs_lfs.h"
|
||||
|
||||
void test_fs_open_flags(void);
|
||||
/* Expected by test_fs_open_flags() */
|
||||
const char *test_fs_open_flags_file_path = TESTFS_MNT_POINT_SMALL"/the_file";
|
||||
|
||||
static void mount(struct fs_mount_t *mp)
|
||||
{
|
||||
TC_PRINT("Mount %s\n", mp->mnt_point);
|
||||
|
||||
zassert_equal(fs_mount(mp), 0, "Failed to mount partition");
|
||||
}
|
||||
|
||||
static void unmount(struct fs_mount_t *mp)
|
||||
{
|
||||
TC_PRINT("Unmounting %s\n", mp->mnt_point);
|
||||
|
||||
zassert_equal(fs_unmount(mp), 0,
|
||||
"Failed to unmount partition");
|
||||
}
|
||||
|
||||
static void cleanup(struct fs_mount_t *mp)
|
||||
{
|
||||
TC_PRINT("Clean %s\n", mp->mnt_point);
|
||||
|
||||
zassert_equal(testfs_lfs_wipe_partition(mp), TC_PASS,
|
||||
"Failed to clean partition");
|
||||
}
|
||||
|
||||
void test_fs_open_flags_lfs(void)
|
||||
{
|
||||
/* Using smallest partition for this tests as they do not write
|
||||
* a lot of data, basically they just check flags.
|
||||
*/
|
||||
struct fs_mount_t *mp = &testfs_small_mnt;
|
||||
|
||||
cleanup(mp);
|
||||
mount(mp);
|
||||
|
||||
test_fs_open_flags();
|
||||
|
||||
unmount(mp);
|
||||
|
||||
}
|
|
@ -24,4 +24,7 @@ void test_lfs_dirops(void);
|
|||
/* Tests in test_lfs_perf */
|
||||
void test_lfs_perf(void);
|
||||
|
||||
/* Test fs_open flags */
|
||||
void test_fs_open_flags_lfs(void);
|
||||
|
||||
#endif /* _ZEPHYR_TESTS_SUBSYS_FS_LITTLEFS_TESTFS_TESTS_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue