app_test.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from __future__ import unicode_literals
  2. import os
  3. import threading
  4. import time
  5. import pexpect
  6. import serial
  7. from tiny_test_fw import Utility
  8. import ttfw_idf
  9. class SerialThread(object):
  10. def run(self, log_path, exit_event):
  11. with serial.Serial(os.getenv('ESPPORT', '/dev/ttyUSB1'), 115200) as ser, open(log_path, 'wb') as f:
  12. while True:
  13. f.write(ser.read(ser.in_waiting))
  14. if exit_event.is_set():
  15. break
  16. time.sleep(1)
  17. def __init__(self, log_path):
  18. self.exit_event = threading.Event()
  19. self.t = threading.Thread(target=self.run, args=(log_path, self.exit_event,))
  20. self.t.start()
  21. def __enter__(self):
  22. return self
  23. def __exit__(self, type, value, traceback):
  24. self.exit_event.set()
  25. self.t.join(60)
  26. if self.t.is_alive():
  27. Utility.console_log('The pyserial thread is still alive', 'O')
  28. @ttfw_idf.idf_custom_test(env_tag="test_jtag_arm", group="test-apps")
  29. def test_app_loadable_elf(env, extra_data):
  30. rel_project_path = os.path.join('tools', 'test_apps', 'system', 'gdb_loadable_elf')
  31. app_files = ['gdb_loadable_elf.elf']
  32. app = ttfw_idf.LoadableElfTestApp(rel_project_path, app_files, target="esp32")
  33. idf_path = app.get_sdk_path()
  34. proj_path = os.path.join(idf_path, rel_project_path)
  35. elf_path = os.path.join(app.binary_path, 'gdb_loadable_elf.elf')
  36. esp_log_path = os.path.join(proj_path, 'esp.log')
  37. with SerialThread(esp_log_path):
  38. openocd_log = os.path.join(proj_path, 'openocd.log')
  39. gdb_log = os.path.join(proj_path, 'gdb.log')
  40. gdb_args = '-x {} --directory={}'.format(os.path.join(proj_path, '.gdbinit.ci'),
  41. os.path.join(proj_path, 'main'))
  42. with ttfw_idf.OCDProcess(openocd_log), ttfw_idf.GDBProcess(gdb_log, elf_path, app.target, gdb_args) as gdb:
  43. i = gdb.pexpect_proc.expect_exact(['Thread 1 hit Temporary breakpoint 2, app_main ()',
  44. 'Load failed'])
  45. if i == 0:
  46. Utility.console_log('gdb is at breakpoint')
  47. elif i == 1:
  48. raise RuntimeError('Load has failed. Please examine the logs.')
  49. else:
  50. Utility.console_log('i = {}'.format(i))
  51. Utility.console_log(str(gdb.pexpect_proc))
  52. # This really should not happen. TIMEOUT and EOF failures are exceptions.
  53. raise RuntimeError('An unknown error has occurred. Please examine the logs.')
  54. gdb.pexpect_proc.expect_exact('(gdb)')
  55. gdb.pexpect_proc.sendline('b esp_restart')
  56. gdb.pexpect_proc.sendline('c')
  57. gdb.pexpect_proc.expect_exact('Thread 1 hit Breakpoint 3, esp_restart ()')
  58. if pexpect.run('grep "Restarting now." {}'.format(esp_log_path), withexitstatus=True)[1]:
  59. raise RuntimeError('Expected output from ESP was not received')
  60. if __name__ == '__main__':
  61. test_app_loadable_elf()