From 201a0b6ba94cfdd18d68ea93c76e76257928f64a Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Thu, 14 Nov 2024 17:58:55 +0100 Subject: [PATCH] test: drivers: flash: common: Copied size can't exceed page.size flash_copy() is performed on a page.size span but following flash_read() verification step is performed on EXPECTED_SIZE length (512). This doesn't work on devices where page.size is lower than EXPECTED_SIZE, such as STM32L1 where page size is 256. To fix this, perform verification on the smalest value between page.size and EXPECTED_SIZE. Signed-off-by: Erwan Gouriou --- tests/drivers/flash/common/src/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/drivers/flash/common/src/main.c b/tests/drivers/flash/common/src/main.c index f7f7c6ee64e..a30f533f655 100644 --- a/tests/drivers/flash/common/src/main.c +++ b/tests/drivers/flash/common/src/main.c @@ -397,8 +397,10 @@ static void test_flash_copy_inner(const struct device *src_dev, off_t src_offset if ((expected_result == 0) && (size != 0) && (src_offset != dst_offset)) { /* verify a successful copy */ - zassert_ok(flash_read(flash_dev, TEST_AREA_OFFSET, expected, EXPECTED_SIZE)); - for (int i = 0; i < EXPECTED_SIZE; i++) { + off_t copy_size = MIN(size, EXPECTED_SIZE); + + zassert_ok(flash_read(flash_dev, TEST_AREA_OFFSET, expected, copy_size)); + for (int i = 0; i < copy_size; i++) { zassert_equal(buf[i], 0xaa, "incorrect data (%02x) at %d", buf[i], i); } }