mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-14 22:16:46 +00:00
ci: use shared OpenOCD class for GDB test app
This commit is contained in:
@@ -1,25 +1,18 @@
|
|||||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import typing
|
||||||
import sys
|
|
||||||
|
|
||||||
import pexpect
|
import pexpect
|
||||||
import pytest
|
import pytest
|
||||||
from pytest_embedded_idf import IdfDut
|
from pytest_embedded_idf import IdfDut
|
||||||
|
|
||||||
try:
|
if typing.TYPE_CHECKING:
|
||||||
from idf_py_actions.debug_ext import get_openocd_arguments
|
from conftest import OpenOCD
|
||||||
except ModuleNotFoundError:
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
|
||||||
from idf_py_actions.debug_ext import get_openocd_arguments
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.supported_targets
|
def _test_idf_gdb(openocd_dut: 'OpenOCD', dut: IdfDut) -> None:
|
||||||
@pytest.mark.jtag
|
|
||||||
def test_idf_gdb(dut: IdfDut) -> None:
|
|
||||||
# Need to wait a moment to connect via OpenOCD after the hard reset happened.
|
# Need to wait a moment to connect via OpenOCD after the hard reset happened.
|
||||||
# Along with this check that app runs ok
|
# Along with this check that app runs ok
|
||||||
dut.expect('Hello world!')
|
dut.expect('Hello world!')
|
||||||
@@ -27,29 +20,34 @@ def test_idf_gdb(dut: IdfDut) -> None:
|
|||||||
# Don't need to have output from UART anymore
|
# Don't need to have output from UART anymore
|
||||||
dut.serial.stop_redirect_thread()
|
dut.serial.stop_redirect_thread()
|
||||||
|
|
||||||
with open(os.path.join(dut.logdir, 'ocd.txt'), 'w') as ocd_log:
|
gdb_env = os.environ.copy()
|
||||||
cmd = ['openocd', *get_openocd_arguments(dut.target).split()]
|
gdb_env['ESP_IDF_GDB_TESTING'] = '1'
|
||||||
openocd_scripts = os.getenv('OPENOCD_SCRIPTS')
|
|
||||||
if openocd_scripts:
|
|
||||||
cmd.extend(['-s', openocd_scripts])
|
|
||||||
|
|
||||||
logging.info('Running %s', cmd)
|
with openocd_dut.run(), open(os.path.join(dut.logdir, 'gdb.txt'), 'w') as gdb_log, pexpect.spawn(
|
||||||
ocd = subprocess.Popen(cmd, stdout=ocd_log, stderr=ocd_log)
|
f'idf.py -B {dut.app.binary_path} gdb --batch',
|
||||||
|
env=gdb_env,
|
||||||
|
timeout=60,
|
||||||
|
logfile=gdb_log,
|
||||||
|
encoding='utf-8',
|
||||||
|
codec_errors='ignore',
|
||||||
|
) as p:
|
||||||
|
p.expect(re.compile(r'add symbol table from file.*bootloader.elf'))
|
||||||
|
p.expect(re.compile(r'add symbol table from file.*rom.elf'))
|
||||||
|
p.expect_exact('hit Temporary breakpoint 1, app_main ()')
|
||||||
|
|
||||||
try:
|
|
||||||
gdb_env = os.environ.copy()
|
|
||||||
gdb_env['ESP_IDF_GDB_TESTING'] = '1'
|
|
||||||
|
|
||||||
with open(os.path.join(dut.logdir, 'gdb.txt'), 'w') as gdb_log, \
|
@pytest.mark.jtag
|
||||||
pexpect.spawn(f'idf.py -B {dut.app.binary_path} gdb --batch',
|
@pytest.mark.esp32
|
||||||
env=gdb_env,
|
@pytest.mark.esp32s2
|
||||||
timeout=60,
|
@pytest.mark.esp32c2
|
||||||
logfile=gdb_log,
|
def test_idf_gdb(openocd_dut: 'OpenOCD', dut: IdfDut) -> None:
|
||||||
encoding='utf-8',
|
_test_idf_gdb(openocd_dut, dut)
|
||||||
codec_errors='ignore') as p:
|
|
||||||
p.expect(re.compile(r'add symbol table from file.*bootloader.elf'))
|
|
||||||
p.expect(re.compile(r'add symbol table from file.*rom.elf'))
|
@pytest.mark.usb_serial_jtag
|
||||||
p.expect_exact('hit Temporary breakpoint 1, app_main ()')
|
@pytest.mark.esp32c3
|
||||||
finally:
|
@pytest.mark.esp32s3
|
||||||
ocd.terminate()
|
@pytest.mark.esp32c6
|
||||||
ocd.kill()
|
@pytest.mark.esp32h2
|
||||||
|
def test_idf_gdb_usj(openocd_dut: 'OpenOCD', dut: IdfDut) -> None:
|
||||||
|
_test_idf_gdb(openocd_dut, dut)
|
||||||
|
Reference in New Issue
Block a user