ci: move more openocd scripts into pytest-embedded

This commit is contained in:
Fu Hanxi
2022-12-01 17:40:03 +08:00
parent 09a32437b3
commit dc3c630919
14 changed files with 327 additions and 330 deletions
@@ -1,64 +0,0 @@
from __future__ import unicode_literals
import os
import re
import tempfile
from io import open
import debug_backend
import ttfw_idf
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
def test_examples_sysview_tracing_heap_log(env, extra_data):
rel_project_path = os.path.join('examples', 'system', 'sysview_tracing_heap_log')
dut = env.get_dut('sysview_tracing_heap_log', rel_project_path)
proj_path = os.path.join(dut.app.idf_path, rel_project_path)
elf_path = os.path.join(dut.app.binary_path, 'sysview_tracing_heap_log.elf')
def get_temp_file():
with tempfile.NamedTemporaryFile(delete=False) as f:
return f.name
try:
tempfiles = [get_temp_file(), get_temp_file()]
with open(os.path.join(proj_path, 'gdbinit')) as f_in, open(tempfiles[0], 'w') as f_out:
new_content = f_in.read()
# localhost connection issue occurs in docker unless:
new_content = new_content.replace(':3333', '127.0.0.1:3333', 1)
new_content = new_content.replace('file:///tmp/heap_log.svdat', 'file://{}'.format(tempfiles[1]), 1)
f_out.write(new_content)
with ttfw_idf.OCDBackend(os.path.join(proj_path, 'openocd.log'), dut.app.target):
dut.start_app()
dut.expect('esp_apptrace: Initialized TRAX on CPU0')
gdb_log = os.path.join(proj_path, 'gdb.log')
gdb_workdir = os.path.join(proj_path, 'main')
with ttfw_idf.GDBBackend(gdb_log, elf_path, dut.app.target, tempfiles[0], gdb_workdir) as p:
for _ in range(2): # There are two breakpoints
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)
# dut has been restarted by gdb since the last dut.expect()
dut.expect('esp_apptrace: Initialized TRAX on CPU0')
with ttfw_idf.CustomProcess(' '.join([os.path.join(dut.app.idf_path, 'tools/esp_app_trace/sysviewtrace_proc.py'),
'-p',
'-b', elf_path,
tempfiles[1]]),
logfile='sysviewtrace_proc.log') as sysviewtrace:
sysviewtrace.pexpect_proc.expect(re.compile(r'Found \d+ leaked bytes in \d+ blocks.'), timeout=120)
finally:
for x in tempfiles:
try:
os.unlink(x)
except Exception:
pass
if __name__ == '__main__':
test_examples_sysview_tracing_heap_log()
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
import os.path
import time
import pexpect.fdpexpect
import pytest
from pytest_embedded_idf import IdfDut
TEMP_FILE = os.path.join(os.path.dirname(__file__), 'heap_log.svdat')
@pytest.mark.esp32
@pytest.mark.jtag
@pytest.mark.parametrize('embedded_services', [
'esp,idf,jtag',
], indirect=True)
def test_examples_sysview_tracing_heap_log(idf_path: str, dut: IdfDut) -> None:
dut.gdb.write('mon reset halt')
dut.gdb.write('flushregs')
dut.gdb.write('tb heap_trace_start')
dut.gdb.write('commands', non_blocking=True)
dut.gdb.write(f'mon esp sysview start file://{TEMP_FILE}', non_blocking=True)
dut.gdb.write('c', non_blocking=True)
dut.gdb.write('end')
dut.gdb.write('tb heap_trace_stop')
dut.gdb.write('commands', non_blocking=True)
dut.gdb.write('mon esp sysview stop', non_blocking=True)
dut.gdb.write('end')
dut.gdb.write('c', non_blocking=True)
dut.expect('esp_apptrace: Initialized TRAX on CPU0')
time.sleep(1) # make sure that the sysview file has been generated
with pexpect.spawn(' '.join([os.path.join(idf_path, 'tools', 'esp_app_trace', 'sysviewtrace_proc.py'),
'-p',
'-b', dut.app.elf_file,
TEMP_FILE])) as sysviewtrace:
sysviewtrace.expect(r'Found \d+ leaked bytes in \d+ blocks.', timeout=120)
with open(dut.gdb._logfile) as fr: # pylint: disable=protected-access
gdb_pexpect_proc = pexpect.fdpexpect.fdspawn(fr.fileno())
gdb_pexpect_proc.expect_exact(
'Thread 2 "main" hit Temporary breakpoint 1, heap_trace_start (mode_param=HEAP_TRACE_ALL)', timeout=10)
gdb_pexpect_proc.expect_exact('Thread 2 "main" hit Temporary breakpoint 2, heap_trace_stop ()', timeout=10)