Skip to content

Commit 78aaa37

Browse files
committed
tests: subsys: fs: bm_zms: add native_sim board target
* Updates the ztest to include the native_sim board target. * Fixes some configuration bugs in the test suite. * Fixes a bug where `bm_zms_clear` was not waited on until completion. Signed-off-by: Mirko Covizzi <mirko.covizzi@nordicsemi.no>
1 parent 95f4b25 commit 78aaa37

File tree

5 files changed

+97
-48
lines changed

5 files changed

+97
-48
lines changed

samples/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# All these samples shall run without multithreading
1010
config MULTITHREADING
11-
default n if !UNITY
11+
default n if (!UNITY && !(ZTEST && BOARD_NATIVE_SIM))
1212

1313
# Software ISR table is not needed if multithreading is not used
1414
config GEN_SW_ISR_TABLE

subsys/fs/bm_zms/bm_zms.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
LOG_MODULE_REGISTER(bm_zms, CONFIG_BM_ZMS_LOG_LEVEL);
3131

32+
#if CONFIG_ZTEST && NATIVE_SIM
33+
#define __ALIGN(x) __aligned(x)
34+
#endif
35+
3236
static zms_op_t cur_op; /* Current bm_zms operation. */
3337
static zms_op_t *p_cur_op;
3438
static atomic_t cur_op_result = ATOMIC_INIT(0);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_BM_STORAGE_BACKEND_NATIVE_SIM=y
2+
CONFIG_HEAP_MEM_POOL_SIZE=1024

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

Lines changed: 77 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,83 @@
1313
#include <zephyr/sys/crc.h>
1414
#include <zephyr/ztest.h>
1515

16+
#if CONFIG_NATIVE_SIM
17+
#include <zephyr/kernel.h>
18+
#endif
19+
1620
#include <bm/fs/bm_zms.h>
1721
#include <bm_zms_priv.h>
1822

1923
/* Arbitrary block size. */
20-
#define SECTOR_SIZE 1024U
21-
22-
#define STORAGE_NODE DT_NODELABEL(storage_partition)
24+
#define TEST_SECTOR_SIZE 1024U
25+
#define TEST_SECTOR_COUNT 4U
26+
#define TEST_PARTITION_SIZE (TEST_SECTOR_SIZE * TEST_SECTOR_COUNT)
27+
#define TEST_DATA_ID 1
28+
29+
#if CONFIG_NATIVE_SIM
30+
static uint8_t mem[TEST_PARTITION_SIZE];
31+
#define TEST_PARTITION_START ((off_t)mem)
32+
#else
33+
#define STORAGE_NODE DT_NODELABEL(storage_partition)
2334
#define TEST_PARTITION_START DT_REG_ADDR(STORAGE_NODE)
24-
#define TEST_PARTITION_SIZE (SECTOR_SIZE * 4)
25-
#define TEST_DATA_ID 1
26-
#define TEST_SECTOR_COUNT 4U
35+
#endif
2736

2837
struct bm_zms_fixture {
2938
struct bm_zms_fs fs;
3039
struct bm_zms_fs_config config;
3140
};
41+
3242
static bool nvm_is_full;
3343

34-
void bm_zms_test_handler(struct bm_zms_evt const *evt)
44+
static void wait_for_ongoing_writes(struct bm_zms_fs *fs)
45+
{
46+
while (fs->ongoing_writes) {
47+
#if CONFIG_NATIVE_SIM
48+
k_sleep(K_MSEC(100));
49+
#elif CONFIG_SOFTDEVICE
50+
/* Wait for an event. */
51+
__WFE();
52+
53+
/* Clear Event Register */
54+
__SEV();
55+
__WFE();
56+
#endif
57+
}
58+
}
59+
60+
static void wait_for_init(struct bm_zms_fs *fs)
61+
{
62+
while (!fs->init_flags.initialized) {
63+
#if CONFIG_NATIVE_SIM
64+
k_sleep(K_MSEC(100));
65+
#elif CONFIG_SOFTDEVICE
66+
/* Wait for an event. */
67+
__WFE();
68+
69+
/* Clear Event Register */
70+
__SEV();
71+
__WFE();
72+
#endif
73+
}
74+
}
75+
76+
static void wait_for_uninit(struct bm_zms_fs *fs)
77+
{
78+
while (fs->init_flags.initialized) {
79+
#if CONFIG_NATIVE_SIM
80+
k_sleep(K_MSEC(100));
81+
#elif CONFIG_SOFTDEVICE
82+
/* Wait for an event. */
83+
__WFE();
84+
85+
/* Clear Event Register */
86+
__SEV();
87+
__WFE();
88+
#endif
89+
}
90+
}
91+
92+
void bm_zms_test_evt_handler(struct bm_zms_evt const *evt)
3593
{
3694
if (evt->evt_type == BM_ZMS_EVT_MOUNT) {
3795
zassert_true(evt->result == 0, "bm_zms_mount call failure: %d",
@@ -57,9 +115,9 @@ static void *setup(void)
57115

58116
memset(&fixture, 0, sizeof(struct bm_zms_fixture));
59117
fixture.config.offset = TEST_PARTITION_START;
60-
fixture.config.sector_size = SECTOR_SIZE;
118+
fixture.config.sector_size = TEST_SECTOR_SIZE;
61119
fixture.config.sector_count = TEST_SECTOR_COUNT;
62-
fixture.config.evt_handler = bm_zms_test_handler;
120+
fixture.config.evt_handler = bm_zms_test_evt_handler;
63121

64122
return &fixture;
65123
}
@@ -79,37 +137,10 @@ static void after(void *data)
79137

80138
err = bm_zms_clear(&fixture->fs);
81139
zassert_true(err == 0, "zms_clear call failure: %x", err);
140+
wait_for_uninit(&fixture->fs);
82141
}
83142

84-
fixture->fs.sector_count = TEST_SECTOR_COUNT;
85-
}
86-
87-
static void wait_for_ongoing_writes(struct bm_zms_fs *fs)
88-
{
89-
while (fs->ongoing_writes) {
90-
#if defined(CONFIG_SOFTDEVICE)
91-
/* Wait for an event. */
92-
__WFE();
93-
94-
/* Clear Event Register */
95-
__SEV();
96-
__WFE();
97-
#endif
98-
}
99-
}
100-
101-
static void wait_for_init(struct bm_zms_fs *fs)
102-
{
103-
while (!fs->init_flags.initialized) {
104-
#if defined(CONFIG_SOFTDEVICE)
105-
/* Wait for an event. */
106-
__WFE();
107-
108-
/* Clear Event Register */
109-
__SEV();
110-
__WFE();
111-
#endif
112-
}
143+
fixture->config.sector_count = TEST_SECTOR_COUNT;
113144
}
114145

