From 815f7439564e7706e87d919b036aa1507ebd6832 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 | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 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..8f449ea1b281 100644 --- a/tests/benchmarks/power_consumption/flash/src/driver_test.c +++ b/tests/benchmarks/power_consumption/flash/src/driver_test.c @@ -17,22 +17,31 @@ #define FLASH_NODE DT_INVALID_NODE #endif -#define TEST_AREA_OFFSET 0xff000 -#define EXPECTED_SIZE 512 +#define TEST_AREA_OFFSET 0xff000 +#define EXPECTED_SIZE 512 +#define FLASH_PAGE_SIZE 4096 + uint8_t buf[EXPECTED_SIZE]; static const struct device *flash_dev = DEVICE_DT_GET(FLASH_NODE); - void thread_definition(void) { - int ret; + int rc; + uint8_t fill_value = 0x00; 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++; }; };