example_test.py 2.5 KB

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