From fb94343ce45d1324189fbf2ff0fffc52e4a9a525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 26 May 2025 10:50:50 +0200 Subject: [PATCH] tests: drivers: flash: common: Fix page size when no erase is required MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no flash device requires erase, this test does not retrieve flash page size with flash_get_page_info_by_offs(), but instead it takes an arbitrary page size based on the test area length. Since the test_flash_copy routine needs to use two pages, the test area needs to be split into at least two parts. Correct the related code and add a check if test_flash_copy requirements are met. Signed-off-by: Andrzej Głąbek --- tests/drivers/flash/common/src/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/drivers/flash/common/src/main.c b/tests/drivers/flash/common/src/main.c index 03b3c08a6cf..ab0e63bb609 100644 --- a/tests/drivers/flash/common/src/main.c +++ b/tests/drivers/flash/common/src/main.c @@ -87,7 +87,8 @@ static void flash_driver_before(void *arg) TC_PRINT("No devices with erase requirement present\n"); erase_value = 0x55; page_info.start_offset = TEST_AREA_OFFSET; - page_info.size = TEST_AREA_MAX - TEST_AREA_OFFSET; + /* test_flash_copy uses 2 pages, so split the test area */ + page_info.size = (TEST_AREA_MAX - TEST_AREA_OFFSET) / 2; } @@ -111,6 +112,10 @@ static void flash_driver_before(void *arg) zassert_true((TEST_AREA_OFFSET + EXPECTED_SIZE) <= TEST_AREA_MAX, "Test area exceeds flash size"); + /* Check if test region is suitable for test_flash_copy */ + zassert_true((TEST_AREA_OFFSET + 2 * page_info.size) <= TEST_AREA_MAX, + "test_flash_copy needs 2 flash pages"); + /* Check if flash is cleared */ if (IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && ebw_required) { bool is_buf_clear = true;