Skip to content

Commit c4dd120

Browse files
de-nordicrghaddab
authored andcommitted
[nrf fromtree] tests/storage/stream_flash: Support for devices without explicit erase
Adds code that runs erase only when needed. Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 27f5291)
1 parent 1ce3591 commit c4dd120

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tests/subsys/storage/stream/stream_flash/src/main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ static uint8_t generic_buf[BUF_LEN];
4141
static uint8_t read_buf[TESTBUF_SIZE];
4242
const static uint8_t write_buf[TESTBUF_SIZE] = {[0 ... TESTBUF_SIZE - 1] = 0xaa};
4343
static uint8_t written_pattern[TESTBUF_SIZE] = {[0 ... TESTBUF_SIZE - 1] = 0xaa};
44+
#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
4445
static uint8_t erased_pattern[TESTBUF_SIZE] = {[0 ... TESTBUF_SIZE - 1] = 0xff};
46+
#endif
4547

4648
#define VERIFY_BUF(start, size, buf) \
4749
do { \
@@ -51,7 +53,11 @@ do { \
5153
} while (0)
5254

5355
#define VERIFY_WRITTEN(start, size) VERIFY_BUF(start, size, written_pattern)
56+
#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
5457
#define VERIFY_ERASED(start, size) VERIFY_BUF(start, size, erased_pattern)
58+
#else
59+
#define VERIFY_ERASED(start, size)
60+
#endif
5561

5662
int stream_flash_callback(uint8_t *buf, size_t len, size_t offset)
5763
{
@@ -66,14 +72,23 @@ int stream_flash_callback(uint8_t *buf, size_t len, size_t offset)
6672

6773
static void erase_flash(void)
6874
{
75+
#if IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
6976
int rc;
77+
#if IS_ENABLED(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
78+
const struct flash_parameters *fparam = flash_get_parameters(fdev);
79+
80+
if (!(flash_params_get_erase_cap(fparam) & FLASH_ERASE_C_EXPLICIT)) {
81+
return;
82+
}
83+
#endif
7084

7185
for (int i = 0; i < MAX_NUM_PAGES; i++) {
7286
rc = flash_erase(fdev,
7387
FLASH_BASE + (i * layout->pages_size),
7488
layout->pages_size);
7589
zassert_equal(rc, 0, "should succeed");
7690
}
91+
#endif
7792
}
7893

7994

@@ -588,7 +603,7 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
588603
bytes_written = load_progress(progress_key);
589604
zassert_equal(bytes_written, bytes_written_old,
590605
"expected bytes_written to be loaded");
591-
#ifdef CONFIG_STREAM_FLASH_ERASE
606+
#if defined(CONFIG_STREAM_FLASH_ERASE)
592607
zassert_equal(erase_offset_old, ctx.last_erased_page_start_offset,
593608
"expected last erased page offset to be loaded");
594609
#endif

tests/subsys/storage/stream/stream_flash/testcase.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ common:
99
tests:
1010
storage.stream_flash:
1111
tags: stream_flash
12+
storage.stream_flash.simulator.no_explicit_erase:
13+
extra_args:
14+
- CONFIG_STREAM_FLASH_ERASE=n
15+
- CONFIG_FLASH_SIMULATOR_EXPLICIT_ERASE=n
16+
platform_allow:
17+
- native_posix
18+
- native_posix/native/64
19+
- native_sim
20+
- native_sim/native/64
21+
tags: stream_flash
22+
storage.stream_flash.no_explicit_erase:
23+
platform_allow:
24+
- nrf54l15pdk/nrf54l15/cpuapp
1225
storage.stream_flash.dword_wbs:
1326
extra_args: DTC_OVERLAY_FILE=unaligned_flush.overlay
1427
tags: stream_flash

0 commit comments

Comments
 (0)