4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
6
6
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
-
19
7
#include <stdio.h>
20
8
#include <string.h>
21
9
#include <zephyr/ztest.h>
@@ -39,8 +27,10 @@ static const struct device *const flash_dev = TEST_NVS_FLASH_AREA_DEV;
39
27
40
28
struct nvs_fixture {
41
29
struct nvs_fs fs ;
30
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
42
31
struct stats_hdr * sim_stats ;
43
32
struct stats_hdr * sim_thresholds ;
33
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
44
34
};
45
35
46
36
static void * setup (void )
@@ -69,22 +59,26 @@ static void *setup(void)
69
59
70
60
static void before (void * data )
71
61
{
62
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
72
63
struct nvs_fixture * fixture = (struct nvs_fixture * )data ;
73
64
74
65
fixture -> sim_stats = stats_group_find ("flash_sim_stats" );
75
66
fixture -> sim_thresholds = stats_group_find ("flash_sim_thresholds" );
67
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
76
68
}
77
69
78
70
static void after (void * data )
79
71
{
80
72
struct nvs_fixture * fixture = (struct nvs_fixture * )data ;
81
73
74
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
82
75
if (fixture -> sim_stats ) {
83
76
stats_reset (fixture -> sim_stats );
84
77
}
85
78
if (fixture -> sim_thresholds ) {
86
79
stats_reset (fixture -> sim_thresholds );
87
80
}
81
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
88
82
89
83
/* Clear NVS */
90
84
if (fixture -> fs .ready ) {
@@ -142,6 +136,7 @@ ZTEST_F(nvs, test_nvs_write)
142
136
execute_long_pattern_write (TEST_DATA_ID , & fixture -> fs );
143
137
}
144
138
139
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
145
140
static int flash_sim_write_calls_find (struct stats_hdr * hdr , void * arg ,
146
141
const char * name , uint16_t off )
147
142
{
@@ -525,6 +520,7 @@ ZTEST_F(nvs, test_nvs_corrupted_sector_close_operation)
525
520
/* Ensure that the NVS is able to store new content. */
526
521
execute_long_pattern_write (max_id , & fixture -> fs );
527
522
}
523
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
528
524
529
525
/**
530
526
* @brief Test case when storage become full, so only deletion is possible.
@@ -639,6 +635,7 @@ ZTEST_F(nvs, test_delete)
639
635
" any footprint in the storage" );
640
636
}
641
637
638
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
642
639
/*
643
640
* Test that garbage-collection can recover all ate's even when the last ate,
644
641
* 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)
758
755
err = nvs_mount (& fixture -> fs );
759
756
zassert_true (err == 0 , "nvs_mount call failure: %d" , err );
760
757
}
758
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
761
759
762
760
#ifdef CONFIG_NVS_LOOKUP_CACHE
763
761
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)
964
962
#endif
965
963
}
966
964
965
+ #ifdef CONFIG_TEST_NVS_SIMULATOR
967
966
/*
968
967
* Test NVS bad region initialization recovery.
969
968
*/
@@ -1000,3 +999,4 @@ ZTEST_F(nvs, test_nvs_init_bad_memory_region)
1000
999
zassert_true (err == - EDEADLK , "nvs_mount call ok, expect fail: %d" , err );
1001
1000
#endif
1002
1001
}
1002
+ #endif /* CONFIG_TEST_NVS_SIMULATOR */
0 commit comments