2020-04-16 08:42:33 -04:00
|
|
|
from __future__ import unicode_literals
|
2021-01-25 21:49:01 -05:00
|
|
|
|
2019-07-22 10:04:03 -04:00
|
|
|
import os
|
2020-05-19 08:27:31 -04:00
|
|
|
import threading
|
|
|
|
import time
|
2021-01-25 21:49:01 -05:00
|
|
|
|
|
|
|
import debug_backend
|
|
|
|
import pexpect
|
|
|
|
import serial
|
2019-11-26 22:58:07 -05:00
|
|
|
import ttfw_idf
|
2021-01-25 21:49:01 -05:00
|
|
|
from tiny_test_fw import Utility
|
2019-07-22 10:04:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
class SerialThread(object):
|
|
|
|
def run(self, log_path, exit_event):
|
2020-05-04 13:10:06 -04:00
|
|
|
with serial.Serial(os.getenv('ESPPORT', '/dev/ttyUSB1'), 115200) as ser, open(log_path, 'wb') as f:
|
2019-07-22 10:04:03 -04:00
|
|
|
while True:
|
|
|
|
f.write(ser.read(ser.in_waiting))
|
|
|
|
if exit_event.is_set():
|
|
|
|
break
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
def __init__(self, log_path):
|
|
|
|
self.exit_event = threading.Event()
|
|
|
|
self.t = threading.Thread(target=self.run, args=(log_path, self.exit_event,))
|
|
|
|
self.t.start()
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback):
|
|
|
|
self.exit_event.set()
|
|
|
|
self.t.join(60)
|
|
|
|
if self.t.is_alive():
|
|
|
|
Utility.console_log('The pyserial thread is still alive', 'O')
|
|
|
|
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
@ttfw_idf.idf_custom_test(env_tag='test_jtag_arm', group='test-apps')
|
2020-04-16 08:42:33 -04:00
|
|
|
def test_app_loadable_elf(env, extra_data):
|
|
|
|
rel_project_path = os.path.join('tools', 'test_apps', 'system', 'gdb_loadable_elf')
|
2020-05-05 03:44:53 -04:00
|
|
|
app_files = ['gdb_loadable_elf.elf']
|
2021-02-01 03:53:13 -05:00
|
|
|
target = 'esp32'
|
|
|
|
app = ttfw_idf.LoadableElfTestApp(rel_project_path, app_files, target=target)
|
2020-04-17 05:51:00 -04:00
|
|
|
idf_path = app.get_sdk_path()
|
2019-07-22 10:04:03 -04:00
|
|
|
proj_path = os.path.join(idf_path, rel_project_path)
|
2020-04-17 05:51:00 -04:00
|
|
|
elf_path = os.path.join(app.binary_path, 'gdb_loadable_elf.elf')
|
2019-07-22 10:04:03 -04:00
|
|
|
esp_log_path = os.path.join(proj_path, 'esp.log')
|
|
|
|
|
|
|
|
with SerialThread(esp_log_path):
|
2020-03-30 10:26:21 -04:00
|
|
|
openocd_log = os.path.join(proj_path, 'openocd.log')
|
|
|
|
gdb_log = os.path.join(proj_path, 'gdb.log')
|
2021-02-01 03:53:13 -05:00
|
|
|
gdb_init = os.path.join(proj_path, 'gdbinit_' + target)
|
2020-05-19 08:27:31 -04:00
|
|
|
gdb_dir = os.path.join(proj_path, 'main')
|
|
|
|
|
|
|
|
with ttfw_idf.OCDBackend(openocd_log, app.target):
|
|
|
|
with ttfw_idf.GDBBackend(gdb_log, elf_path, app.target, gdb_init, gdb_dir) as p:
|
|
|
|
def wait_for_breakpoint():
|
|
|
|
p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING)
|
|
|
|
stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED)
|
|
|
|
assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason)
|
|
|
|
|
|
|
|
wait_for_breakpoint()
|
|
|
|
|
|
|
|
p.gdb.add_bp('esp_restart')
|
|
|
|
p.gdb.exec_continue()
|
|
|
|
|
|
|
|
wait_for_breakpoint()
|
2019-07-22 10:04:03 -04:00
|
|
|
|
|
|
|
if pexpect.run('grep "Restarting now." {}'.format(esp_log_path), withexitstatus=True)[1]:
|
|
|
|
raise RuntimeError('Expected output from ESP was not received')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-04-16 08:42:33 -04:00
|
|
|
test_app_loadable_elf()
|