test: pytest_gdb.py avoid LIBUSB_ERROR_BUSY

- stop using `shell=True`
- use `terminate()`
This commit is contained in:
Fu Hanxi
2022-12-05 11:03:51 +08:00
parent dc3c630919
commit 1148980383

View File

@@ -1,14 +1,14 @@
# 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 signal
import subprocess import subprocess
import sys import sys
import pexpect import pexpect
import pytest import pytest
from pytest_embedded import Dut from pytest_embedded_idf import IdfDut
try: try:
from idf_py_actions.debug_ext import get_openocd_arguments from idf_py_actions.debug_ext import get_openocd_arguments
@@ -24,11 +24,17 @@ def test_idf_gdb(dut: IdfDut) -> None:
# Along with this check that app runs ok # Along with this check that app runs ok
dut.expect('Hello world!') dut.expect('Hello world!')
# Don't need to have output from UART any more # 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: 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: try:
gdb_env = os.environ.copy() 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(re.compile(r'add symbol table from file.*rom.elf'))
p.expect_exact('hit Temporary breakpoint 1, app_main ()') p.expect_exact('hit Temporary breakpoint 1, app_main ()')
finally: finally:
try: ocd.terminate()
ocd.send_signal(signal.SIGINT)
ocd.communicate(timeout=15)
except subprocess.TimeoutExpired:
ocd.kill() ocd.kill()
ocd.communicate()