qemu-iotests: attach gdbserver to qemu instance
cover qemu-iotests: attach gdbserver to qemu instance
This series adds the option to attach gdbserver to the qemu_system_* instance running in the qemu-iotests.
Patch 1 adds the possibility to set a custom timer for the QMP socket, necessary otherwise the connection will just drop after 15 seconds, making the use of gdb very hard. Patch 2 adds the flag in the python tests (or in general when a test is invoked with the check script), patch 3 adds the same option for the tests done in bash.
This series is tested on the previous serie "qemu-iotests: quality of life improvements"
but independent from it, so it can be applied separately.
Emanuele Giuseppe Esposito (3):
python: qemu: add timer parameter for qmp.accept socket
qemu-iotests: add option to attach gdbserver
qemu-iotests: add gdbserver option to script tests too
python/qemu/machine.py | 8 +++++--- python/qemu/qtest.py | 8 +++++--- tests/qemu-iotests/check | 5 ++++- tests/qemu-iotests/common.rc | 8 +++++++- tests/qemu-iotests/iotests.py | 7 ++++++- tests/qemu-iotests/testenv.py | 15 +++++++++++++-- 6 files changed, 40 insertions(+), 11 deletions(-)
Signature · 1 line
2.30.2
RFC PATCH 1/3 python: qemu: add timer parameter for qmp.accept socket
Extend the _post_launch function to include the timer as parameter instead of defaulting to 15 sec.
--- python/qemu/machine.py | 4 ++-- python/qemu/qtest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
python/qemu/machine.py +2 -2
@@ -321,9 +321,9 @@ def _pre_launch(self) -> None: nickname=self._name ) - def _post_launch(self) -> None: + def _post_launch(self, timer) -> None: if self._qmp_connection: - self._qmp.accept() + self._qmp.accept(timer) def _post_shutdown(self) -> None: """
python/qemu/qtest.py +2 -2
@@ -138,9 +138,9 @@ def _pre_launch(self) -> None: super()._pre_launch() self._qtest = QEMUQtestProtocol(self._qtest_path, server=True) - def _post_launch(self) -> None: + def _post_launch(self, timer) -> None: assert self._qtest is not None - super()._post_launch() + super()._post_launch(timer) self._qtest.accept() def _post_shutdown(self) -> None:
Signature · 1 line
2.30.2
RFC PATCH 2/3 qemu-iotests: add option to attach gdbserver
In reply to Emanuele Giuseppe EspositoAdd -gdb flag and GDB_QEMU environmental variable
to python tests to attach a gdbserver to each qemu_system instance. The GDB_QEMU will just contain the options to provide to gdbserver, if empty and -gdb is set it will default to "localhost:12345".
The gdb option is provided to python/qemu/machine.py through the "wrapper" parameter, currently unused by qemu-iotests.
Attaching a gdbserver implies that the qmp socket should wait indefinitely for an answer from QEMU, otherwise the connection will drop after 15 seconds.
if -gdb is not provided but $GDB_QEMU is set, the script will ignore the environmental variable.
--- python/qemu/machine.py | 4 +++- python/qemu/qtest.py | 4 +++- tests/qemu-iotests/check | 5 ++++- tests/qemu-iotests/iotests.py | 7 ++++++- tests/qemu-iotests/testenv.py | 15 +++++++++++++-- 5 files changed, 29 insertions(+), 6 deletions(-)
python/qemu/machine.py +3 -1
@@ -408,7 +408,9 @@ def _launch(self) -> None: stderr=subprocess.STDOUT, shell=False, close_fds=False) - self._post_launch() + + timer = None if 'gdbserver' in self._wrapper else 15.0 + self._post_launch(timer) def _early_cleanup(self) -> None: """
python/qemu/qtest.py +3 -1
@@ -111,6 +111,7 @@ class QEMUQtestMachine(QEMUMachine): def __init__(self, binary: str, args: Sequence[str] = (), + wrapper: Sequence[str] = (), name: Optional[str] = None, test_dir: str = "/var/tmp", socket_scm_helper: Optional[str] = None,
@@ -119,7 +120,8 @@ def __init__(self, name = "qemu-%d" % os.getpid() if sock_dir is None: sock_dir = test_dir - super().__init__(binary, args, name=name, test_dir=test_dir, + super().__init__(binary, args, wrapper=wrapper, name=name, + test_dir=test_dir, socket_scm_helper=socket_scm_helper, sock_dir=sock_dir) self._qtest: Optional[QEMUQtestProtocol] = None
tests/qemu-iotests/check +4 -1
@@ -36,6 +36,8 @@ def make_argparser() -> argparse.ArgumentParser: help='pretty print output for make check') p.add_argument('-d', dest='debug', action='store_true', help='debug') + p.add_argument('-gdb', action='store_true', + help="start gdb server on localhost. Default port is 12345") p.add_argument('-misalign', action='store_true', help='misalign memory allocations') p.add_argument('--color', choices=['on', 'off', 'auto'],
@@ -115,7 +117,8 @@ if __name__ == '__main__': env = TestEnv(imgfmt=args.imgfmt, imgproto=args.imgproto, aiomode=args.aiomode, cachemode=args.cachemode, imgopts=args.imgopts, misalign=args.misalign, - debug=args.debug, valgrind=args.valgrind) + debug=args.debug, valgrind=args.valgrind, + gdb=args.gdb) if len(sys.argv) > 1 and sys.argv[-len(args.tests)-1] == '--': if not args.tests:
tests/qemu-iotests/iotests.py +6 -1
@@ -74,6 +74,10 @@ qemu_prog = os.environ.get('QEMU_PROG', 'qemu') qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ') +qemu_gdb = [] +if os.environ.get('GDB_QEMU'): + qemu_gdb = ['gdbserver'] + os.environ.get('GDB_QEMU').strip().split(' ') + imgfmt = os.environ.get('IMGFMT', 'raw') imgproto = os.environ.get('IMGPROTO', 'file') output_dir = os.environ.get('OUTPUT_DIR', '.')
@@ -574,7 +578,8 @@ class VM(qtest.QEMUQtestMachine): def __init__(self, path_suffix=''): name = "qemu%s-%d" % (path_suffix, os.getpid()) - super().__init__(qemu_prog, qemu_opts, name=name, + super().__init__(qemu_prog, qemu_opts, wrapper=qemu_gdb, + name=name, test_dir=test_dir, socket_scm_helper=socket_scm_helper, sock_dir=sock_dir)
tests/qemu-iotests/testenv.py +13 -2
@@ -72,7 +72,8 @@ class TestEnv(ContextManager['TestEnv']): 'QEMU_NBD_OPTIONS', 'IMGOPTS', 'IMGFMT', 'IMGPROTO', 'AIOMODE', 'CACHEMODE', 'VALGRIND_QEMU', 'CACHEMODE_IS_DEFAULT', 'IMGFMT_GENERIC', 'IMGOPTSSYNTAX', - 'IMGKEYSECRET', 'QEMU_DEFAULT_MACHINE', 'MALLOC_PERTURB_'] + 'IMGKEYSECRET', 'QEMU_DEFAULT_MACHINE', 'MALLOC_PERTURB_', + 'GDB_QEMU'] def prepare_subprocess(self, args: List[str]) -> Dict[str, str]: if self.debug:
@@ -178,7 +179,8 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str, imgopts: Optional[str] = None, misalign: bool = False, debug: bool = False, - valgrind: bool = False) -> None: + valgrind: bool = False, + gdb: bool = False) -> None: self.imgfmt = imgfmt self.imgproto = imgproto self.aiomode = aiomode
@@ -186,6 +188,14 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str, self.misalign = misalign self.debug = debug + self.gdb_qemu = os.getenv('GDB_QEMU') + + if gdb and not self.gdb_qemu: + self.gdb_qemu = 'localhost:12345' + elif self.gdb_qemu and not gdb: + del self.gdb_qemu + del os.environ['GDB_QEMU'] + if valgrind: self.valgrind_qemu = 'y'
@@ -284,6 +294,7 @@ def print_env(self) -> None: TEST_DIR -- {TEST_DIR} SOCK_DIR -- {SOCK_DIR} SOCKET_SCM_HELPER -- {SOCKET_SCM_HELPER} +GDB_QEMU -- "{GDB_QEMU}" """ args = collections.defaultdict(str, self.get_env())
Signature · 1 line
2.30.2
RFC PATCH 3/3 qemu-iotests: add gdbserver option to script tests too
In reply to Emanuele Giuseppe EspositoThe only limitation here is that running a script with gdbserver will make the test output mismatch with the expected results, making the test fail.
--- tests/qemu-iotests/common.rc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
tests/qemu-iotests/common.rc +7 -1
@@ -166,8 +166,14 @@ _qemu_wrapper() if [ -n "${QEMU_NEED_PID}" ]; then echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" fi + + GDB="${QEMU_PROG}" + if [ ! -z ${GDB_QEMU} ]; then + GDB="gdbserver ${GDB_QEMU} ${GDB}" + fi + VALGRIND_QEMU="${VALGRIND_QEMU_VM}" _qemu_proc_exec "${VALGRIND_LOGFILE}" \ - "$QEMU_PROG" $QEMU_OPTIONS "$@" + $GDB $QEMU_OPTIONS "$@" ) RETVAL=$? _qemu_proc_valgrind_log "${VALGRIND_LOGFILE}" $RETVAL
Signature · 1 line
2.30.2