Skip to content

Commit

Permalink
tests: benchmarks: power_consumption: flash: extend test with writes
Browse files Browse the repository at this point in the history
Add erase and write operation.
Validate read values.

Signed-off-by: Piotr Kosycarz <[email protected]>
  • Loading branch information
nordic-piks committed Jan 10, 2025
1 parent 8f2b54a commit f9e9dd4
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions tests/benchmarks/power_consumption/flash/src/driver_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
};
};

0 comments on commit f9e9dd4

Please sign in to comment.