test_partition_ext.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "esp_flash.h"
  2. #include "esp_partition.h"
  3. #include "unity.h"
  4. TEST_CASE("Basic handling of a partition in external flash", "[partition]")
  5. {
  6. esp_flash_t flash = {
  7. .size = 1 * 1024 * 1024,
  8. };
  9. const esp_partition_type_t t = ESP_PARTITION_TYPE_DATA;
  10. const esp_partition_subtype_t st = ESP_PARTITION_SUBTYPE_DATA_FAT;
  11. const char* label = "ext_fat";
  12. /* can register */
  13. const esp_partition_t* ext_partition;
  14. TEST_ESP_OK(esp_partition_register_external(&flash, 0, flash.size, label, t, st, &ext_partition));
  15. /* can find the registered partition */
  16. const esp_partition_t* found = esp_partition_find_first(t, st, label);
  17. TEST_ASSERT_EQUAL_HEX(ext_partition, found);
  18. TEST_ASSERT_EQUAL(found->size, flash.size);
  19. TEST_ASSERT_EQUAL(found->address, 0);
  20. /* can deregister */
  21. TEST_ESP_OK(esp_partition_deregister_external(ext_partition));
  22. /* can not deregister one of the partitions on the main flash chip */
  23. const esp_partition_t* nvs_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, NULL);
  24. TEST_ASSERT_NOT_NULL(nvs_partition);
  25. TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_partition_deregister_external(nvs_partition));
  26. /* can not deregister an unknown partition */
  27. esp_partition_t dummy_partition = {};
  28. TEST_ESP_ERR(ESP_ERR_NOT_FOUND, esp_partition_deregister_external(&dummy_partition));
  29. /* can not register a partition larger than the flash size */
  30. TEST_ESP_ERR(ESP_ERR_INVALID_SIZE,
  31. esp_partition_register_external(&flash, 0, 2 * flash.size, "ext_fat", t, st, &ext_partition));
  32. /* can not register an overlapping partition */
  33. TEST_ESP_OK(esp_partition_register_external(&flash, 0, 2 * SPI_FLASH_SEC_SIZE, "p1", t, st, &ext_partition));
  34. TEST_ESP_ERR(ESP_ERR_INVALID_ARG, esp_partition_register_external(&flash, SPI_FLASH_SEC_SIZE, 2 * SPI_FLASH_SEC_SIZE,
  35. "p2", t, st, NULL));
  36. TEST_ESP_OK(esp_partition_deregister_external(ext_partition));
  37. }