panic_tests.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #!/usr/bin/env python
  2. from pprint import pformat
  3. import re
  4. from test_panic_util.test_panic_util import get_dut
  5. def get_default_backtrace(test_name):
  6. return [
  7. test_name,
  8. "app_main",
  9. "main_task",
  10. "vPortTaskWrapper"
  11. ]
  12. def test_common(dut, test_name, expected_backtrace=None):
  13. if expected_backtrace is None:
  14. expected_backtrace = get_default_backtrace(dut.test_name)
  15. if "gdbstub" in test_name:
  16. dut.start_gdb()
  17. frames = dut.gdb_backtrace()
  18. if not dut.match_backtrace(frames, expected_backtrace):
  19. raise AssertionError("Unexpected backtrace in test {}:\n{}".format(test_name, pformat(frames)))
  20. return
  21. if "uart" in test_name:
  22. dut.expect(dut.COREDUMP_UART_END)
  23. dut.expect("Rebooting...")
  24. if "uart" in test_name:
  25. dut.process_coredump_uart()
  26. # TODO: check backtrace
  27. elif "flash" in test_name:
  28. dut.process_coredump_flash()
  29. # TODO: check backtrace
  30. elif "panic" in test_name:
  31. # TODO: check backtrace
  32. pass
  33. def task_wdt_inner(env, test_name):
  34. with get_dut(env, test_name, "test_task_wdt", qemu_wdt_enable=True) as dut:
  35. dut.expect("Task watchdog got triggered. The following tasks did not reset the watchdog in time:")
  36. dut.expect("CPU 0: main")
  37. dut.expect(re.compile(r"abort\(\) was called at PC [0-9xa-f]+ on core 0"))
  38. dut.expect_none("register dump:")
  39. dut.expect_backtrace()
  40. dut.expect_elf_sha256()
  41. dut.expect_none("Guru Meditation")
  42. test_common(dut, test_name, expected_backtrace=[
  43. # Backtrace interrupted when abort is called, IDF-842.
  44. # Task WDT calls abort internally.
  45. "panic_abort", "esp_system_abort"
  46. ])
  47. def int_wdt_inner(env, test_name):
  48. with get_dut(env, test_name, "test_int_wdt", qemu_wdt_enable=True) as dut:
  49. dut.expect_gme("Interrupt wdt timeout on CPU0")
  50. dut.expect_reg_dump(0)
  51. dut.expect_backtrace()
  52. dut.expect_none("Guru Meditation")
  53. dut.expect_reg_dump(1)
  54. dut.expect_backtrace()
  55. dut.expect_elf_sha256()
  56. dut.expect_none("Guru Meditation")
  57. test_common(dut, test_name)
  58. def int_wdt_cache_disabled_inner(env, test_name):
  59. with get_dut(env, test_name, "test_int_wdt_cache_disabled", qemu_wdt_enable=True) as dut:
  60. dut.expect("Re-enable cpu cache.")
  61. dut.expect_gme("Interrupt wdt timeout on CPU0")
  62. dut.expect_reg_dump(0)
  63. dut.expect("Backtrace:")
  64. dut.expect_none("Guru Meditation")
  65. dut.expect_reg_dump(1)
  66. dut.expect_backtrace()
  67. dut.expect_elf_sha256()
  68. dut.expect_none("Guru Meditation")
  69. test_common(dut, test_name)
  70. def cache_error_inner(env, test_name):
  71. with get_dut(env, test_name, "test_cache_error") as dut:
  72. dut.expect("Re-enable cpu cache.")
  73. dut.expect_gme("Cache disabled but cached memory region accessed")
  74. dut.expect_reg_dump(0)
  75. dut.expect_backtrace()
  76. dut.expect_elf_sha256()
  77. dut.expect_none("Guru Meditation")
  78. test_common(dut, test_name,
  79. expected_backtrace=["die"] + get_default_backtrace(dut.test_name))
  80. def abort_inner(env, test_name):
  81. with get_dut(env, test_name, "test_abort") as dut:
  82. dut.expect(re.compile(r"abort\(\) was called at PC [0-9xa-f]+ on core 0"))
  83. dut.expect_backtrace()
  84. dut.expect_elf_sha256()
  85. dut.expect_none("Guru Meditation", "Re-entered core dump")
  86. test_common(dut, test_name, expected_backtrace=[
  87. # Backtrace interrupted when abort is called, IDF-842
  88. "panic_abort", "esp_system_abort"
  89. ])
  90. def storeprohibited_inner(env, test_name):
  91. with get_dut(env, test_name, "test_storeprohibited") as dut:
  92. dut.expect_gme("StoreProhibited")
  93. dut.expect_reg_dump(0)
  94. dut.expect_backtrace()
  95. dut.expect_elf_sha256()
  96. dut.expect_none("Guru Meditation")
  97. test_common(dut, test_name)
  98. def stack_overflow_inner(env, test_name):
  99. with get_dut(env, test_name, "test_stack_overflow") as dut:
  100. dut.expect_gme("Unhandled debug exception")
  101. dut.expect("Stack canary watchpoint triggered (main)")
  102. dut.expect_reg_dump(0)
  103. dut.expect_backtrace()
  104. dut.expect_elf_sha256()
  105. dut.expect_none("Guru Meditation")
  106. test_common(dut, test_name)
  107. def illegal_instruction_inner(env, test_name):
  108. with get_dut(env, test_name, "test_illegal_instruction") as dut:
  109. dut.expect_gme("IllegalInstruction")
  110. dut.expect_reg_dump(0)
  111. dut.expect_backtrace()
  112. dut.expect_elf_sha256()
  113. dut.expect_none("Guru Meditation")
  114. test_common(dut, test_name)
  115. def instr_fetch_prohibited_inner(env, test_name):
  116. with get_dut(env, test_name, "test_instr_fetch_prohibited") as dut:
  117. dut.expect_gme("InstrFetchProhibited")
  118. dut.expect_reg_dump(0)
  119. dut.expect_backtrace()
  120. dut.expect_elf_sha256()
  121. dut.expect_none("Guru Meditation")
  122. test_common(dut, test_name,
  123. expected_backtrace=["_init"] + get_default_backtrace(dut.test_name))