example_test.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import unicode_literals
  2. import os
  3. import re
  4. import tempfile
  5. from io import open
  6. import debug_backend
  7. import ttfw_idf
  8. @ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
  9. def test_examples_sysview_tracing_heap_log(env, extra_data):
  10. rel_project_path = os.path.join('examples', 'system', 'sysview_tracing_heap_log')
  11. dut = env.get_dut('sysview_tracing_heap_log', rel_project_path)
  12. proj_path = os.path.join(dut.app.idf_path, rel_project_path)
  13. elf_path = os.path.join(dut.app.binary_path, 'sysview_tracing_heap_log.elf')
  14. def get_temp_file():
  15. with tempfile.NamedTemporaryFile(delete=False) as f:
  16. return f.name
  17. try:
  18. tempfiles = [get_temp_file(), get_temp_file()]
  19. with open(os.path.join(proj_path, 'gdbinit')) as f_in, open(tempfiles[0], 'w') as f_out:
  20. new_content = f_in.read()
  21. # localhost connection issue occurs in docker unless:
  22. new_content = new_content.replace(':3333', '127.0.0.1:3333', 1)
  23. new_content = new_content.replace('file:///tmp/heap_log.svdat', 'file://{}'.format(tempfiles[1]), 1)
  24. f_out.write(new_content)
  25. with ttfw_idf.OCDBackend(os.path.join(proj_path, 'openocd.log'), dut.app.target):
  26. dut.start_app()
  27. dut.expect('esp_apptrace: Initialized TRAX on CPU0')
  28. gdb_log = os.path.join(proj_path, 'gdb.log')
  29. gdb_workdir = os.path.join(proj_path, 'main')
  30. with ttfw_idf.GDBBackend(gdb_log, elf_path, dut.app.target, tempfiles[0], gdb_workdir) as p:
  31. for _ in range(2): # There are two breakpoints
  32. p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING)
  33. stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED)
  34. assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason)
  35. # dut has been restarted by gdb since the last dut.expect()
  36. dut.expect('esp_apptrace: Initialized TRAX on CPU0')
  37. with ttfw_idf.CustomProcess(' '.join([os.path.join(dut.app.idf_path, 'tools/esp_app_trace/sysviewtrace_proc.py'),
  38. '-p',
  39. '-b', elf_path,
  40. tempfiles[1]]),
  41. logfile='sysviewtrace_proc.log') as sysviewtrace:
  42. sysviewtrace.pexpect_proc.expect(re.compile(r'Found \d+ leaked bytes in \d+ blocks.'), timeout=120)
  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_heap_log()