Skip to content

Commit f9e9dd4

Browse files
committed
tests: benchmarks: power_consumption: flash: extend test with writes
Add erase and write operation. Validate read values. Signed-off-by: Piotr Kosycarz <[email protected]>
1 parent 8f2b54a commit f9e9dd4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

tests/benchmarks/power_consumption/flash/src/driver_test.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
#define FLASH_NODE DT_INVALID_NODE
1818
#endif
1919

20-
#define TEST_AREA_OFFSET 0xff000
21-
#define EXPECTED_SIZE 512
20+
#define TEST_AREA_OFFSET 0xff000
21+
#define EXPECTED_SIZE 512
22+
#define FLASH_PAGE_SIZE 4096
23+
2224
uint8_t buf[EXPECTED_SIZE];
2325

2426
static const struct device *flash_dev = DEVICE_DT_GET(FLASH_NODE);
2527

26-
2728
void thread_definition(void)
2829
{
29-
int ret;
30+
int rc;
31+
uint8_t fill_value = 0x00;
3032

3133
while (1) {
32-
ret = flash_read(flash_dev, TEST_AREA_OFFSET, buf, EXPECTED_SIZE);
33-
if (ret < 0) {
34-
printk("Failure in reading byte %d", ret);
35-
return;
34+
rc = flash_erase(flash_dev, TEST_AREA_OFFSET, FLASH_PAGE_SIZE);
35+
__ASSERT(rc == 0, "flash_erase %d\n", rc);
36+
rc = flash_fill(flash_dev, fill_value, TEST_AREA_OFFSET, EXPECTED_SIZE);
37+
__ASSERT(rc == 0, "flash_fill %d\n", rc);
38+
rc = flash_read(flash_dev, TEST_AREA_OFFSET, buf, EXPECTED_SIZE);
39+
__ASSERT(rc == 0, "flash_read %d\n", rc);
40+
for (size_t i = 0; i < EXPECTED_SIZE; i++) {
41+
__ASSERT(buf[i] == fill_value, "flash value %d but expected %d\n", buf[i],
42+
fill_value);
43+
buf[i] = (uint8_t)i;
3644
}
45+
fill_value++;
3746
};
3847
};

0 commit comments

Comments
 (0)