app_main.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "unity.h"
  9. #include "mbedtls/aes.h"
  10. #include "memory_checks.h"
  11. #include "soc/soc_caps.h"
  12. #if SOC_SHA_SUPPORT_PARALLEL_ENG
  13. #include "sha/sha_parallel_engine.h"
  14. #elif SOC_SHA_SUPPORT_DMA
  15. #include "sha/sha_dma.h"
  16. #else
  17. #include "sha/sha_block.h"
  18. #endif
  19. #if SOC_SHA_SUPPORT_SHA512
  20. #define SHA_TYPE SHA2_512
  21. #else
  22. #define SHA_TYPE SHA2_256
  23. #endif //SOC_SHA_SUPPORT_SHA512
  24. /* setUp runs before every test */
  25. void setUp(void)
  26. {
  27. // Execute esp_sha operation to allocate internal SHA semaphore (in case of ESP32)
  28. // and initial DMA setup memory which is considered as leaked otherwise
  29. #if SOC_SHA_SUPPORTED
  30. const uint8_t input_buffer[64] = {0};
  31. uint8_t output_buffer[64];
  32. esp_sha(SHA_TYPE, input_buffer, sizeof(input_buffer), output_buffer);
  33. #endif // SOC_SHA_SUPPORTED
  34. // Execute mbedtls_aes_init operation to allocate AES interrupt
  35. // allocation memory which is considered as leak otherwise
  36. #if SOC_AES_SUPPORTED
  37. mbedtls_aes_context ctx;
  38. mbedtls_aes_init(&ctx);
  39. #endif // SOC_AES_SUPPORTED
  40. test_utils_record_free_mem();
  41. TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
  42. TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_GENERAL));
  43. }
  44. /* tearDown runs after every test */
  45. void tearDown(void)
  46. {
  47. /* some FreeRTOS stuff is cleaned up by idle task */
  48. vTaskDelay(5);
  49. /* clean up some of the newlib's lazy allocations */
  50. esp_reent_cleanup();
  51. /* check if unit test has caused heap corruption in any heap */
  52. TEST_ASSERT_MESSAGE( heap_caps_check_integrity(MALLOC_CAP_INVALID, true), "The test has corrupted the heap");
  53. test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
  54. test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
  55. }
  56. void app_main(void)
  57. {
  58. unity_run_menu();
  59. }