From 56481263ce069ec1b808711d09ea6c5d03fc9eb3 Mon Sep 17 00:00:00 2001 From: Piotr Kosycarz Date: Fri, 10 Jan 2025 11:16:59 +0100 Subject: [PATCH] tests: benchmarks: power_consumption: flash: extend test with writes Add erase and write operation. Validate read values. Signed-off-by: Piotr Kosycarz --- .../power_consumption/flash/src/driver_test.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/benchmarks/power_consumption/flash/src/driver_test.c b/tests/benchmarks/power_consumption/flash/src/driver_test.c index 23f818ca54f8..819ffba812d9 100644 --- a/tests/benchmarks/power_consumption/flash/src/driver_test.c +++ b/tests/benchmarks/power_consumption/flash/src/driver_test.c @@ -19,20 +19,29 @@ #define TEST_AREA_OFFSET 0xff000 #define EXPECTED_SIZE 512 +#define FLASH_PAGE_SIZE 4096 + uint8_t buf[EXPECTED_SIZE]; +uint8_t fill_value = 0x00; static const struct device *flash_dev = DEVICE_DT_GET(FLASH_NODE); void thread_definition(void) { - int ret; + int rc; while (1) { - ret = flash_read(flash_dev, TEST_AREA_OFFSET, buf, EXPECTED_SIZE); - if (ret < 0) { - printk("Failure in reading byte %d", ret); - return; + rc = flash_erase(flash_dev, TEST_AREA_OFFSET, FLASH_PAGE_SIZE); + __ASSERT(rc == 0, "flash_erase %d\n", rc); + rc = flash_fill(flash_dev, fill_value, TEST_AREA_OFFSET, EXPECTED_SIZE); + __ASSERT(rc == 0, "flash_fill %d\n", rc); + rc = flash_read(flash_dev, TEST_AREA_OFFSET, buf, EXPECTED_SIZE); + __ASSERT(rc == 0, "flash_read %d\n", rc); + for (size_t i = 0; i < EXPECTED_SIZE; i++) { + __ASSERT(buf[i] == fill_value, "flash value %d but expected %d\n", buf[i], fill_value); + buf[i] = (uint8_t)i; } + fill_value++; }; };