2023-01-20 10:43:12 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
2022-12-01 09:40:03 +00:00
|
|
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
|
import os.path
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pexpect.fdpexpect
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded_idf import IdfDut
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.jtag
|
2023-06-27 08:02:36 +00:00
|
|
|
@pytest.mark.parametrize('config', ['app_trace_jtag'], indirect=True)
|
|
|
|
@pytest.mark.parametrize('embedded_services', ['esp,idf,jtag'], indirect=True)
|
2022-12-01 09:40:03 +00:00
|
|
|
def test_examples_sysview_tracing_heap_log(idf_path: str, dut: IdfDut) -> None:
|
2023-01-20 10:43:12 +00:00
|
|
|
trace_log = os.path.join(os.path.dirname(dut.gdb._logfile), 'heap_log.svdat') # pylint: disable=protected-access
|
|
|
|
|
2022-12-01 09:40:03 +00:00
|
|
|
dut.gdb.write('mon reset halt')
|
|
|
|
dut.gdb.write('flushregs')
|
|
|
|
|
|
|
|
dut.gdb.write('tb heap_trace_start')
|
|
|
|
dut.gdb.write('commands', non_blocking=True)
|
2023-01-20 10:43:12 +00:00
|
|
|
dut.gdb.write(f'mon esp sysview start file://{trace_log}', non_blocking=True)
|
2022-12-01 09:40:03 +00:00
|
|
|
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')
|
|
|
|
|
2023-01-20 10:43:12 +00:00
|
|
|
dut.gdb.write('c')
|
2022-12-01 09:40:03 +00:00
|
|
|
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,
|
2023-01-20 10:43:12 +00:00
|
|
|
trace_log])) as sysviewtrace:
|
2022-12-01 09:40:03 +00:00
|
|
|
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)
|