app_test.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from __future__ import unicode_literals
  2. import os
  3. import threading
  4. import time
  5. import debug_backend
  6. import pexpect
  7. import serial
  8. import ttfw_idf
  9. from tiny_test_fw import Utility
  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. target = 'esp32'
  34. app = ttfw_idf.LoadableElfTestApp(rel_project_path, app_files, target=target)
  35. idf_path = app.get_sdk_path()
  36. proj_path = os.path.join(idf_path, rel_project_path)
  37. elf_path = os.path.join(app.binary_path, 'gdb_loadable_elf.elf')
  38. esp_log_path = os.path.join(proj_path, 'esp.log')
  39. with SerialThread(esp_log_path):
  40. openocd_log = os.path.join(proj_path, 'openocd.log')
  41. gdb_log = os.path.join(proj_path, 'gdb.log')
  42. gdb_init = os.path.join(proj_path, 'gdbinit_' + target)
  43. gdb_dir = os.path.join(proj_path, 'main')
  44. with ttfw_idf.OCDBackend(openocd_log, app.target):
  45. with ttfw_idf.GDBBackend(gdb_log, elf_path, app.target, gdb_init, gdb_dir) as p:
  46. def wait_for_breakpoint():
  47. p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING)
  48. stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED)
  49. assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason)
  50. wait_for_breakpoint()
  51. p.gdb.add_bp('esp_restart')
  52. p.gdb.exec_continue()
  53. wait_for_breakpoint()
  54. if pexpect.run('grep "Restarting now." {}'.format(esp_log_path), withexitstatus=True)[1]:
  55. raise RuntimeError('Expected output from ESP was not received')
  56. if __name__ == '__main__':
  57. test_app_loadable_elf()