Skip to content

Commit

Permalink
tests/storage/stream_flash: Add erase range check test
Browse files Browse the repository at this point in the history
The commit adds test for stream_flash_erase_page range check.

Signed-off-by: Dominik Ermel <[email protected]>
(cherry picked from commit 2380530)
  • Loading branch information
de-nordic committed Oct 30, 2024
1 parent 72aea10 commit a7c83cf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/subsys/storage/stream/stream_flash/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,25 @@ ZTEST(lib_stream_flash, test_stream_flash_erase_page)
zassert_equal(memcmp(&bad_ctx, &cmp_ctx, sizeof(bad_ctx)), 0,
"Ctx should not get altered");
zassert_equal(rc, -EINVAL, "Expected failure");

/* False dev with erase set to NULL to avoid actual erase */
fake_api.erase = NULL;
struct stream_flash_ctx range_test_ctx = {
.offset = 1024,
.available = 2048,
.fdev = &fake_dev,
.last_erased_page_start_offset = -1,
};

rc = stream_flash_erase_page(&range_test_ctx, 1024);
zassert_equal(rc, -ENOSYS, "%d No device attached - expected failure", rc);

rc = stream_flash_erase_page(&range_test_ctx, 1023);
zassert_equal(rc, -ERANGE, "Expected failure - offset before designated area");

rc = stream_flash_erase_page(&range_test_ctx,
range_test_ctx.offset + range_test_ctx.available + 1);
zassert_equal(rc, -ERANGE, "Expected failure - offset after designated area");
}
#else
ZTEST(lib_stream_flash, test_stream_flash_erase_page)
Expand Down

0 comments on commit a7c83cf

Please sign in to comment.