Skip to content

Commit a0219be

Browse files
committed
tests/drivers/flash/common: Add support for testing flash_mmap
Add flash_mmap test scenario. Signed-off-by: Dominik Ermel <[email protected]>
1 parent 1569d20 commit a0219be

File tree

1 file changed

+19
-0
lines changed
  • tests/drivers/flash/common/src

1 file changed

+19
-0
lines changed

tests/drivers/flash/common/src/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,25 @@ ZTEST(flash_driver, test_flash_erase)
307307
zassert_not_equal(expected[0], erase_value, "These values shall be different");
308308
}
309309

310+
ZTEST(flash_driver, test_mmap)
311+
{
312+
int rc;
313+
uint64_t size;
314+
uint8_t *p;
315+
316+
rc = flash_mmap(flash_dev, (void **)&p, &size, FLASH_MMAP_F_READ);
317+
if (rc == -ENOTSUP || rc == -ENOSYS) {
318+
ztest_test_skip();
319+
} else {
320+
const static uint8_t out[] = "Hello World!!!\n";
321+
struct flash_pages_info fp;
322+
323+
zassert_ok(flash_get_page_info_by_offs(flash_dev, size - 1, &fp));
324+
zassert_ok(flash_erase(flash_dev, fp.start_offset, fp.size));
325+
zassert_ok(flash_write(flash_dev, fp.start_offset, out, sizeof(out)));
326+
zassert_ok(memcmp(p + fp.start_offset, out, sizeof(out)));
327+
}
328+
}
310329
struct test_cb_data_type {
311330
uint32_t page_counter; /* used to count how many pages was iterated */
312331
uint32_t exit_page; /* terminate iteration when this page is reached */

0 commit comments

Comments
 (0)