test_app_main.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <assert.h>
  9. #include <string.h>
  10. #include "esp_err.h"
  11. #include "esp_system.h"
  12. #include "freertos/FreeRTOS.h"
  13. #include "freertos/task.h"
  14. #include "test_panic.h"
  15. #include "test_memprot.h"
  16. /* Test Utility Functions */
  17. #define BOOT_CMD_MAX_LEN (128)
  18. #define HANDLE_TEST(test_name, name_) \
  19. if (strcmp(test_name, #name_) == 0) { \
  20. name_(); \
  21. die("Test function has returned"); \
  22. }
  23. static const char* get_test_name(void)
  24. {
  25. static char test_name_str[BOOT_CMD_MAX_LEN] = {0};
  26. printf("Enter test name: ");
  27. fflush(stdout);
  28. /* Not using blocking fgets(stdin) here, as QEMU doesn't yet implement RX timeout interrupt,
  29. * which is required for the UART driver and blocking stdio to work.
  30. */
  31. int c = EOF;
  32. char *p = test_name_str;
  33. const char *end = test_name_str + sizeof(test_name_str) - 1;
  34. while (p < end) {
  35. c = getchar();
  36. if (c == EOF) {
  37. vTaskDelay(pdMS_TO_TICKS(10));
  38. } else if ((c == '\r' || c == '\n') && p != test_name_str) {
  39. /* terminate the line */
  40. puts("\n\r");
  41. fflush(stdout);
  42. *p = '\0';
  43. break;
  44. } else {
  45. /* echo the received character */
  46. putchar(c);
  47. fflush(stdout);
  48. /* and save it */
  49. *p = c;
  50. ++p;
  51. }
  52. }
  53. return test_name_str;
  54. }
  55. /* app_main */
  56. void app_main(void)
  57. {
  58. /* Needed to allow the tick hook to set correct INT WDT timeouts */
  59. vTaskDelay(2);
  60. /* Test script sends to command over UART. Read it and determine how to proceed. */
  61. const char* test_name = get_test_name();
  62. if (test_name == NULL) {
  63. /* Nothing to do */
  64. return;
  65. }
  66. printf("Got test name: %s\n", test_name);
  67. HANDLE_TEST(test_name, test_abort);
  68. HANDLE_TEST(test_name, test_abort_cache_disabled);
  69. HANDLE_TEST(test_name, test_int_wdt);
  70. HANDLE_TEST(test_name, test_task_wdt_cpu0);
  71. HANDLE_TEST(test_name, test_hw_stack_guard_cpu0);
  72. #if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
  73. HANDLE_TEST(test_name, test_panic_extram_stack);
  74. #endif
  75. #if !CONFIG_FREERTOS_UNICORE
  76. HANDLE_TEST(test_name, test_task_wdt_cpu1);
  77. HANDLE_TEST(test_name, test_task_wdt_both_cpus);
  78. #endif
  79. HANDLE_TEST(test_name, test_storeprohibited);
  80. HANDLE_TEST(test_name, test_cache_error);
  81. HANDLE_TEST(test_name, test_int_wdt_cache_disabled);
  82. HANDLE_TEST(test_name, test_stack_overflow);
  83. HANDLE_TEST(test_name, test_illegal_instruction);
  84. HANDLE_TEST(test_name, test_instr_fetch_prohibited);
  85. HANDLE_TEST(test_name, test_ub);
  86. HANDLE_TEST(test_name, test_assert);
  87. HANDLE_TEST(test_name, test_assert_cache_disabled);
  88. #if CONFIG_IDF_TARGET_ESP32
  89. HANDLE_TEST(test_name, test_illegal_access);
  90. #endif
  91. #if CONFIG_TEST_MEMPROT
  92. HANDLE_TEST(test_name, test_iram_reg1_write_violation);
  93. HANDLE_TEST(test_name, test_iram_reg2_write_violation);
  94. HANDLE_TEST(test_name, test_iram_reg3_write_violation);
  95. /* TODO: IDF-6820: ESP32-S2 -> Fix incorrect panic reason: Unhandled debug exception */
  96. HANDLE_TEST(test_name, test_iram_reg4_write_violation);
  97. /* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
  98. HANDLE_TEST(test_name, test_dram_reg1_execute_violation);
  99. HANDLE_TEST(test_name, test_dram_reg2_execute_violation);
  100. #if CONFIG_SOC_RTC_FAST_MEM_SUPPORTED
  101. HANDLE_TEST(test_name, test_rtc_fast_reg1_execute_violation);
  102. HANDLE_TEST(test_name, test_rtc_fast_reg2_execute_violation);
  103. /* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
  104. HANDLE_TEST(test_name, test_rtc_fast_reg3_execute_violation);
  105. #endif
  106. #if SOC_DCACHE_SUPPORTED
  107. HANDLE_TEST(test_name, test_dcache_read_violation);
  108. /* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
  109. HANDLE_TEST(test_name, test_dcache_write_violation);
  110. #endif
  111. #if CONFIG_SOC_RTC_SLOW_MEM_SUPPORTED
  112. HANDLE_TEST(test_name, test_rtc_slow_reg1_execute_violation);
  113. HANDLE_TEST(test_name, test_rtc_slow_reg2_execute_violation);
  114. #endif
  115. #endif
  116. die("Unknown test name");
  117. }