115146
ZTEST_SUITE(bm_zms, NULL, setup, before, after, NULL);
@@ -155,6 +186,8 @@ ZTEST_F(bm_zms, test_bm_zms_write)
155186

156187
err = bm_zms_mount(&fixture->fs, &fixture->config);
157188
zassert_true(err == 0, "zms_mount call failure: %d", err);
189+
wait_for_init(&fixture->fs);
190+
158191
execute_long_pattern_write(TEST_DATA_ID, &fixture->fs);
159192
}
160193

@@ -168,7 +201,7 @@ ZTEST_F(bm_zms, test_zms_gc)
168201
/* 21st write will trigger GC. */
169202
const uint16_t max_writes = 21;
170203

171-
fixture->fs.sector_count = 2;
204+
fixture->config.sector_count = 2;
172205

173206
err = bm_zms_mount(&fixture->fs, &fixture->config);
174207
wait_for_init(&fixture->fs);
@@ -296,6 +329,7 @@ ZTEST_F(bm_zms, test_zms_gc_3sectors)
296329

297330
err = bm_zms_mount(&fixture->fs, &fixture->config);
298331
zassert_true(err == 0, "bm_zms_mount call failure");
332+
wait_for_init(&fixture->fs);
299333

300334
zassert_equal(fixture->fs.ate_wra >> ADDR_SECT_SHIFT, 0, "unexpected write sector");
301335
check_content(max_id, &fixture->fs);
@@ -339,7 +373,7 @@ ZTEST_F(bm_zms, test_zms_full_sector)
339373
uint32_t filling_id = 0;
340374
uint32_t data_read;
341375

342-
fixture->fs.sector_count = 3;
376+
fixture->config.sector_count = 3;
343377

344378
err = bm_zms_mount(&fixture->fs, &fixture->config);
345379
wait_for_init(&fixture->fs);
@@ -392,7 +426,7 @@ ZTEST_F(bm_zms, test_delete)
392426
uint32_t ate_wra;
393427
uint32_t data_wra;
394428

395-
fixture->fs.sector_count = 3;
429+
fixture->config.sector_count = 3;
396430

397431
err = bm_zms_mount(&fixture->fs, &fixture->config);
398432
wait_for_init(&fixture->fs);
@@ -466,7 +500,7 @@ ZTEST_F(bm_zms, test_zms_cache_init)
466500

467501
/* Test cache initialization when the store is empty */
468502

469-
fixture->fs.sector_count = 3;
503+
fixture->config.sector_count = 3;
470504
err = bm_zms_mount(&fixture->fs, &fixture->config);
471505
wait_for_init(&fixture->fs);
472506
zassert_true(err == 0, "bm_zms_mount call failure");
@@ -512,7 +546,7 @@ ZTEST_F(bm_zms, test_zms_cache_collission)
512546
int err;
513547
uint16_t data;
514548

515-
fixture->fs.sector_count = 4;
549+
fixture->config.sector_count = 4;
516550
err = bm_zms_mount(&fixture->fs, &fixture->config);
517551
wait_for_init(&fixture->fs);
518552
zassert_true(err == 0, "bm_zms_mount call failure");
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
common:
22
tags: bm_zms
3-
skip: true
43
platform_allow:
4+
- native_sim
55
- bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
66
- bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
77
- bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
8+
integration_platforms:
9+
- native_sim
810
tests:
911
subsys.bm_zms:
1012
tags: bm_zms
11-
subsys.bm_zms.cache:
13+
subsys.bm_zms.native_sim.cache:
14+
filter: BOARD_NATIVE_SIM
1215
extra_args:
1316
- CONFIG_BM_ZMS_LOOKUP_CACHE=y
1417
- CONFIG_BM_ZMS_LOOKUP_CACHE_SIZE=64
15-
subsys.bm_zms.data_crc:
18+
subsys.bm_zms.native_sim.data_crc:
19+
filter: BOARD_NATIVE_SIM
1620
extra_args:
1721
- CONFIG_BM_ZMS_DATA_CRC=y
18-
subsys.bm_zms.softdevice:
22+
subsys.bm_zms.native_sim.async:
23+
filter: BOARD_NATIVE_SIM
24+
extra_args:
25+
- CONFIG_BM_STORAGE_BACKEND_NATIVE_SIM_ASYNC=y
26+
subsys.bm_zms.bm_nrf54l15dk.softdevice:
27+
filter: not BOARD_NATIVE_SIM
1928
extra_args:
2029
- CONFIG_SOFTDEVICE=y

0 commit comments

Comments
 (0)