mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_flash: improve unit test to detect over boundary issue
This commit is contained in:
parent
a9c8895bb2
commit
f99ba33920
@ -382,7 +382,8 @@ void test_simple_read_write(esp_flash_t *chip)
|
|||||||
|
|
||||||
srand(test_seed);
|
srand(test_seed);
|
||||||
for (int i = 0; i < sizeof(sector_buf); i++) {
|
for (int i = 0; i < sizeof(sector_buf); i++) {
|
||||||
TEST_ASSERT_EQUAL_HEX8(rand() & 0xFF, sector_buf[i]);
|
uint8_t data = rand();
|
||||||
|
TEST_ASSERT_EQUAL_HEX8(data, sector_buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,17 +413,22 @@ FLASH_TEST_CASE_3("SPI flash unaligned read/write", test_unaligned_read_write);
|
|||||||
|
|
||||||
void test_single_read_write(esp_flash_t* chip)
|
void test_single_read_write(esp_flash_t* chip)
|
||||||
{
|
{
|
||||||
|
const int seed = 699;
|
||||||
ESP_LOGI(TAG, "Testing chip %p...", chip);
|
ESP_LOGI(TAG, "Testing chip %p...", chip);
|
||||||
uint32_t offs = erase_test_region(chip, 2);
|
uint32_t offs = erase_test_region(chip, 2);
|
||||||
|
|
||||||
|
srand(seed);
|
||||||
for (unsigned v = 0; v < 512; v++) {
|
for (unsigned v = 0; v < 512; v++) {
|
||||||
TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_flash_write(chip, &v, offs + v, 1) );
|
uint32_t data = rand();
|
||||||
|
TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_flash_write(chip, &data, offs + v, 1) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srand(seed);
|
||||||
for (unsigned v = 0; v < 512; v++) {
|
for (unsigned v = 0; v < 512; v++) {
|
||||||
uint8_t readback;
|
uint8_t readback;
|
||||||
|
uint32_t data = rand();
|
||||||
TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_flash_read(chip, &readback, offs + v, 1) );
|
TEST_ASSERT_EQUAL_HEX(ESP_OK, esp_flash_read(chip, &readback, offs + v, 1) );
|
||||||
TEST_ASSERT_EQUAL_HEX8(v, readback);
|
TEST_ASSERT_EQUAL_HEX8(data, readback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,18 +441,23 @@ FLASH_TEST_CASE_3("SPI flash single byte reads/writes", test_single_read_write);
|
|||||||
*/
|
*/
|
||||||
void test_three_byte_read_write(esp_flash_t *chip)
|
void test_three_byte_read_write(esp_flash_t *chip)
|
||||||
{
|
{
|
||||||
|
const int seed = 700;
|
||||||
ESP_LOGI(TAG, "Testing chip %p...", chip);
|
ESP_LOGI(TAG, "Testing chip %p...", chip);
|
||||||
uint32_t offs = erase_test_region(chip, 2);
|
uint32_t offs = erase_test_region(chip, 2);
|
||||||
ets_printf("offs:%X\n", offs);
|
ets_printf("offs:%X\n", offs);
|
||||||
|
|
||||||
for (uint32_t v = 0; v < 2000; v++) {
|
srand(seed);
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_write(chip, &v, offs + 3 * v, 3) );
|
for (uint32_t v = 0; v < 86; v++) {
|
||||||
|
uint32_t data = rand();
|
||||||
|
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_write(chip, &data, offs + 3 * v, 3) );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t v = 0; v < 2000; v++) {
|
srand(seed);
|
||||||
|
for (uint32_t v = 0; v < 1; v++) {
|
||||||
uint32_t readback;
|
uint32_t readback;
|
||||||
|
uint32_t data = rand();
|
||||||
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_read(chip, &readback, offs + 3 * v, 3) );
|
TEST_ASSERT_EQUAL(ESP_OK, esp_flash_read(chip, &readback, offs + 3 * v, 3) );
|
||||||
TEST_ASSERT_EQUAL_HEX32(v & 0xFFFFFF, readback & 0xFFFFFF);
|
TEST_ASSERT_EQUAL_HEX32(data & 0xFFFFFF, readback & 0xFFFFFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user