From 7a77109e0d1b0023476690be258cb19d96ec77fe Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Tue, 22 Nov 2022 15:53:14 +0100 Subject: [PATCH] ci: lift restriction on pygdbmi in panic test Backport of 01f1aba2d08042ba6bb9af6ab43ac3d199cfde4d --- .../panic/test_panic_util/test_panic_util.py | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/tools/test_apps/system/panic/test_panic_util/test_panic_util.py b/tools/test_apps/system/panic/test_panic_util/test_panic_util.py index 4be900c5203..bbd444c0441 100644 --- a/tools/test_apps/system/panic/test_panic_util/test_panic_util.py +++ b/tools/test_apps/system/panic/test_panic_util/test_panic_util.py @@ -3,9 +3,10 @@ import re import subprocess import sys +from subprocess import Popen import ttfw_idf -from pygdbmi.gdbcontroller import GdbController, GdbTimeoutError, NoGdbProcessError +from pygdbmi.gdbcontroller import GdbController from tiny_test_fw import DUT, TinyFW, Utility from tiny_test_fw.Utility import CaseConfig, SearchCases @@ -14,6 +15,26 @@ TEST_SUITE = 'Panic' +class NoGdbProcessError(ValueError): + """Raise when trying to interact with gdb subprocess, but it does not exist. + It may have been killed and removed, or failed to initialize for some reason.""" + + pass + + +def verify_valid_gdb_subprocess(gdb_process: Popen) -> None: + """Verify there is a process object, and that it is still running. + Raise NoGdbProcessError if either of the above are not true.""" + if not gdb_process: + raise NoGdbProcessError('gdb process is not attached') + + elif gdb_process.poll() is not None: + raise NoGdbProcessError( + 'gdb process has already finished with return code: %s' + % str(gdb_process.poll()) + ) + + def ok(data): """ Helper function used with dut.expect_any """ pass @@ -160,14 +181,33 @@ def start_gdb(self): self._port_close() Utility.console_log('Starting GDB...', 'orange') - self.gdb = GdbController(gdb_path=self.TOOLCHAIN_PREFIX + 'gdb') - Utility.console_log('Running command: {}'.format(self.gdb.get_subprocess_cmd()), 'orange') + gdb_path = self.TOOLCHAIN_PREFIX + 'gdb' + try: + from pygdbmi.constants import GdbTimeoutError + default_gdb_args = ['--nx', '--quiet', '--interpreter=mi2'] + gdb_command = [gdb_path] + default_gdb_args + self.gdb = GdbController(command=gdb_command) + except ImportError: + # fallback for pygdbmi<0.10.0.0. + from pygdbmi.gdbcontroller import GdbTimeoutError + self.gdb = GdbController(gdb_path=gdb_path) + + try: + gdb_command = self.gdb.command + except AttributeError: + # fallback for pygdbmi < 0.10 + gdb_command = self.gdb.cmd + + Utility.console_log('Running command: {}'.format(gdb_command), 'orange') for _ in range(10): try: # GdbController creates a process with subprocess.Popen(). Is it really running? It is probable that # an RPI under high load will get non-responsive during creating a lot of processes. - resp = self.gdb.get_gdb_response(timeout_sec=10) # calls verify_valid_gdb_subprocess() internally + if not hasattr(self.gdb, 'verify_valid_gdb_subprocess'): + # for pygdbmi >= 0.10.0.0 + verify_valid_gdb_subprocess(self.gdb.gdb_process) + resp = self.gdb.get_gdb_response(timeout_sec=10) # calls verify_valid_gdb_subprocess() internally (pygdbmi < 0.10) # it will be interesting to look up this response if the next GDB command fails (times out) Utility.console_log('GDB response: {}'.format(resp), 'orange') break # success