test_ota_ops.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <freertos/FreeRTOS.h>
  5. #include <freertos/task.h>
  6. #include <freertos/semphr.h>
  7. #include <unity.h>
  8. #include <test_utils.h>
  9. #include <esp_ota_ops.h>
  10. #include "bootloader_common.h"
  11. /* These OTA tests currently don't assume an OTA partition exists
  12. on the device, so they're a bit limited
  13. */
  14. TEST_CASE("esp_ota_begin() verifies arguments", "[ota]")
  15. {
  16. const esp_partition_t *running = esp_ota_get_running_partition();
  17. esp_partition_t partition;
  18. static esp_ota_handle_t handle = 0;
  19. if (handle != 0) { /* clean up from any previous test */
  20. esp_ota_end(handle);
  21. handle = 0;
  22. }
  23. /* running partition & configured boot partition are same */
  24. TEST_ASSERT_NOT_NULL(running);
  25. /* trying to 'begin' on running partition fails */
  26. TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_ota_begin(running, OTA_SIZE_UNKNOWN, &handle));
  27. TEST_ASSERT_EQUAL(0, handle);
  28. memcpy(&partition, running, sizeof(esp_partition_t));
  29. partition.address--;
  30. /* non existent partition fails */
  31. TEST_ASSERT_EQUAL_HEX(ESP_ERR_NOT_FOUND, esp_ota_begin(&partition, OTA_SIZE_UNKNOWN, &handle));
  32. TEST_ASSERT_EQUAL(0, handle);
  33. }
  34. TEST_CASE("esp_ota_get_next_update_partition logic", "[ota]")
  35. {
  36. const esp_partition_t *running = esp_ota_get_running_partition();
  37. const esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  38. ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
  39. const esp_partition_t *ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  40. ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);
  41. const esp_partition_t *ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  42. ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
  43. const esp_partition_t *ota_2 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  44. ESP_PARTITION_SUBTYPE_APP_OTA_2, NULL);
  45. TEST_ASSERT_NOT_NULL(running);
  46. TEST_ASSERT_NOT_NULL(factory);
  47. TEST_ASSERT_NOT_NULL(ota_0);
  48. TEST_ASSERT_NOT_NULL(ota_1);
  49. TEST_ASSERT_NULL(ota_2); /* this partition shouldn't exist in test partition table */
  50. TEST_ASSERT_EQUAL_PTR(factory, running); /* this may not be true if/when we get OTA tests that do OTA updates */
  51. /* (The test steps verify subtypes before verifying pointer equality, because the failure messages are more readable
  52. this way.)
  53. */
  54. /* Factory app OTA updates OTA 0 slot */
  55. const esp_partition_t *p = esp_ota_get_next_update_partition(NULL);
  56. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);
  57. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  58. p = esp_ota_get_next_update_partition(factory);
  59. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);
  60. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  61. /* OTA slot 0 updates OTA slot 1 */
  62. p = esp_ota_get_next_update_partition(ota_0);
  63. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_1, p->subtype);
  64. TEST_ASSERT_EQUAL_PTR(ota_1, p);
  65. /* OTA slot 1 updates OTA slot 0 */
  66. p = esp_ota_get_next_update_partition(ota_1);
  67. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);;
  68. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  69. }
  70. TEST_CASE("esp_ota_get_partition_description", "[ota]")
  71. {
  72. const esp_partition_t *running = esp_ota_get_running_partition();
  73. TEST_ASSERT_NOT_NULL(running);
  74. esp_app_desc_t app_desc1, app_desc2;
  75. TEST_ESP_OK(esp_ota_get_partition_description(running, &app_desc1));
  76. const esp_partition_pos_t running_pos = {
  77. .offset = running->address,
  78. .size = running->size
  79. };
  80. TEST_ESP_OK(bootloader_common_get_partition_description(&running_pos, &app_desc2));
  81. TEST_ASSERT_EQUAL_MEMORY_MESSAGE((uint8_t *)&app_desc1, (uint8_t *)&app_desc2, sizeof(app_desc1), "must be the same");
  82. const esp_partition_t *not_app = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
  83. TEST_ASSERT_NOT_NULL(not_app);
  84. TEST_ESP_ERR(ESP_ERR_NOT_SUPPORTED, esp_ota_get_partition_description(not_app, &app_desc1));
  85. const esp_partition_pos_t not_app_pos = {
  86. .offset = not_app->address,
  87. .size = not_app->size
  88. };
  89. TEST_ESP_ERR(ESP_ERR_NOT_FOUND, bootloader_common_get_partition_description(&not_app_pos, &app_desc1));
  90. }