pytest_app_trace_basic.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. import time
  4. import pexpect
  5. import pytest
  6. from pytest_embedded_idf import IdfDut
  7. from pytest_embedded_jtag import OpenOcd
  8. def apptrace_wait_stop(openocd: OpenOcd, timeout: int = 30) -> None:
  9. stopped = False
  10. end_before = time.time() + timeout
  11. while not stopped:
  12. cmd_out = openocd.write('esp apptrace status')
  13. for line in cmd_out.splitlines():
  14. if line.startswith('Tracing is STOPPED.'):
  15. stopped = True
  16. break
  17. if not stopped and time.time() > end_before:
  18. raise pexpect.TIMEOUT('Failed to wait for apptrace stop!')
  19. time.sleep(1)
  20. @pytest.mark.parametrize(
  21. 'embedded_services, no_gdb',
  22. [
  23. ('esp,idf,jtag', 'y'),
  24. ],
  25. indirect=True,
  26. )
  27. @pytest.mark.parametrize(
  28. 'port, openocd_cli_args', [
  29. pytest.param(None, None, marks=[pytest.mark.esp32, pytest.mark.jtag]),
  30. pytest.param(None, '-f board/esp32s2-kaluga-1.cfg', marks=[pytest.mark.esp32s2, pytest.mark.jtag]),
  31. pytest.param(None, '-f board/esp32c2-ftdi.cfg', marks=[pytest.mark.esp32c2, pytest.mark.jtag]),
  32. pytest.param('/dev/serial_ports/ttyACM-esp32', '-f board/esp32s3-builtin.cfg', marks=[pytest.mark.esp32s3, pytest.mark.usb_serial_jtag]),
  33. pytest.param('/dev/serial_ports/ttyACM-esp32', '-f board/esp32c3-builtin.cfg', marks=[pytest.mark.esp32c3, pytest.mark.usb_serial_jtag]),
  34. ],
  35. indirect=True
  36. )
  37. def test_examples_app_trace_basic(dut: IdfDut, openocd: OpenOcd) -> None:
  38. dut.openocd.write('reset')
  39. dut.expect_exact('example: Waiting for OpenOCD connection', timeout=5)
  40. assert 'Targets connected.' in dut.openocd.write('esp apptrace start file://apptrace.log 0 2000 3 0 0')
  41. apptrace_wait_stop(dut.openocd)
  42. with open(openocd._logfile) as oocd_log: # pylint: disable=protected-access
  43. cores = 1 if dut.app.sdkconfig.get('FREERTOS_UNICORE') is True else 2
  44. params_str = 'App trace params: from {} cores,'.format(cores)
  45. found = False
  46. for line in oocd_log:
  47. if params_str in line:
  48. found = True
  49. break
  50. if found is not True:
  51. raise RuntimeError(
  52. '"{}" could not be found in {}'.format(params_str, openocd._logfile) # pylint: disable=protected-access
  53. )
  54. with open('apptrace.log') as apptrace_log:
  55. for sample_num in range(1, 51):
  56. log_str = 'Apptrace test data[{}]:{}'.format(sample_num, sample_num * sample_num)
  57. found = False
  58. for line in apptrace_log:
  59. if log_str in line:
  60. found = True
  61. break
  62. if found is not True:
  63. raise RuntimeError(
  64. '"{}" could not be found in {}'.format(log_str, 'apptrace.log')
  65. )