2017-10-25 03:22:30 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "unity.h"
|
2022-06-27 03:24:07 -04:00
|
|
|
#include "spi_flash_mmap.h"
|
2017-10-25 03:22:30 -04:00
|
|
|
#include "esp_ota_ops.h"
|
|
|
|
|
2019-06-11 04:45:26 -04:00
|
|
|
#if CONFIG_SPI_FLASH_DANGEROUS_WRITE_ABORTS || CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS
|
2017-10-25 03:22:30 -04:00
|
|
|
|
|
|
|
static const char *data = "blah blah blah";
|
|
|
|
|
2019-06-11 04:45:26 -04:00
|
|
|
#if CONFIG_SPI_FLASH_DANGEROUS_WRITE_FAILS
|
2019-01-08 05:29:25 -05:00
|
|
|
#define TEST_TAGS "[spi_flash][esp_flash]"
|
2017-10-25 03:22:30 -04:00
|
|
|
#else // ABORTS
|
2019-01-08 05:29:25 -05:00
|
|
|
#define TEST_TAGS "[spi_flash][esp_flash][ignore]"
|
2017-10-25 03:22:30 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
TEST_CASE("can't overwrite bootloader", TEST_TAGS)
|
|
|
|
{
|
2022-06-27 03:24:07 -04:00
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_write(NULL, data, 0x1000, strlen(data)));
|
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_write(NULL, data, 0x0FF8, strlen(data)));
|
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_write(NULL, data, 0x1400, strlen(data)));
|
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_erase_region(NULL, 0x8000, 0x2000));
|
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_erase_region(NULL, 0x7000, 0x2000));
|
2017-10-25 03:22:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("can't overwrite current running app", TEST_TAGS)
|
|
|
|
{
|
|
|
|
const esp_partition_t *p = esp_ota_get_running_partition();
|
2022-06-27 03:24:07 -04:00
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_write(NULL, data, p->address + 1024, strlen(data)));
|
|
|
|
TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_flash_erase_region(NULL, p->address + 4096, 8192));
|
2017-10-25 03:22:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // FAILS || ABORTS
|