test_partition_ext.c 2.1 KB

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