pytest_sysview_tracing.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. import re
  4. import time
  5. import pexpect.fdpexpect
  6. import pytest
  7. from pytest_embedded_idf import IdfDut
  8. @pytest.mark.esp32
  9. @pytest.mark.jtag
  10. @pytest.mark.parametrize(
  11. 'embedded_services',
  12. [
  13. 'esp,idf,jtag',
  14. ],
  15. indirect=True,
  16. )
  17. def test_examples_sysview_tracing(dut: IdfDut) -> None:
  18. def dut_expect_task_event() -> None:
  19. dut.expect(re.compile(rb'example: Task\[0x3[0-9A-Fa-f]+\]: received event \d+'), timeout=30)
  20. dut.gdb.write('mon reset halt')
  21. dut.gdb.write('maintenance flush register-cache')
  22. dut.gdb.write('b app_main')
  23. dut.gdb.write('commands', non_blocking=True)
  24. dut.gdb.write(
  25. 'mon esp sysview start file:///tmp/sysview_example0.svdat file:///tmp/sysview_example1.svdat', non_blocking=True
  26. )
  27. dut.gdb.write('c', non_blocking=True)
  28. dut.gdb.write('end')
  29. dut.gdb.write('c', non_blocking=True)
  30. time.sleep(1) # to avoid EOF file error
  31. with open(dut.gdb._logfile) as fr: # pylint: disable=protected-access
  32. gdb_pexpect_proc = pexpect.fdpexpect.fdspawn(fr.fileno())
  33. gdb_pexpect_proc.expect('Thread 2 "main" hit Breakpoint 1, app_main ()')
  34. dut.expect('example: Created task') # dut has been restarted by gdb since the last dut.expect()
  35. dut_expect_task_event()
  36. # Do a sleep while sysview samples are captured.
  37. time.sleep(3)
  38. # GDB isn't responding now to any commands, therefore, the following command is issued to openocd
  39. dut.openocd.write('esp sysview stop')