2020-05-22 08:21:05 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import re
|
2021-01-25 21:49:01 -05:00
|
|
|
from pprint import pformat
|
|
|
|
|
2020-05-22 08:21:05 -04:00
|
|
|
from test_panic_util.test_panic_util import get_dut
|
|
|
|
|
|
|
|
|
2020-09-30 16:41:14 -04:00
|
|
|
def get_default_backtrace(test_name):
|
|
|
|
return [
|
|
|
|
test_name,
|
2021-01-25 21:49:01 -05:00
|
|
|
'app_main',
|
|
|
|
'main_task',
|
|
|
|
'vPortTaskWrapper'
|
2020-09-30 16:41:14 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_common(dut, test_name, expected_backtrace=None):
|
|
|
|
if expected_backtrace is None:
|
|
|
|
expected_backtrace = get_default_backtrace(dut.test_name)
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
if 'gdbstub' in test_name:
|
2021-03-29 20:01:39 -04:00
|
|
|
dut.expect('Entering gdb stub now.')
|
2020-09-30 16:41:14 -04:00
|
|
|
dut.start_gdb()
|
|
|
|
frames = dut.gdb_backtrace()
|
|
|
|
if not dut.match_backtrace(frames, expected_backtrace):
|
2021-01-25 21:49:01 -05:00
|
|
|
raise AssertionError('Unexpected backtrace in test {}:\n{}'.format(test_name, pformat(frames)))
|
2020-09-30 16:41:14 -04:00
|
|
|
return
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
if 'uart' in test_name:
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect(dut.COREDUMP_UART_END)
|
2020-09-30 16:41:14 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect('Rebooting...')
|
2020-09-30 16:41:14 -04:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
if 'uart' in test_name:
|
2020-09-30 16:41:14 -04:00
|
|
|
dut.process_coredump_uart()
|
|
|
|
# TODO: check backtrace
|
2021-01-25 21:49:01 -05:00
|
|
|
elif 'flash' in test_name:
|
2020-09-30 16:41:14 -04:00
|
|
|
dut.process_coredump_flash()
|
|
|
|
# TODO: check backtrace
|
2021-01-25 21:49:01 -05:00
|
|
|
elif 'panic' in test_name:
|
2020-09-30 16:41:14 -04:00
|
|
|
# TODO: check backtrace
|
|
|
|
pass
|
2020-05-22 08:21:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
def task_wdt_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_task_wdt', qemu_wdt_enable=True) as dut:
|
|
|
|
dut.expect('Task watchdog got triggered. The following tasks did not reset the watchdog in time:')
|
|
|
|
dut.expect('CPU 0: main')
|
|
|
|
dut.expect(re.compile(r'abort\(\) was called at PC [0-9xa-f]+ on core 0'))
|
|
|
|
dut.expect_none('register dump:')
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-09-30 16:41:14 -04:00
|
|
|
test_common(dut, test_name, expected_backtrace=[
|
|
|
|
# Backtrace interrupted when abort is called, IDF-842.
|
|
|
|
# Task WDT calls abort internally.
|
2021-01-25 21:49:01 -05:00
|
|
|
'panic_abort', 'esp_system_abort'
|
2020-09-30 16:41:14 -04:00
|
|
|
])
|
2020-05-22 08:21:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
def int_wdt_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_int_wdt', qemu_wdt_enable=True) as dut:
|
|
|
|
dut.expect_gme('Interrupt wdt timeout on CPU0')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(1)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
test_common(dut, test_name)
|
|
|
|
|
|
|
|
|
|
|
|
def int_wdt_cache_disabled_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_int_wdt_cache_disabled', qemu_wdt_enable=True) as dut:
|
|
|
|
dut.expect_gme('Interrupt wdt timeout on CPU0')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect('Backtrace:')
|
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(1)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
test_common(dut, test_name)
|
|
|
|
|
|
|
|
|
|
|
|
def cache_error_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_cache_error') as dut:
|
|
|
|
dut.expect_gme('Cache disabled but cached memory region accessed')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-09-30 16:41:14 -04:00
|
|
|
test_common(dut, test_name,
|
2021-01-25 21:49:01 -05:00
|
|
|
expected_backtrace=['die'] + get_default_backtrace(dut.test_name))
|
2020-05-22 08:21:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
def abort_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_abort') as dut:
|
|
|
|
dut.expect(re.compile(r'abort\(\) was called at PC [0-9xa-f]+ on core 0'))
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation', 'Re-entered core dump')
|
2020-09-30 16:41:14 -04:00
|
|
|
test_common(dut, test_name, expected_backtrace=[
|
|
|
|
# Backtrace interrupted when abort is called, IDF-842
|
2021-01-25 21:49:01 -05:00
|
|
|
'panic_abort', 'esp_system_abort'
|
2020-09-30 16:41:14 -04:00
|
|
|
])
|
2020-05-22 08:21:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
def storeprohibited_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_storeprohibited') as dut:
|
|
|
|
dut.expect_gme('StoreProhibited')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
test_common(dut, test_name)
|
|
|
|
|
|
|
|
|
|
|
|
def stack_overflow_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_stack_overflow') as dut:
|
|
|
|
dut.expect_gme('Unhandled debug exception')
|
|
|
|
dut.expect('Stack canary watchpoint triggered (main)')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
test_common(dut, test_name)
|
|
|
|
|
|
|
|
|
|
|
|
def illegal_instruction_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_illegal_instruction') as dut:
|
|
|
|
dut.expect_gme('IllegalInstruction')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:23:29 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-05-22 08:21:05 -04:00
|
|
|
test_common(dut, test_name)
|
|
|
|
|
|
|
|
|
|
|
|
def instr_fetch_prohibited_inner(env, test_name):
|
2021-01-25 21:49:01 -05:00
|
|
|
with get_dut(env, test_name, 'test_instr_fetch_prohibited') as dut:
|
|
|
|
dut.expect_gme('InstrFetchProhibited')
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_reg_dump(0)
|
2020-07-29 06:20:52 -04:00
|
|
|
dut.expect_backtrace()
|
2020-05-22 08:21:05 -04:00
|
|
|
dut.expect_elf_sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
dut.expect_none('Guru Meditation')
|
2020-09-30 16:41:14 -04:00
|
|
|
test_common(dut, test_name,
|
2021-01-25 21:49:01 -05:00
|
|
|
expected_backtrace=['_init'] + get_default_backtrace(dut.test_name))
|
2020-11-20 21:15:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
def ub_inner(env, test_name):
|
2021-01-24 10:37:28 -05:00
|
|
|
with get_dut(env, test_name, 'test_ub') as dut:
|
|
|
|
dut.expect(re.compile(r'Undefined behavior of type out_of_bounds'))
|
2020-11-20 21:15:59 -05:00
|
|
|
dut.expect_backtrace()
|
|
|
|
dut.expect_elf_sha256()
|
2021-01-24 10:37:28 -05:00
|
|
|
dut.expect_none('Guru Meditation', 'Re-entered core dump')
|
2020-11-20 21:15:59 -05:00
|
|
|
test_common(dut, test_name, expected_backtrace=[
|
|
|
|
# Backtrace interrupted when abort is called, IDF-842
|
2021-01-24 10:37:28 -05:00
|
|
|
'panic_abort', 'esp_system_abort'
|
2020-11-20 21:15:59 -05:00
|
|
|
])
|