Skip to content

Commit

Permalink
tests: intel_s1000: flash_map: Enable tests for flash_map
Browse files Browse the repository at this point in the history
This patchset introduces some tests for the flash_map and
flash_page_layout features.

Signed-off-by: Rajavardhan Gundi <[email protected]>
  • Loading branch information
rgundi authored and nashif committed Jan 17, 2019
1 parent b5dd8ac commit 18b6483
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/boards/intel_s1000_crb/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ CONFIG_I2C=y
CONFIG_DMA=y
CONFIG_SPI=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
40 changes: 40 additions & 0 deletions tests/boards/intel_s1000_crb/src/spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <zephyr.h>
#include <flash.h>
#include <flash_map.h>
#include <device.h>
#include <stdio.h>
#include <logging/log.h>
Expand All @@ -17,10 +18,42 @@ LOG_MODULE_REGISTER(test_flash);
#define TEST_DATA_BYTE_1 0x4a
#define TEST_DATA_LEN 128

int flash_region_is_empty(u32_t off, void *dst, u32_t len)
{
u8_t i;
u8_t *u8dst;
int rc;
const struct flash_area *fap;

rc = flash_area_open(3, &fap);
if (rc != 0) {
LOG_ERR("SPI flash area open failed!\n");
return -1;
}

rc = flash_area_read(fap, off - fap->fa_off, dst, len);
if (rc) {
LOG_ERR("SPI flash efailed!\n");
return -1;
}

for (i = 0, u8dst = (uint8_t *)dst; i < len; i++) {
if (u8dst[i] != 0xFF) {
flash_area_close(fap);
return 0;
}
}

flash_area_close(fap);

return 1;
}

void test_flash(void)
{
struct device *flash_dev;
u8_t buf[TEST_DATA_LEN];
u32_t magic[4];
int i;

flash_dev = device_get_binding(DT_SPI_NOR_DRV_NAME);
Expand Down Expand Up @@ -67,4 +100,11 @@ void test_flash(void)
} else {
LOG_ERR(" Data read does not match with data written!!\n");
}

if (flash_region_is_empty(
FLASH_TEST_REGION_OFFSET - 16, magic, 16) == 1) {
LOG_INF(" Flash region is empty. Good!!\n");
} else {
LOG_ERR(" Flash region is not empty!!\n");
}
}

0 comments on commit 18b6483

Please sign in to comment.