app_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from __future__ import unicode_literals
  2. from tiny_test_fw import Utility
  3. import debug_backend
  4. import os
  5. import pexpect
  6. import serial
  7. import threading
  8. import time
  9. import ttfw_idf
  10. class SerialThread(object):
  11. def run(self, log_path, exit_event):
  12. with serial.Serial(os.getenv('ESPPORT', '/dev/ttyUSB1'), 115200) as ser, open(log_path, 'wb') as f:
  13. while True:
  14. f.write(ser.read(ser.in_waiting))
  15. if exit_event.is_set():
  16. break
  17. time.sleep(1)
  18. def __init__(self, log_path):
  19. self.exit_event = threading.Event()
  20. self.t = threading.Thread(target=self.run, args=(log_path, self.exit_event,))
  21. self.t.start()
  22. def __enter__(self):
  23. return self
  24. def __exit__(self, type, value, traceback):
  25. self.exit_event.set()
  26. self.t.join(60)
  27. if self.t.is_alive():
  28. Utility.console_log('The pyserial thread is still alive', 'O')
  29. @ttfw_idf.idf_custom_test(env_tag="test_jtag_arm", group="test-apps")
  30. def test_app_loadable_elf(env, extra_data):
  31. rel_project_path = os.path.join('tools', 'test_apps', 'system', 'gdb_loadable_elf')
  32. app_files = ['gdb_loadable_elf.elf']
  33. app = ttfw_idf.LoadableElfTestApp(rel_project_path, app_files, target="esp32")
  34. idf_path = app.get_sdk_path()
  35. proj_path = os.path.join(idf_path, rel_project_path)
  36. elf_path = os.path.join(app.binary_path, 'gdb_loadable_elf.elf')
  37. esp_log_path = os.path.join(proj_path, 'esp.log')
  38. with SerialThread(esp_log_path):
  39. openocd_log = os.path.join(proj_path, 'openocd.log')
  40. gdb_log = os.path.join(proj_path, 'gdb.log')
  41. gdb_init = os.path.join(proj_path, 'gdbinit')
  42. gdb_dir = os.path.join(proj_path, 'main')
  43. with ttfw_idf.OCDBackend(openocd_log, app.target):
  44. with ttfw_idf.GDBBackend(gdb_log, elf_path, app.target, gdb_init, gdb_dir) as p:
  45. def wait_for_breakpoint():
  46. p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING)
  47. stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED)
  48. assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason)
  49. wait_for_breakpoint()
  50. p.gdb.add_bp('esp_restart')
  51. p.gdb.exec_continue()
  52. wait_for_breakpoint()
  53. if pexpect.run('grep "Restarting now." {}'.format(esp_log_path), withexitstatus=True)[1]:
  54. raise RuntimeError('Expected output from ESP was not received')
  55. if __name__ == '__main__':
  56. test_app_loadable_elf()