Skip to content

Commit 1c788ba

Browse files
maass-hamburgkartben
authored andcommitted
tests: storage: flash_map: add test for flash_area_copy()
add test for flash_area_copy(). Signed-off-by: Fin Maaß <[email protected]>
1 parent ddefc42 commit 1c788ba

File tree

1 file changed

+33
-0
lines changed
  • tests/subsys/storage/flash_map/src

1 file changed

+33
-0
lines changed

tests/subsys/storage/flash_map/src/main.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION)
1717
#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION)
1818
#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION)
19+
#define SLOT1_PARTITION_SIZE FIXED_PARTITION_SIZE(SLOT1_PARTITION)
20+
21+
#define FLASH_AREA_COPY_SIZE MIN((SLOT1_PARTITION_SIZE / 2), 128)
1922

2023
extern int flash_map_entries;
2124
struct flash_sector fs_sectors[2048];
@@ -223,4 +226,34 @@ ZTEST(flash_map, test_flash_area_erase_and_flatten)
223226
i + fa->fa_off);
224227
}
225228

229+
ZTEST(flash_map, test_flash_area_copy)
230+
{
231+
const struct flash_area *fa;
232+
uint8_t src_buf[FLASH_AREA_COPY_SIZE], dst_buf[FLASH_AREA_COPY_SIZE],
233+
copy_buf[32];
234+
int rc;
235+
236+
/* Get source and destination flash areas */
237+
fa = FIXED_PARTITION(SLOT1_PARTITION);
238+
239+
/* First erase the area so it's ready for use. */
240+
rc = flash_area_erase(fa, 0, fa->fa_size);
241+
zassert_true(rc == 0, "flash area erase fail");
242+
243+
/* Fill source area with test data */
244+
memset(src_buf, 0xAB, sizeof(src_buf));
245+
rc = flash_area_write(fa, 0, src_buf, sizeof(src_buf));
246+
zassert_true(rc == 0, "Failed to write to source flash area");
247+
248+
/* Perform the copy operation */
249+
rc = flash_area_copy(fa, 0, fa, FLASH_AREA_COPY_SIZE, sizeof(src_buf), copy_buf,
250+
sizeof(copy_buf));
251+
zassert_true(rc == 0, "flash_area_copy failed");
252+
253+
/* Verify the copied data */
254+
rc = flash_area_read(fa, FLASH_AREA_COPY_SIZE, dst_buf, sizeof(dst_buf));
255+
zassert_true(rc == 0, "Failed to read from destination flash area");
256+
zassert_mem_equal(src_buf, dst_buf, sizeof(src_buf), "Data mismatch after copy");
257+
}
258+
226259
ZTEST_SUITE(flash_map, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)