tests/drivers/flash: Make tests check for explicit erase capability
Test now check whether device has requirement for explicit erase before call or not, before performing various actions. Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
parent
b3c9f957c6
commit
010b8d19e9
1 changed files with 53 additions and 22 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2020-2024 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
@ -44,11 +44,16 @@
|
|||
|
||||
#define EXPECTED_SIZE 512
|
||||
|
||||
#if !IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && \
|
||||
!IS_ENABLED(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
|
||||
#error There is no flash device enabled or it is missing Kconfig options
|
||||
#endif
|
||||
|
||||
static const struct device *const flash_dev = TEST_AREA_DEVICE;
|
||||
static struct flash_pages_info page_info;
|
||||
static uint8_t __aligned(4) expected[EXPECTED_SIZE];
|
||||
static const struct flash_parameters *flash_params;
|
||||
static uint8_t erase_value;
|
||||
static bool ebw_required;
|
||||
|
||||
static void *flash_driver_setup(void)
|
||||
{
|
||||
|
@ -57,12 +62,22 @@ static void *flash_driver_setup(void)
|
|||
TC_PRINT("Test will run on device %s\n", flash_dev->name);
|
||||
zassert_true(device_is_ready(flash_dev));
|
||||
|
||||
flash_params = flash_get_parameters(flash_dev);
|
||||
erase_value = flash_params->erase_value;
|
||||
/* Check for erase is only needed when there is mix of devices */
|
||||
if (IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE)) {
|
||||
const struct flash_parameters *fparams = flash_get_parameters(flash_dev);
|
||||
|
||||
erase_value = fparams->erase_value;
|
||||
ebw_required = flash_params_get_erase_cap(fparams) & FLASH_ERASE_C_EXPLICIT;
|
||||
/* For tests purposes use page (in nrf_qspi_nor page = 64 kB) */
|
||||
flash_get_page_info_by_offs(flash_dev, TEST_AREA_OFFSET,
|
||||
&page_info);
|
||||
} else {
|
||||
TC_PRINT("No devices with erase requirement present\n");
|
||||
erase_value = 0x55;
|
||||
page_info.start_offset = TEST_AREA_OFFSET;
|
||||
page_info.size = TEST_AREA_MAX - TEST_AREA_OFFSET;
|
||||
}
|
||||
|
||||
/* For tests purposes use page (in nrf_qspi_nor page = 64 kB) */
|
||||
flash_get_page_info_by_offs(flash_dev, TEST_AREA_OFFSET,
|
||||
&page_info);
|
||||
|
||||
/* Check if test region is not empty */
|
||||
uint8_t buf[EXPECTED_SIZE];
|
||||
|
@ -85,23 +100,25 @@ static void *flash_driver_setup(void)
|
|||
"Test area exceeds flash size");
|
||||
|
||||
/* Check if flash is cleared */
|
||||
bool is_buf_clear = true;
|
||||
if (IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && ebw_required) {
|
||||
bool is_buf_clear = true;
|
||||
|
||||
for (off_t i = 0; i < EXPECTED_SIZE; i++) {
|
||||
if (buf[i] != erase_value) {
|
||||
is_buf_clear = false;
|
||||
break;
|
||||
for (off_t i = 0; i < EXPECTED_SIZE; i++) {
|
||||
if (buf[i] != erase_value) {
|
||||
is_buf_clear = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_buf_clear) {
|
||||
/* Erase a nb of pages aligned to the EXPECTED_SIZE */
|
||||
rc = flash_erase(flash_dev, page_info.start_offset,
|
||||
(page_info.size *
|
||||
((EXPECTED_SIZE + page_info.size - 1)
|
||||
/ page_info.size)));
|
||||
if (!is_buf_clear) {
|
||||
/* Erase a nb of pages aligned to the EXPECTED_SIZE */
|
||||
rc = flash_erase(flash_dev, page_info.start_offset,
|
||||
(page_info.size *
|
||||
((EXPECTED_SIZE + page_info.size - 1)
|
||||
/ page_info.size)));
|
||||
|
||||
zassert_equal(rc, 0, "Flash memory not properly erased");
|
||||
zassert_equal(rc, 0, "Flash memory not properly erased");
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -112,9 +129,23 @@ ZTEST(flash_driver, test_read_unaligned_address)
|
|||
int rc;
|
||||
uint8_t buf[EXPECTED_SIZE];
|
||||
const uint8_t canary = erase_value;
|
||||
uint32_t start;
|
||||
|
||||
if (IS_ENABLED(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && ebw_required) {
|
||||
start = page_info.start_offset;
|
||||
/* Erase a nb of pages aligned to the EXPECTED_SIZE */
|
||||
rc = flash_erase(flash_dev, page_info.start_offset,
|
||||
(page_info.size *
|
||||
((EXPECTED_SIZE + page_info.size - 1)
|
||||
/ page_info.size)));
|
||||
|
||||
zassert_equal(rc, 0, "Flash memory not properly erased");
|
||||
} else {
|
||||
start = TEST_AREA_OFFSET;
|
||||
}
|
||||
|
||||
rc = flash_write(flash_dev,
|
||||
page_info.start_offset,
|
||||
start,
|
||||
expected, EXPECTED_SIZE);
|
||||
zassert_equal(rc, 0, "Cannot write to flash");
|
||||
|
||||
|
@ -129,7 +160,7 @@ ZTEST(flash_driver, test_read_unaligned_address)
|
|||
buf[buf_o + len] = canary;
|
||||
memset(buf + buf_o, 0, len);
|
||||
rc = flash_read(flash_dev,
|
||||
page_info.start_offset + ad_o,
|
||||
start + ad_o,
|
||||
buf + buf_o, len);
|
||||
zassert_equal(rc, 0, "Cannot read flash");
|
||||
zassert_equal(memcmp(buf + buf_o,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue