test_ota_ops.c 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. /* These OTA tests currently don't assume an OTA partition exists
  11. on the device, so they're a bit limited
  12. */
  13. TEST_CASE("esp_ota_begin() verifies arguments", "[ota]")
  14. {
  15. const esp_partition_t *running = esp_ota_get_running_partition();
  16. esp_partition_t partition;
  17. static esp_ota_handle_t handle = 0;
  18. if (handle != 0) { /* clean up from any previous test */
  19. esp_ota_end(handle);
  20. handle = 0;
  21. }
  22. /* running partition & configured boot partition are same */
  23. TEST_ASSERT_NOT_NULL(running);
  24. /* trying to 'begin' on running partition fails */
  25. TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_ota_begin(running, OTA_SIZE_UNKNOWN, &handle));
  26. TEST_ASSERT_EQUAL(0, handle);
  27. memcpy(&partition, running, sizeof(esp_partition_t));
  28. partition.address--;
  29. /* non existent partition fails */
  30. TEST_ASSERT_EQUAL_HEX(ESP_ERR_NOT_FOUND, esp_ota_begin(&partition, OTA_SIZE_UNKNOWN, &handle));
  31. TEST_ASSERT_EQUAL(0, handle);
  32. }
  33. TEST_CASE("esp_ota_get_next_update_partition logic", "[ota]")
  34. {
  35. const esp_partition_t *running = esp_ota_get_running_partition();
  36. const esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  37. ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
  38. const esp_partition_t *ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  39. ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);
  40. const esp_partition_t *ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  41. ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
  42. const esp_partition_t *ota_2 = esp_partition_find_first(ESP_PARTITION_TYPE_APP,
  43. ESP_PARTITION_SUBTYPE_APP_OTA_2, NULL);
  44. TEST_ASSERT_NOT_NULL(running);
  45. TEST_ASSERT_NOT_NULL(factory);
  46. TEST_ASSERT_NOT_NULL(ota_0);
  47. TEST_ASSERT_NOT_NULL(ota_1);
  48. TEST_ASSERT_NULL(ota_2); /* this partition shouldn't exist in test partition table */
  49. TEST_ASSERT_EQUAL_PTR(factory, running); /* this may not be true if/when we get OTA tests that do OTA updates */
  50. /* (The test steps verify subtypes before verifying pointer equality, because the failure messages are more readable
  51. this way.)
  52. */
  53. /* Factory app OTA updates OTA 0 slot */
  54. const esp_partition_t *p = esp_ota_get_next_update_partition(NULL);
  55. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);
  56. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  57. p = esp_ota_get_next_update_partition(factory);
  58. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);
  59. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  60. /* OTA slot 0 updates OTA slot 1 */
  61. p = esp_ota_get_next_update_partition(ota_0);
  62. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_1, p->subtype);
  63. TEST_ASSERT_EQUAL_PTR(ota_1, p);
  64. /* OTA slot 1 updates OTA slot 0 */
  65. p = esp_ota_get_next_update_partition(ota_1);
  66. TEST_ASSERT_EQUAL_HEX8(ESP_PARTITION_SUBTYPE_APP_OTA_0, p->subtype);;
  67. TEST_ASSERT_EQUAL_PTR(ota_0, p);
  68. }