example_test.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from __future__ import unicode_literals
  2. from io import open
  3. import debug_backend
  4. import os
  5. import re
  6. import tempfile
  7. import time
  8. import ttfw_idf
  9. @ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
  10. def test_examples_sysview_tracing(env, extra_data):
  11. rel_project_path = os.path.join('examples', 'system', 'sysview_tracing')
  12. dut = env.get_dut('sysview_tracing', rel_project_path)
  13. idf_path = dut.app.get_sdk_path()
  14. proj_path = os.path.join(idf_path, rel_project_path)
  15. elf_path = os.path.join(dut.app.get_binary_path(rel_project_path), 'sysview_tracing.elf')
  16. def get_temp_file():
  17. with tempfile.NamedTemporaryFile(delete=False) as f:
  18. return f.name
  19. try:
  20. tempfiles = [get_temp_file(), get_temp_file()]
  21. with open(os.path.join(proj_path, 'gdbinit')) as f_in, open(tempfiles[0], 'w') as f_out:
  22. new_content = f_in.read()
  23. # localhost connection issue occurs in docker unless:
  24. new_content = new_content.replace(':3333', '127.0.0.1:3333', 1)
  25. new_content = new_content.replace('file:///tmp/sysview_example.svdat', 'file://{}'.format(tempfiles[1]), 1)
  26. f_out.write(new_content)
  27. with ttfw_idf.OCDBackend(os.path.join(proj_path, 'openocd.log'), dut.app.target) as oocd:
  28. dut.start_app()
  29. def dut_expect_task_event():
  30. dut.expect(re.compile(r'example: Task\[0x3[0-9A-Fa-f]+\]: received event \d+'), timeout=30)
  31. dut_expect_task_event()
  32. gdb_log = os.path.join(proj_path, 'gdb.log')
  33. gdb_workdir = os.path.join(proj_path, 'main')
  34. with ttfw_idf.GDBBackend(gdb_log, elf_path, dut.app.target, tempfiles[0], gdb_workdir) as p:
  35. p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING)
  36. stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED)
  37. assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason)
  38. dut.expect('example: Created task') # dut has been restarted by gdb since the last dut.expect()
  39. dut_expect_task_event()
  40. # Do a sleep while sysview samples are captured.
  41. time.sleep(3)
  42. # GDBMI isn't responding now to any commands, therefore, the following command is issued to openocd
  43. oocd.cmd_exec('esp sysview stop')
  44. finally:
  45. for x in tempfiles:
  46. try:
  47. os.unlink(x)
  48. except Exception:
  49. pass
  50. if __name__ == '__main__':
  51. test_examples_sysview_tracing()