Skip to content

Commit 172811b

Browse files
butokkartben
authored andcommitted
tests: nvs: allow to build & run on real platforms
- Allows to build and run NVS tests on real platforms. - Enables NVS tests designed for a flash-simulator only when built for qemu_x86, mps2_an385 or native_sim targets. Signed-off-by: Andrej Butok <[email protected]>
1 parent a12f71d commit 172811b

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

tests/subsys/fs/nvs/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "NVS test configuration"
5+
6+
config TEST_NVS_SIMULATOR
7+
bool "Enable NVS tests designed to be run using a flash-simulator"
8+
default y if BOARD_QEMU_X86 || ARCH_POSIX || BOARD_MPS2_AN385
9+
help
10+
If y, enables NVS tests designed to be run using a flash-simulator,
11+
which provide functionality for flash property customization
12+
and emulating errors in flash operation in parallel to
13+
the regular flash API.
14+
The tests must be run only on qemu_x86, mps2_an385, or native_sim target.
15+
16+
source "Kconfig.zephyr"

tests/subsys/fs/nvs/src/main.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
/*
8-
* This test is designed to be run using flash-simulator which provide
9-
* functionality for flash property customization and emulating errors in
10-
* flash operation in parallel to regular flash API.
11-
* Test should be run on qemu_x86, mps2_an385 or native_sim target.
12-
*/
13-
14-
#if !defined(CONFIG_BOARD_QEMU_X86) && !defined(CONFIG_ARCH_POSIX) && \
15-
!defined(CONFIG_BOARD_MPS2_AN385)
16-
#error "Run only on qemu_x86, mps2_an385, or a posix architecture based target (for ex. native_sim)"
17-
#endif
18-
197
#include <stdio.h>
208
#include <string.h>
219
#include <zephyr/ztest.h>
@@ -39,8 +27,10 @@ static const struct device *const flash_dev = TEST_NVS_FLASH_AREA_DEV;
3927

4028
struct nvs_fixture {
4129
struct nvs_fs fs;
30+
#ifdef CONFIG_TEST_NVS_SIMULATOR
4231
struct stats_hdr *sim_stats;
4332
struct stats_hdr *sim_thresholds;
33+
#endif /* CONFIG_TEST_NVS_SIMULATOR */
4434
};
4535

4636
static void *setup(void)
@@ -69,22 +59,26 @@ static void *setup(void)
6959

7060
static void before(void *data)
7161
{
62+
#ifdef CONFIG_TEST_NVS_SIMULATOR
7263
struct nvs_fixture *fixture = (struct nvs_fixture *)data;
7364

7465
fixture->sim_stats = stats_group_find("flash_sim_stats");
7566
fixture->sim_thresholds = stats_group_find("flash_sim_thresholds");
67+
#endif /* CONFIG_TEST_NVS_SIMULATOR */
7668
}
7769

7870
static void after(void *data)
7971
{
8072
struct nvs_fixture *fixture = (struct nvs_fixture *)data;
8173

74+
#ifdef CONFIG_TEST_NVS_SIMULATOR
8275
if (fixture->sim_stats) {
8376
stats_reset(fixture->sim_stats);
8477
}
8578
if (fixture->sim_thresholds) {
8679
stats_reset(fixture->sim_thresholds);
8780
}
81+
#endif /* CONFIG_TEST_NVS_SIMULATOR */
8882

8983
/* Clear NVS */
9084
if (fixture->fs.ready) {
@@ -142,6 +136,7 @@ ZTEST_F(nvs, test_nvs_write)
142136
execute_long_pattern_write(TEST_DATA_ID, &fixture->fs);
143137
}
144138

139+
#ifdef CONFIG_TEST_NVS_SIMULATOR
145140
static int flash_sim_write_calls_find(struct stats_hdr *hdr, void *arg,
146141
const char *name, uint16_t off)
147142
{
@@ -525,6 +520,7 @@ ZTEST_F(nvs, test_nvs_corrupted_sector_close_operation)
525520
/* Ensure that the NVS is able to store new content. */
526521
execute_long_pattern_write(max_id, &fixture->fs);
527522
}
523+
#endif /* CONFIG_TEST_NVS_SIMULATOR */
528524

529525
/**
530526
* @brief Test case when storage become full, so only deletion is possible.
@@ -639,6 +635,7 @@ ZTEST_F(nvs, test_delete)
639635
" any footprint in the storage");
640636
}
641637

638+
#ifdef CONFIG_TEST_NVS_SIMULATOR
642639
/*
643640
* Test that garbage-collection can recover all ate's even when the last ate,
644641
* ie close_ate, is corrupt. In this test the close_ate is set to point to the
@@ -758,6 +755,7 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_ate)
758755
err = nvs_mount(&fixture->fs);
759756
zassert_true(err == 0, "nvs_mount call failure: %d", err);
760757
}
758+
#endif /* CONFIG_TEST_NVS_SIMULATOR */
761759

762760
#ifdef CONFIG_NVS_LOOKUP_CACHE
763761
static size_t num_matching_cache_entries(uint32_t addr, bool compare_sector_only, struct nvs_fs *fs)
@@ -964,6 +962,7 @@ ZTEST_F(nvs, test_nvs_cache_hash_quality)
964962
#endif
965963
}
966964

965+
#ifdef CONFIG_TEST_NVS_SIMULATOR
967966
/*
968967
* Test NVS bad region initialization recovery.
969968
*/
@@ -1000,3 +999,4 @@ ZTEST_F(nvs, test_nvs_init_bad_memory_region)
1000999
zassert_true(err == -EDEADLK, "nvs_mount call ok, expect fail: %d", err);
10011000
#endif
10021001
}
1002+
#endif /* CONFIG_TEST_NVS_SIMULATOR */

0 commit comments

Comments
 (0)