pytest_runtime.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: CC0-1.0
  3. import os
  4. import sys
  5. import pytest
  6. sys.path.append(os.path.expandvars(os.path.join('$IDF_PATH', 'tools', 'test_apps', 'system', 'panic')))
  7. from test_panic_util import PanicTestDut # noqa: E402
  8. @pytest.mark.supported_targets
  9. @pytest.mark.temp_skip_ci(targets=['esp32c2', 'esp32h2'], reason='resolve IDF-7264')
  10. @pytest.mark.generic
  11. def test_gdbstub_runtime(dut: PanicTestDut) -> None:
  12. dut.expect_exact('tested app is runnig.')
  13. dut.write(b'\x03') # send Ctrl-C
  14. dut.start_gdb()
  15. # Test breakpoint
  16. cmd = '-break-insert --source test_app_main.c --line 23'
  17. response = dut.find_gdb_response('done', 'result', dut.gdb_write(cmd))
  18. assert response is not None
  19. cmd = '-exec-continue'
  20. responses = dut.gdb_write(cmd)
  21. assert dut.find_gdb_response('running', 'result', responses) is not None
  22. if not dut.find_gdb_response('stopped', 'notify', responses):
  23. # does not stoped on breakpoint yet
  24. responses = dut.gdbmi.get_gdb_response(timeout_sec=3)
  25. assert dut.find_gdb_response('stopped', 'notify', responses) is not None
  26. payload = dut.find_gdb_response('stopped', 'notify', responses)['payload']
  27. assert payload['reason'] == 'breakpoint-hit'
  28. assert payload['bkptno'] == '1'
  29. assert payload['frame']['func'] == 'app_main'
  30. assert payload['frame']['line'] == '23'
  31. assert payload['stopped-threads'] == 'all'
  32. # Test step command
  33. cmd = '-exec-step'
  34. responses = dut.gdb_write(cmd)
  35. assert dut.find_gdb_response('running', 'result', responses) is not None
  36. if not dut.find_gdb_response('stopped', 'notify', responses):
  37. # does not stoped on breakpoint yet
  38. responses = dut.gdbmi.get_gdb_response(timeout_sec=3)
  39. assert dut.find_gdb_response('stopped', 'notify', responses) is not None
  40. payload = dut.find_gdb_response('stopped', 'notify', responses)['payload']
  41. assert payload['reason'] == 'end-stepping-range'
  42. assert payload['frame']['func'] == 'foo'
  43. assert payload['frame']['line'] == '14'
  44. assert payload['stopped-threads'] == 'all'
  45. # Test finish command
  46. cmd = '-exec-finish'
  47. responses = dut.gdb_write(cmd)
  48. assert dut.find_gdb_response('running', 'result', responses) is not None
  49. if not dut.find_gdb_response('stopped', 'notify', responses):
  50. # does not stoped on breakpoint yet
  51. responses = dut.gdbmi.get_gdb_response(timeout_sec=3)
  52. assert dut.find_gdb_response('stopped', 'notify', responses) is not None
  53. payload = dut.find_gdb_response('stopped', 'notify', responses)['payload']
  54. assert payload['reason'] == 'function-finished'
  55. assert payload['frame']['line'] == '23'
  56. assert payload['frame']['func'] == 'app_main'
  57. assert payload['stopped-threads'] == 'all'
  58. # Test next command
  59. cmd = '-exec-next'
  60. responses = dut.gdb_write(cmd)
  61. assert dut.find_gdb_response('running', 'result', responses) is not None
  62. if not dut.find_gdb_response('stopped', 'notify', responses):
  63. # does not stoped on breakpoint yet
  64. responses = dut.gdbmi.get_gdb_response(timeout_sec=3)
  65. assert dut.find_gdb_response('stopped', 'notify', responses) is not None
  66. payload = dut.find_gdb_response('stopped', 'notify', responses)['payload']
  67. assert payload['reason'] == 'end-stepping-range'
  68. assert payload['frame']['line'] == '21'
  69. assert payload['frame']['func'] == 'app_main'
  70. assert payload['stopped-threads'] == 'all'
  71. # test delete breakpoint
  72. cmd = '-break-delete 1'
  73. responses = dut.gdb_write(cmd)
  74. assert dut.find_gdb_response('done', 'result', responses) is not None
  75. cmd = '-exec-continue'
  76. responses = dut.gdb_write(cmd)
  77. assert dut.find_gdb_response('running', 'result', responses) is not None
  78. assert dut.find_gdb_response('running', 'notify', responses) is not None
  79. # test ctrl-c
  80. responses = dut.gdbmi.send_signal_to_gdb(2)
  81. # assert dut.find_gdb_response('stopped', 'notify', responses) is not None
  82. # ?? No response? check we stopped
  83. dut.gdb_backtrace()
  84. # test watchpoint
  85. cmd = '-break-watch var_2'
  86. responses = dut.gdb_write(cmd)
  87. assert dut.find_gdb_response('done', 'result', responses) is not None
  88. cmd = '-exec-continue'
  89. responses = dut.gdb_write(cmd)
  90. assert dut.find_gdb_response('running', 'result', responses) is not None
  91. if not dut.find_gdb_response('stopped', 'notify', responses):
  92. # does not stoped on breakpoint yet
  93. responses = dut.gdbmi.get_gdb_response(timeout_sec=3)
  94. payload = dut.find_gdb_response('stopped', 'notify', responses)['payload']
  95. assert payload['reason'] == 'signal-received'
  96. assert payload['frame']['func'] == 'foo'
  97. assert payload['stopped-threads'] == 'all'
  98. # Uncomment this when implement send reason to gdb: GCC-313
  99. #
  100. # assert payload['reason'] == 'watchpoint-trigger'
  101. # assert int(payload['value']['new']) == int(payload['value']['old']) + 1
  102. # assert payload['frame']['line'] == '14'