Skip to content

Commit

Permalink
tests/stream_flash: Add testing of erased_up_to.
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Ermel <[email protected]>
  • Loading branch information
de-nordic committed Nov 29, 2024
1 parent 11b3358 commit 64f71f7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions tests/subsys/storage/stream/stream_flash/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ ZTEST(lib_stream_flash, test_stream_flash_erase_page)
fake_dev.api = &fake_api;
bad_ctx.fdev = &fake_dev;
/* Triger erase attempt */
bad_ctx.last_erased_page_start_offset = FLASH_BASE - 16;
bad_ctx.erased_up_to = bad_ctx.available + 16;
cmp_ctx = bad_ctx;

rc = stream_flash_erase_page(&bad_ctx, FLASH_BASE);
Expand All @@ -472,7 +472,7 @@ ZTEST(lib_stream_flash, test_stream_flash_erase_page)
.offset = 1024,
.available = 2048,
.fdev = &fake_dev,
.last_erased_page_start_offset = -1,
.erased_up_to = 0,
};

rc = stream_flash_erase_page(&range_test_ctx, 1024);
Expand Down Expand Up @@ -577,16 +577,15 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
size_t bytes_written_old;
size_t bytes_written;
#ifdef CONFIG_STREAM_FLASH_ERASE
off_t erase_offset_old;
off_t erase_offset;
size_t erased_up_to_old;
#endif

clear_all_progress();
init_target();

bytes_written_old = stream_flash_bytes_written(&ctx);
#ifdef CONFIG_STREAM_FLASH_ERASE
erase_offset_old = ctx.last_erased_page_start_offset;
erased_up_to_old = ctx.erased_up_to;
#endif

/* Test load with zero bytes_written */
Expand All @@ -600,8 +599,7 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
zassert_equal(bytes_written, bytes_written_old,
"expected bytes_written to be unchanged");
#ifdef CONFIG_STREAM_FLASH_ERASE
erase_offset = ctx.last_erased_page_start_offset;
zassert_equal(erase_offset, erase_offset_old,
zassert_equal(ctx.erased_up_to, erased_up_to_old,
"expected erase offset to be unchanged");
#endif

Expand All @@ -612,8 +610,8 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
bytes_written_old = write_and_save_progress(page_size * 2,
progress_key);
#ifdef CONFIG_STREAM_FLASH_ERASE
erase_offset_old = ctx.last_erased_page_start_offset;
zassert_true(erase_offset_old != 0, "expected pages to be erased");
zassert_false(ctx.erased_up_to == 0, "expected pages to be erased");
erased_up_to_old = ctx.erased_up_to;
#endif

init_target();
Expand All @@ -623,7 +621,7 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_resume)
zassert_equal(bytes_written, bytes_written_old,
"expected bytes_written to be loaded");
#if defined(CONFIG_STREAM_FLASH_ERASE)
zassert_equal(erase_offset_old, ctx.last_erased_page_start_offset,
zassert_equal(erased_up_to_old, ctx.erased_up_to,
"expected last erased page offset to be loaded");
#endif

Expand All @@ -644,7 +642,6 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_clear)
size_t bytes_written;
#ifdef CONFIG_STREAM_FLASH_ERASE
off_t erase_offset_old;
off_t erase_offset;
#endif

clear_all_progress();
Expand All @@ -660,7 +657,7 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_clear)

bytes_written_old = stream_flash_bytes_written(&ctx);
#ifdef CONFIG_STREAM_FLASH_ERASE
erase_offset_old = ctx.last_erased_page_start_offset;
erase_offset_old = ctx.erased_up_to;
#endif

rc = stream_flash_progress_load(&ctx, progress_key);
Expand All @@ -671,8 +668,7 @@ ZTEST(lib_stream_flash, test_stream_flash_progress_clear)
"expected bytes_written to be unchanged");

#ifdef CONFIG_STREAM_FLASH_ERASE
erase_offset = ctx.last_erased_page_start_offset;
zassert_equal(erase_offset, erase_offset_old,
zassert_equal(ctx.erased_up_to, erase_offset_old,
"expected erase offset to be unchanged");
#endif
}
Expand Down

0 comments on commit 64f71f7

Please sign in to comment.