Skip to content

Commit da14e2e

Browse files
butokrghaddab
authored andcommitted
[nrf fromtree] tests: zms: allow to build & run on real platforms
- Allows to build and run ZMS tests on real platforms. - Enables ZMS tests designed for a flash-simulator only when built for qemu_x86 or native_sim targets. Signed-off-by: Andrej Butok <[email protected]> (cherry picked from commit b826d46)
1 parent 2d58bae commit da14e2e

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

tests/subsys/fs/zms/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 "ZMS test configuration"
5+
6+
config TEST_ZMS_SIMULATOR
7+
bool "Enable ZMS tests designed to be run using a flash-simulator"
8+
default y if BOARD_QEMU_X86 || ARCH_POSIX
9+
help
10+
If y, enables ZMS 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 or native_sim target.
15+
16+
source "Kconfig.zephyr"

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +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 or native_sim target.
12-
*/
13-
14-
#if !defined(CONFIG_BOARD_QEMU_X86) && !defined(CONFIG_ARCH_POSIX)
15-
#error "Run only on qemu_x86 or a posix architecture based target (for ex. native_sim)"
16-
#endif
17-
187
#include <stdio.h>
198
#include <string.h>
209
#include <zephyr/ztest.h>
@@ -37,8 +26,10 @@ static const struct device *const flash_dev = TEST_ZMS_AREA_DEV;
3726

3827
struct zms_fixture {
3928
struct zms_fs fs;
29+
#ifdef CONFIG_TEST_ZMS_SIMULATOR
4030
struct stats_hdr *sim_stats;
4131
struct stats_hdr *sim_thresholds;
32+
#endif /* CONFIG_TEST_ZMS_SIMULATOR */
4233
};
4334

4435
static void *setup(void)
@@ -66,22 +57,26 @@ static void *setup(void)
6657

6758
static void before(void *data)
6859
{
60+
#ifdef CONFIG_TEST_ZMS_SIMULATOR
6961
struct zms_fixture *fixture = (struct zms_fixture *)data;
7062

7163
fixture->sim_stats = stats_group_find("flash_sim_stats");
7264
fixture->sim_thresholds = stats_group_find("flash_sim_thresholds");
65+
#endif /* CONFIG_TEST_ZMS_SIMULATOR */
7366
}
7467

7568
static void after(void *data)
7669
{
7770
struct zms_fixture *fixture = (struct zms_fixture *)data;
7871

72+
#ifdef CONFIG_TEST_ZMS_SIMULATOR
7973
if (fixture->sim_stats) {
8074
stats_reset(fixture->sim_stats);
8175
}
8276
if (fixture->sim_thresholds) {
8377
stats_reset(fixture->sim_thresholds);
8478
}
79+
#endif /* CONFIG_TEST_ZMS_SIMULATOR */
8580

8681
/* Clear ZMS */
8782
if (fixture->fs.ready) {
@@ -137,6 +132,7 @@ ZTEST_F(zms, test_zms_write)
137132
execute_long_pattern_write(TEST_DATA_ID, &fixture->fs);
138133
}
139134

135+
#ifdef CONFIG_TEST_ZMS_SIMULATOR
140136
static int flash_sim_write_calls_find(struct stats_hdr *hdr, void *arg, const char *name,
141137
uint16_t off)
142138
{
@@ -453,6 +449,7 @@ ZTEST_F(zms, test_zms_corrupted_sector_close_operation)
453449
/* Ensure that the ZMS is able to store new content. */
454450
execute_long_pattern_write(max_id, &fixture->fs);
455451
}
452+
#endif /* CONFIG_TEST_ZMS_SIMULATOR */
456453

457454
/**
458455
* @brief Test case when storage become full, so only deletion is possible.
@@ -562,6 +559,7 @@ ZTEST_F(zms, test_delete)
562559
#endif
563560
}
564561

562+
#ifdef CONFIG_TEST_ZMS_SIMULATOR
565563
/*
566564
* Test that garbage-collection can recover all ate's even when the last ate,
567565
* ie close_ate, is corrupt. In this test the close_ate is set to point to the
@@ -639,6 +637,7 @@ ZTEST_F(zms, test_zms_gc_corrupt_close_ate)
639637
zassert_true(len == sizeof(data), "zms_read should have read %d bytes", sizeof(data));
640638
zassert_true(data == 0xaa55aa55, "unexpected value %d", data);
641639
}
640+
#endif /* CONFIG_TEST_ZMS_SIMULATOR */
642641

643642
/*
644643
* Test that garbage-collection correctly handles corrupt ate's.

0 commit comments

Comments
 (0)