2023-01-05 06:41:40 -05:00
|
|
|
/*
|
2024-02-05 06:48:44 -05:00
|
|
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
2023-01-05 06:41:40 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_system.h"
|
|
|
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
|
|
|
|
#include "test_panic.h"
|
2023-01-06 00:16:26 -05:00
|
|
|
#include "test_memprot.h"
|
2023-01-05 06:41:40 -05:00
|
|
|
|
|
|
|
/* Test Utility Functions */
|
|
|
|
|
|
|
|
#define BOOT_CMD_MAX_LEN (128)
|
|
|
|
|
|
|
|
#define HANDLE_TEST(test_name, name_) \
|
|
|
|
if (strcmp(test_name, #name_) == 0) { \
|
|
|
|
name_(); \
|
|
|
|
die("Test function has returned"); \
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* get_test_name(void)
|
|
|
|
{
|
|
|
|
static char test_name_str[BOOT_CMD_MAX_LEN] = {0};
|
2024-01-19 02:51:57 -05:00
|
|
|
bool print_prompt = true;
|
2023-01-05 06:41:40 -05:00
|
|
|
|
|
|
|
/* Not using blocking fgets(stdin) here, as QEMU doesn't yet implement RX timeout interrupt,
|
|
|
|
* which is required for the UART driver and blocking stdio to work.
|
|
|
|
*/
|
|
|
|
int c = EOF;
|
|
|
|
char *p = test_name_str;
|
|
|
|
const char *end = test_name_str + sizeof(test_name_str) - 1;
|
|
|
|
while (p < end) {
|
2024-01-19 02:51:57 -05:00
|
|
|
if (print_prompt) {
|
|
|
|
printf("Enter test name: ");
|
|
|
|
fflush(stdout);
|
|
|
|
print_prompt = false;
|
|
|
|
}
|
2023-01-05 06:41:40 -05:00
|
|
|
c = getchar();
|
|
|
|
if (c == EOF) {
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(10));
|
2024-01-19 02:51:57 -05:00
|
|
|
} else if (c == '\r' || c == '\n') {
|
2023-01-05 06:41:40 -05:00
|
|
|
/* terminate the line */
|
|
|
|
puts("\n\r");
|
|
|
|
fflush(stdout);
|
2024-01-19 02:51:57 -05:00
|
|
|
print_prompt = true;
|
|
|
|
if (p != test_name_str) {
|
|
|
|
*p = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (c >= '0' && c <= 'z') {
|
2023-01-05 06:41:40 -05:00
|
|
|
/* echo the received character */
|
|
|
|
putchar(c);
|
|
|
|
fflush(stdout);
|
|
|
|
/* and save it */
|
|
|
|
*p = c;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return test_name_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* app_main */
|
|
|
|
|
|
|
|
void app_main(void)
|
|
|
|
{
|
|
|
|
/* Needed to allow the tick hook to set correct INT WDT timeouts */
|
|
|
|
vTaskDelay(2);
|
|
|
|
|
|
|
|
/* Test script sends to command over UART. Read it and determine how to proceed. */
|
|
|
|
const char* test_name = get_test_name();
|
|
|
|
if (test_name == NULL) {
|
|
|
|
/* Nothing to do */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("Got test name: %s\n", test_name);
|
|
|
|
|
|
|
|
HANDLE_TEST(test_name, test_abort);
|
|
|
|
HANDLE_TEST(test_name, test_abort_cache_disabled);
|
|
|
|
HANDLE_TEST(test_name, test_int_wdt);
|
|
|
|
HANDLE_TEST(test_name, test_task_wdt_cpu0);
|
2024-01-19 02:51:57 -05:00
|
|
|
#if CONFIG_ESP_SYSTEM_HW_STACK_GUARD
|
2023-05-04 11:31:31 -04:00
|
|
|
HANDLE_TEST(test_name, test_hw_stack_guard_cpu0);
|
2024-01-19 02:51:57 -05:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
|
|
|
HANDLE_TEST(test_name, test_hw_stack_guard_cpu1);
|
|
|
|
#endif // CONFIG_FREERTOS_UNICORE
|
|
|
|
#endif // CONFIG_ESP_SYSTEM_HW_STACK_GUARD
|
2023-01-05 06:41:40 -05:00
|
|
|
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
2024-05-02 18:00:03 -04:00
|
|
|
HANDLE_TEST(test_name, test_panic_extram_stack_heap);
|
|
|
|
#if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
|
|
|
|
HANDLE_TEST(test_name, test_panic_extram_stack_bss);
|
|
|
|
#endif
|
2023-01-05 06:41:40 -05:00
|
|
|
#endif
|
2024-03-11 16:19:17 -04:00
|
|
|
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
|
|
|
|
HANDLE_TEST(test_name, test_capture_dram);
|
|
|
|
#endif
|
2023-01-05 06:41:40 -05:00
|
|
|
#if !CONFIG_FREERTOS_UNICORE
|
|
|
|
HANDLE_TEST(test_name, test_task_wdt_cpu1);
|
|
|
|
#endif
|
2024-04-15 11:09:11 -04:00
|
|
|
HANDLE_TEST(test_name, test_loadprohibited);
|
2023-01-05 06:41:40 -05:00
|
|
|
HANDLE_TEST(test_name, test_storeprohibited);
|
|
|
|
HANDLE_TEST(test_name, test_cache_error);
|
|
|
|
HANDLE_TEST(test_name, test_int_wdt_cache_disabled);
|
|
|
|
HANDLE_TEST(test_name, test_stack_overflow);
|
|
|
|
HANDLE_TEST(test_name, test_illegal_instruction);
|
|
|
|
HANDLE_TEST(test_name, test_instr_fetch_prohibited);
|
|
|
|
HANDLE_TEST(test_name, test_ub);
|
|
|
|
HANDLE_TEST(test_name, test_assert);
|
|
|
|
HANDLE_TEST(test_name, test_assert_cache_disabled);
|
2024-04-25 12:13:46 -04:00
|
|
|
HANDLE_TEST(test_name, test_assert_cache_write_back_error_can_print_backtrace);
|
|
|
|
HANDLE_TEST(test_name, test_assert_cache_write_back_error_can_print_backtrace2);
|
2024-02-27 17:51:28 -05:00
|
|
|
HANDLE_TEST(test_name, test_tcb_corrupted);
|
2024-04-29 12:32:00 -04:00
|
|
|
#if CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH && CONFIG_ESP_COREDUMP_DATA_FORMAT_ELF
|
|
|
|
HANDLE_TEST(test_name, test_setup_coredump_summary);
|
|
|
|
HANDLE_TEST(test_name, test_coredump_summary);
|
|
|
|
#endif
|
2023-10-11 07:24:24 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
|
|
|
HANDLE_TEST(test_name, test_illegal_access);
|
|
|
|
#endif
|
2023-01-05 06:41:40 -05:00
|
|
|
|
2023-01-06 00:16:26 -05:00
|
|
|
#if CONFIG_TEST_MEMPROT
|
|
|
|
|
|
|
|
HANDLE_TEST(test_name, test_iram_reg1_write_violation);
|
|
|
|
HANDLE_TEST(test_name, test_iram_reg2_write_violation);
|
|
|
|
HANDLE_TEST(test_name, test_iram_reg3_write_violation);
|
|
|
|
|
|
|
|
/* TODO: IDF-6820: ESP32-S2 -> Fix incorrect panic reason: Unhandled debug exception */
|
|
|
|
HANDLE_TEST(test_name, test_iram_reg4_write_violation);
|
|
|
|
|
|
|
|
/* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
|
|
|
|
HANDLE_TEST(test_name, test_dram_reg1_execute_violation);
|
|
|
|
|
|
|
|
HANDLE_TEST(test_name, test_dram_reg2_execute_violation);
|
|
|
|
|
|
|
|
#if CONFIG_SOC_RTC_FAST_MEM_SUPPORTED
|
|
|
|
HANDLE_TEST(test_name, test_rtc_fast_reg1_execute_violation);
|
|
|
|
HANDLE_TEST(test_name, test_rtc_fast_reg2_execute_violation);
|
|
|
|
|
|
|
|
/* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
|
|
|
|
HANDLE_TEST(test_name, test_rtc_fast_reg3_execute_violation);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if SOC_DCACHE_SUPPORTED
|
|
|
|
HANDLE_TEST(test_name, test_dcache_read_violation);
|
|
|
|
|
|
|
|
/* TODO: IDF-6820: ESP32-S2-> Fix multiple panic reasons in different runs */
|
|
|
|
HANDLE_TEST(test_name, test_dcache_write_violation);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_SOC_RTC_SLOW_MEM_SUPPORTED
|
|
|
|
HANDLE_TEST(test_name, test_rtc_slow_reg1_execute_violation);
|
|
|
|
HANDLE_TEST(test_name, test_rtc_slow_reg2_execute_violation);
|
|
|
|
#endif
|
|
|
|
|
2024-02-05 06:48:44 -05:00
|
|
|
#if CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT
|
|
|
|
HANDLE_TEST(test_name, test_irom_reg_write_violation);
|
|
|
|
HANDLE_TEST(test_name, test_drom_reg_write_violation);
|
|
|
|
HANDLE_TEST(test_name, test_drom_reg_execute_violation);
|
|
|
|
#endif
|
|
|
|
|
2024-05-31 12:56:59 -04:00
|
|
|
#ifdef CONFIG_SOC_CPU_HAS_PMA
|
|
|
|
HANDLE_TEST(test_name, test_invalid_memory_region_write_violation);
|
|
|
|
HANDLE_TEST(test_name, test_invalid_memory_region_execute_violation);
|
|
|
|
#endif
|
2023-01-06 00:16:26 -05:00
|
|
|
#endif
|
|
|
|
|
2023-01-05 06:41:40 -05:00
|
|
|
die("Unknown test name");
|
|
|
|
}
|