* [RFC PATCH 0/3] qemu-iotests: attach gdbserver to qemu instance
@ 2021-04-01 13:57 Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 1/3] python: qemu: add timer parameter for qmp.accept socket Emanuele Giuseppe Esposito
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2021-04-01 13:57 UTC (permalink / raw)
To: qemu-block
Cc: Kevin Wolf, Emanuele Giuseppe Esposito, Eduardo Habkost,
qemu-devel, Max Reitz, Cleber Rosa, John Snow
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(-)
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [RFC PATCH 1/3] python: qemu: add timer parameter for qmp.accept socket
2021-04-01 13:57 [RFC PATCH 0/3] qemu-iotests: attach gdbserver to qemu instance Emanuele Giuseppe Esposito
@ 2021-04-01 13:57 ` Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 2/3] qemu-iotests: add option to attach gdbserver Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 3/3] qemu-iotests: add gdbserver option to script tests too Emanuele Giuseppe Esposito
2 siblings, 0 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2021-04-01 13:57 UTC (permalink / raw)
To: qemu-block
Cc: Kevin Wolf, Emanuele Giuseppe Esposito, Eduardo Habkost,
qemu-devel, Max Reitz, Cleber Rosa, John Snow
Extend the _post_launch function to include the timer as
parameter instead of defaulting to 15 sec.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
python/qemu/machine.py | 4 ++--
python/qemu/qtest.py | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 6e44bda337..c721e07d63 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -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:
"""
diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py
index 39a0cf62fe..0d01715086 100644
--- a/python/qemu/qtest.py
+++ b/python/qemu/qtest.py
@@ -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:
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH 2/3] qemu-iotests: add option to attach gdbserver
2021-04-01 13:57 [RFC PATCH 0/3] qemu-iotests: attach gdbserver to qemu instance Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 1/3] python: qemu: add timer parameter for qmp.accept socket Emanuele Giuseppe Esposito
@ 2021-04-01 13:57 ` Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 3/3] qemu-iotests: add gdbserver option to script tests too Emanuele Giuseppe Esposito
2 siblings, 0 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2021-04-01 13:57 UTC (permalink / raw)
To: qemu-block
Cc: Kevin Wolf, Emanuele Giuseppe Esposito, Eduardo Habkost,
qemu-devel, Max Reitz, Cleber Rosa, John Snow
Add -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.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
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(-)
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index c721e07d63..d7fca6b3c1 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -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:
"""
diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py
index 0d01715086..4c90daf430 100644
--- a/python/qemu/qtest.py
+++ b/python/qemu/qtest.py
@@ -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
diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check
index df9fd733ff..5a1d0518f1 100755
--- a/tests/qemu-iotests/check
+++ b/tests/qemu-iotests/check
@@ -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:
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 2a34eef601..138cf135ea 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -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)
diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
index 169268f61a..62749becbd 100644
--- a/tests/qemu-iotests/testenv.py
+++ b/tests/qemu-iotests/testenv.py
@@ -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())
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH 3/3] qemu-iotests: add gdbserver option to script tests too
2021-04-01 13:57 [RFC PATCH 0/3] qemu-iotests: attach gdbserver to qemu instance Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 1/3] python: qemu: add timer parameter for qmp.accept socket Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 2/3] qemu-iotests: add option to attach gdbserver Emanuele Giuseppe Esposito
@ 2021-04-01 13:57 ` Emanuele Giuseppe Esposito
2 siblings, 0 replies; 4+ messages in thread
From: Emanuele Giuseppe Esposito @ 2021-04-01 13:57 UTC (permalink / raw)
To: qemu-block
Cc: Kevin Wolf, Emanuele Giuseppe Esposito, Eduardo Habkost,
qemu-devel, Max Reitz, Cleber Rosa, John Snow
The only limitation here is that running a script with gdbserver
will make the test output mismatch with the expected
results, making the test fail.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
tests/qemu-iotests/common.rc | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 65cdba5723..53a3310fee 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -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
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-01 14:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 13:57 [RFC PATCH 0/3] qemu-iotests: attach gdbserver to qemu instance Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 1/3] python: qemu: add timer parameter for qmp.accept socket Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 2/3] qemu-iotests: add option to attach gdbserver Emanuele Giuseppe Esposito
2021-04-01 13:57 ` [RFC PATCH 3/3] qemu-iotests: add gdbserver option to script tests too Emanuele Giuseppe Esposito
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).