tests: settings: Test setting FS back-end using Littlefs
The commit ports settings tests that use NFFS to use Littlefs. GH Issue #18341 Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
94e048559c
commit
0449c672bc
33 changed files with 710 additions and 5 deletions
12
tests/subsys/settings/fs/src/CMakeLists.txt
Normal file
12
tests/subsys/settings/fs/src/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
zephyr_library_named(settings_test_fs)
|
||||
|
||||
# zephyr_library() is here in "app-mode", see
|
||||
# https://github.com/zephyrproject-rtos/zephyr/issues/19582
|
||||
# Random build failures without this, depends on the number of threads.
|
||||
add_dependencies( settings_test_fs offsets_h)
|
||||
|
||||
FILE(GLOB fssources *.c )
|
||||
zephyr_library_sources(${fssources})
|
|
@ -19,8 +19,8 @@ void test_config_empty_file(void)
|
|||
|
||||
config_wipe_srcs();
|
||||
|
||||
cf_mfg.cf_name = TEST_CONFIG_DIR "/mfg";
|
||||
cf_running.cf_name = TEST_CONFIG_DIR "/running";
|
||||
cf_mfg.cf_name = TEST_CONFIG_DIR"/mfg";
|
||||
cf_running.cf_name = TEST_CONFIG_DIR"/running";
|
||||
|
||||
rc = settings_file_src(&cf_mfg);
|
||||
zassert_true(rc == 0, "can't register FS as configuration source");
|
||||
|
@ -36,11 +36,11 @@ void test_config_empty_file(void)
|
|||
rc = fs_mkdir(TEST_CONFIG_DIR);
|
||||
zassert_true(rc == 0, "can't create directory");
|
||||
|
||||
rc = fsutil_write_file(TEST_CONFIG_DIR "/mfg", cf_mfg_test,
|
||||
rc = fsutil_write_file(TEST_CONFIG_DIR"/mfg", cf_mfg_test,
|
||||
0);
|
||||
zassert_true(rc == 0, "can't write to file");
|
||||
|
||||
rc = fsutil_write_file(TEST_CONFIG_DIR "/running", cf_running_test,
|
||||
rc = fsutil_write_file(TEST_CONFIG_DIR"/running", cf_running_test,
|
||||
sizeof(cf_running_test));
|
||||
zassert_true(rc == 0, "can't write to file");
|
||||
|
18
tests/subsys/settings/littlefs/base64/CMakeLists.txt
Normal file
18
tests/subsys/settings/littlefs/base64/CMakeLists.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(littlefs)
|
||||
|
||||
add_subdirectory(../src littlefs_test_bindir)
|
||||
target_link_libraries(app PRIVATE settings_littlefs_test)
|
||||
|
||||
# The code is in the library common to several tests.
|
||||
target_sources(app PRIVATE placeholder.c)
|
||||
|
||||
if(TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&flashcontroller0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&flashcontroller0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPI_NOR=y
|
||||
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&mx25r64 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
2
tests/subsys/settings/littlefs/base64/placeholder.c
Normal file
2
tests/subsys/settings/littlefs/base64/placeholder.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/* Copyright (c) 2019 Nordic Semiconductor ASA */
|
21
tests/subsys/settings/littlefs/base64/prj.conf
Normal file
21
tests/subsys/settings/littlefs/base64/prj.conf
Normal file
|
@ -0,0 +1,21 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_ARM_MPU=n
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=y
|
20
tests/subsys/settings/littlefs/base64/prj_native_posix.conf
Normal file
20
tests/subsys/settings/littlefs/base64/prj_native_posix.conf
Normal file
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=y
|
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=4096
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=y
|
7
tests/subsys/settings/littlefs/base64/testcase.yaml
Normal file
7
tests/subsys/settings/littlefs/base64/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
tests:
|
||||
system.settings.littlefs:
|
||||
platform_whitelist: nrf52840_pca10056 native_posix native_posix_64
|
||||
tags: settings_fs filesystem
|
19
tests/subsys/settings/littlefs/raw/CMakeLists.txt
Normal file
19
tests/subsys/settings/littlefs/raw/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
cmake_minimum_required(VERSION 3.13.1)
|
||||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
||||
project(NONE)
|
||||
|
||||
add_subdirectory(../src littlefs_test_bindir)
|
||||
|
||||
target_link_libraries(app PRIVATE settings_littlefs_test)
|
||||
|
||||
# The code is in the library common to several tests.
|
||||
target_sources(app PRIVATE placeholder.c)
|
||||
|
||||
if(TEST)
|
||||
target_compile_definitions(app PRIVATE
|
||||
-DTEST_${TEST}
|
||||
)
|
||||
endif()
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&flashcontroller0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&flashcontroller0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
};
|
||||
|
||||
&flash0 {
|
||||
reg = <0x00000000 DT_SIZE_K(4096)>;
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
|
@ -0,0 +1,6 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_SPI=y
|
||||
CONFIG_SPI_NOR=y
|
||||
CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&mx25r64 {
|
||||
partitions {
|
||||
compatible = "fixed-partitions";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
|
||||
partition@0 {
|
||||
label = "littlefs_dev";
|
||||
reg = <0x00000000 0x00010000>;
|
||||
};
|
||||
};
|
||||
};
|
5
tests/subsys/settings/littlefs/raw/placeholder.c
Normal file
5
tests/subsys/settings/littlefs/raw/placeholder.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
21
tests/subsys/settings/littlefs/raw/prj.conf
Normal file
21
tests/subsys/settings/littlefs/raw/prj.conf
Normal file
|
@ -0,0 +1,21 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
CONFIG_ARM_MPU=n
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=n
|
20
tests/subsys/settings/littlefs/raw/prj_native_posix.conf
Normal file
20
tests/subsys/settings/littlefs/raw/prj_native_posix.conf
Normal file
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=4096
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=1024
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=n
|
20
tests/subsys/settings/littlefs/raw/prj_native_posix_64.conf
Normal file
20
tests/subsys/settings/littlefs/raw/prj_native_posix_64.conf
Normal file
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_PAGE_LAYOUT=y
|
||||
CONFIG_FLASH_MAP=y
|
||||
|
||||
CONFIG_ZTEST_STACKSIZE=2048
|
||||
CONFIG_MAIN_STACK_SIZE=1024
|
||||
CONFIG_HEAP_MEM_POOL_SIZE=4096
|
||||
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
|
||||
CONFIG_SETTINGS=y
|
||||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FS=y
|
||||
CONFIG_SETTINGS_USE_BASE64=n
|
7
tests/subsys/settings/littlefs/raw/testcase.yaml
Normal file
7
tests/subsys/settings/littlefs/raw/testcase.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
tests:
|
||||
system.settings.littlefs:
|
||||
platform_whitelist: nrf52840_pca10056 native_posix native_posix_64
|
||||
tags: settings_fs settings_littlefs
|
21
tests/subsys/settings/littlefs/src/CMakeLists.txt
Normal file
21
tests/subsys/settings/littlefs/src/CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
|
||||
zephyr_library_named(settings_littlefs_test)
|
||||
|
||||
add_subdirectory(../../src settings_test_bindir)
|
||||
add_subdirectory(../../fs/src settings_test_fs_bindir)
|
||||
|
||||
target_link_libraries(settings_littlefs_test PRIVATE LITTLEFS)
|
||||
target_link_libraries(settings_littlefs_test PRIVATE settings_test)
|
||||
target_link_libraries(settings_littlefs_test PRIVATE settings_test_fs)
|
||||
|
||||
zephyr_include_directories(
|
||||
$ENV{ZEPHYR_BASE}/subsys/settings/include
|
||||
$ENV{ZEPHYR_BASE}/subsys/settings/src
|
||||
$ENV{ZEPHYR_BASE}/tests/subsys/settings/littlefs/src
|
||||
)
|
||||
|
||||
|
||||
FILE(GLOB mysources *.c)
|
||||
zephyr_library_sources(${mysources})
|
34
tests/subsys/settings/littlefs/src/settings_setup_littlefs.c
Normal file
34
tests/subsys/settings/littlefs/src/settings_setup_littlefs.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "settings_test.h"
|
||||
#include <device.h>
|
||||
#include <fs/fs.h>
|
||||
#include <fs/littlefs.h>
|
||||
|
||||
/* NFFS work area strcut */
|
||||
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
|
||||
static struct fs_mount_t littlefs_mnt = {
|
||||
.type = FS_LITTLEFS,
|
||||
.fs_data = &cstorage,
|
||||
.storage_dev = (void *)DT_FLASH_AREA_LITTLEFS_DEV_ID,
|
||||
.mnt_point = TEST_FS_MPTR,
|
||||
};
|
||||
|
||||
void config_setup_littlefs(void)
|
||||
{
|
||||
int rc;
|
||||
const struct flash_area *fap;
|
||||
|
||||
rc = flash_area_open(DT_FLASH_AREA_LITTLEFS_DEV_ID, &fap);
|
||||
zassert_true(rc == 0, "opening flash area for erase [%d]\n", rc);
|
||||
|
||||
flash_area_erase(fap, fap->fa_off, fap->fa_size);
|
||||
zassert_true(rc == 0, "erasing flash area [%d]\n", rc);
|
||||
|
||||
rc = fs_mount(&littlefs_mnt);
|
||||
zassert_true(rc == 0, "mounting littlefs [%d]\n", rc);
|
||||
}
|
53
tests/subsys/settings/littlefs/src/settings_test.h
Normal file
53
tests/subsys/settings/littlefs/src/settings_test.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _SETTINGS_FS_TEST_H
|
||||
#define _SETTINGS_FS_TEST_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ztest.h>
|
||||
#include <fs/fs.h>
|
||||
|
||||
#include "settings/settings.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#extern "C" {
|
||||
#endif
|
||||
|
||||
#define TEST_FS_MPTR "/littlefs"
|
||||
#define TEST_CONFIG_DIR TEST_FS_MPTR""CONFIG_SETTINGS_FS_DIR
|
||||
|
||||
extern u8_t val8;
|
||||
extern u16_t val16;
|
||||
extern u32_t val32;
|
||||
extern u64_t val64;
|
||||
|
||||
extern int test_get_called;
|
||||
extern int test_set_called;
|
||||
extern int test_commit_called;
|
||||
extern int test_export_block;
|
||||
|
||||
extern int c2_var_count;
|
||||
|
||||
extern struct settings_handler c_test_handlers[];
|
||||
|
||||
void ctest_clear_call_state(void);
|
||||
int ctest_get_call_state(void);
|
||||
|
||||
void config_wipe_srcs(void);
|
||||
|
||||
int fsutil_read_file(const char *path, off_t offset, size_t len, void *dst,
|
||||
size_t *out_len);
|
||||
int fsutil_write_file(const char *path, const void *data, size_t len);
|
||||
int settings_test_file_strstr(const char *fname, char const *string,
|
||||
size_t str_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SETTINGS_FS_TEST_H */
|
270
tests/subsys/settings/littlefs/src/settings_test_littlefs.c
Normal file
270
tests/subsys/settings/littlefs/src/settings_test_littlefs.c
Normal file
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "settings_test.h"
|
||||
#include "settings_priv.h"
|
||||
|
||||
|
||||
u8_t val8;
|
||||
u16_t val16;
|
||||
u64_t val64;
|
||||
|
||||
int test_get_called;
|
||||
int test_set_called;
|
||||
int test_commit_called;
|
||||
int test_export_block;
|
||||
|
||||
int c2_var_count = 1;
|
||||
|
||||
int c1_handle_get(const char *name, char *val, int val_len_max);
|
||||
int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
|
||||
void *cb_arg);
|
||||
int c1_handle_commit(void);
|
||||
int c1_handle_export(int (*cb)(const char *name,
|
||||
const void *value, size_t val_len));
|
||||
|
||||
struct settings_handler c_test_handlers[] = {
|
||||
{
|
||||
.name = "myfoo",
|
||||
.h_get = c1_handle_get,
|
||||
.h_set = c1_handle_set,
|
||||
.h_commit = c1_handle_commit,
|
||||
.h_export = c1_handle_export
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
int c1_handle_get(const char *name, char *val, int val_len_max)
|
||||
{
|
||||
test_get_called = 1;
|
||||
const char *next;
|
||||
|
||||
if (settings_name_steq(name, "mybar", &next) && !next) {
|
||||
val_len_max = MIN(val_len_max, sizeof(val8));
|
||||
memcpy(val, &val8, MIN(val_len_max, sizeof(val8)));
|
||||
return val_len_max;
|
||||
}
|
||||
|
||||
if (settings_name_steq(name, "mybar16", &next) && !next) {
|
||||
val_len_max = MIN(val_len_max, sizeof(val16));
|
||||
memcpy(val, &val16, MIN(val_len_max, sizeof(val16)));
|
||||
return val_len_max;
|
||||
}
|
||||
|
||||
if (settings_name_steq(name, "mybar64", &next) && !next) {
|
||||
val_len_max = MIN(val_len_max, sizeof(val64));
|
||||
memcpy(val, &val64, MIN(val_len_max, sizeof(val64)));
|
||||
return val_len_max;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int c1_handle_set(const char *name, size_t len, settings_read_cb read_cb,
|
||||
void *cb_arg)
|
||||
{
|
||||
int rc;
|
||||
const char *next;
|
||||
size_t val_len;
|
||||
|
||||
test_set_called = 1;
|
||||
if (settings_name_steq(name, "mybar", &next) && !next) {
|
||||
val_len = len;
|
||||
zassert_true(val_len == 1, "bad set-value size");
|
||||
|
||||
rc = read_cb(cb_arg, &val8, sizeof(val8));
|
||||
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (settings_name_steq(name, "mybar16", &next) && !next) {
|
||||
val_len = len;
|
||||
zassert_true(val_len == 2, "bad set-value size");
|
||||
|
||||
rc = read_cb(cb_arg, &val16, sizeof(val16));
|
||||
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (settings_name_steq(name, "mybar64", &next) && !next) {
|
||||
val_len = len;
|
||||
zassert_true(val_len == 8, "bad set-value size");
|
||||
|
||||
rc = read_cb(cb_arg, &val64, sizeof(val64));
|
||||
zassert_true(rc >= 0, "SETTINGS_VALUE_SET callback");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int c1_handle_commit(void)
|
||||
{
|
||||
test_commit_called = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int c1_handle_export(int (*cb)(const char *name,
|
||||
const void *value, size_t val_len))
|
||||
{
|
||||
if (test_export_block) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void)cb("myfoo/mybar", &val8, sizeof(val8));
|
||||
|
||||
(void)cb("myfoo/mybar16", &val16, sizeof(val16));
|
||||
|
||||
(void)cb("myfoo/mybar64", &val64, sizeof(val64));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ctest_clear_call_state(void)
|
||||
{
|
||||
test_get_called = 0;
|
||||
test_set_called = 0;
|
||||
test_commit_called = 0;
|
||||
}
|
||||
|
||||
int ctest_get_call_state(void)
|
||||
{
|
||||
return test_get_called + test_set_called + test_commit_called;
|
||||
}
|
||||
|
||||
void config_wipe_srcs(void)
|
||||
{
|
||||
sys_slist_init(&settings_load_srcs);
|
||||
settings_save_dst = NULL;
|
||||
}
|
||||
|
||||
int fsutil_read_file(const char *path, off_t offset, size_t len, void *dst,
|
||||
size_t *out_len)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
ssize_t r_len = 0;
|
||||
|
||||
rc = fs_open(&file, path);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
r_len = fs_read(&file, dst, len);
|
||||
if (r_len < 0) {
|
||||
rc = -EIO;
|
||||
} else {
|
||||
*out_len = r_len;
|
||||
}
|
||||
|
||||
fs_close(&file);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int fsutil_write_file(const char *path, const void *data, size_t len)
|
||||
{
|
||||
struct fs_file_t file;
|
||||
int rc;
|
||||
|
||||
rc = fs_open(&file, path);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (fs_write(&file, data, len) != len) {
|
||||
rc = -EIO;
|
||||
}
|
||||
|
||||
fs_close(&file);
|
||||
return rc;
|
||||
}
|
||||
|
||||
char const *memmem(char const *mem, size_t mem_len, char const *sub,
|
||||
size_t sub_len)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (sub_len <= mem_len && sub_len > 0) {
|
||||
for (i = 0; i <= mem_len - sub_len; i++) {
|
||||
if (!memcmp(&mem[i], sub, sub_len)) {
|
||||
return &mem[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int settings_test_file_strstr(const char *fname, char const *string,
|
||||
size_t str_len)
|
||||
{
|
||||
int rc;
|
||||
u32_t len;
|
||||
size_t rlen;
|
||||
char *buf;
|
||||
struct fs_dirent entry;
|
||||
|
||||
rc = fs_stat(fname, &entry);
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
len = entry.size;
|
||||
buf = (char *)k_malloc(len + 1);
|
||||
zassert_not_null(buf, "out of memory");
|
||||
|
||||
rc = fsutil_read_file(fname, 0, len, buf, &rlen);
|
||||
zassert_true(rc == 0, "can't access the file\n'");
|
||||
zassert_true(rc == 0, "not enough data read\n'");
|
||||
buf[rlen] = '\0';
|
||||
|
||||
if (memmem(buf, len, string, str_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void config_empty_lookups(void);
|
||||
void test_config_insert(void);
|
||||
void test_config_getset_unknown(void);
|
||||
void test_config_getset_int(void);
|
||||
void test_config_getset_int64(void);
|
||||
void test_config_commit(void);
|
||||
|
||||
void config_setup_littlefs(void);
|
||||
void test_config_empty_file(void);
|
||||
void test_config_small_file(void);
|
||||
void test_config_multiple_in_file(void);
|
||||
void test_config_save_in_file(void);
|
||||
void test_config_save_one_file(void);
|
||||
void test_config_compress_file(void);
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(test_config,
|
||||
/* Config tests */
|
||||
ztest_unit_test(config_empty_lookups),
|
||||
ztest_unit_test(test_config_insert),
|
||||
ztest_unit_test(test_config_getset_unknown),
|
||||
ztest_unit_test(test_config_getset_int),
|
||||
ztest_unit_test(test_config_getset_int64),
|
||||
ztest_unit_test(test_config_commit),
|
||||
/* Littlefs as backing storage. */
|
||||
ztest_unit_test(config_setup_littlefs),
|
||||
ztest_unit_test(test_config_empty_file),
|
||||
ztest_unit_test(test_config_small_file),
|
||||
ztest_unit_test(test_config_multiple_in_file),
|
||||
ztest_unit_test(test_config_save_in_file),
|
||||
ztest_unit_test(test_config_save_one_file),
|
||||
ztest_unit_test(test_config_compress_file)
|
||||
);
|
||||
|
||||
ztest_run_test_suite(test_config);
|
||||
}
|
|
@ -5,6 +5,7 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|||
project(NONE)
|
||||
|
||||
add_subdirectory(../src nffs_test_bindir)
|
||||
|
||||
target_link_libraries(app PRIVATE settings_nffs_test)
|
||||
|
||||
# The code is in the library common to several tests.
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
zephyr_library_named(settings_nffs_test)
|
||||
|
||||
add_subdirectory(../../src settings_test_bindir)
|
||||
target_link_libraries(settings_nffs_test PRIVATE settings_test)
|
||||
add_subdirectory(../../fs/src settings_test_fs_bindir)
|
||||
|
||||
target_link_libraries(settings_nffs_test PRIVATE NFFS)
|
||||
target_link_libraries(settings_nffs_test PRIVATE settings_test)
|
||||
target_link_libraries(settings_nffs_test PRIVATE settings_test_fs)
|
||||
|
||||
zephyr_include_directories(
|
||||
$ENV{ZEPHYR_BASE}/subsys/settings/include
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue