test: pytest_gdb.py avoid LIBUSB_ERROR_BUSY
stop using `shell=True`
use `terminate()`
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
+import logging
import os
import re
-import signal
import subprocess
import sys
import pexpect
import pytest
-from pytest_embedded import Dut
+from pytest_embedded_idf import IdfDut
try:
from idf_py_actions.debug_ext import get_openocd_arguments
@@ -28,7 +28,13 @@ def test_idf_gdb(dut: IdfDut) -> None:
dut.serial.stop_redirect_thread()
with open(os.path.join(dut.logdir, 'ocd.txt'), 'w') as ocd_log:
- ocd = subprocess.Popen(f'openocd {get_openocd_arguments(dut.target)}', stdout=ocd_log, stderr=ocd_log, shell=True)
+ cmd = ['openocd', *get_openocd_arguments(dut.target).split()]
+ openocd_scripts = os.getenv('OPENOCD_SCRIPTS')
+ if openocd_scripts:
+ cmd.extend(['-s', openocd_scripts])
+
+ logging.info('Running %s', cmd)
+ ocd = subprocess.Popen(cmd, stdout=ocd_log, stderr=ocd_log)
try:
gdb_env = os.environ.copy()
@@ -45,9 +51,5 @@ def test_idf_gdb(dut: IdfDut) -> None:
p.expect(re.compile(r'add symbol table from file.*rom.elf'))
p.expect_exact('hit Temporary breakpoint 1, app_main ()')
finally:
- try:
- ocd.send_signal(signal.SIGINT)
- ocd.communicate(timeout=15)
- except subprocess.TimeoutExpired:
+ ocd.terminate()
ocd.kill()
- ocd.communicate()
