[PULL v2 40/44] gdbstub: add test for untimely stop-reply packets

Taylor Simpson posted 44 patches 1 year, 4 months ago
Maintainers: Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Thomas Huth <thuth@redhat.com>, Taylor Simpson <tsimpson@quicinc.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Alessandro Di Federico <ale@rev.ng>, Anton Johansson <anjo@rev.ng>
[PULL v2 40/44] gdbstub: add test for untimely stop-reply packets
Posted by Taylor Simpson 1 year, 4 months ago
From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>

In the previous commit, we modified gdbstub.c to only send stop-reply
packets as a response to GDB commands that accept it. Now, let's add a
test for this intended behavior. Running this test before the fix from
the previous commit fails as QEMU sends a stop-reply packet
asynchronously, when GDB was in fact waiting an ACK.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Acked-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
Message-Id: <a30d93b9a8d66e9d9294354cfa2fc3af35f00202.1683214375.git.quic_mathbern@quicinc.com>
---
 tests/guest-debug/run-test.py                    | 16 ++++++++++++----
 .../tcg/multiarch/system/Makefile.softmmu-target | 16 +++++++++++++++-
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/tests/guest-debug/run-test.py b/tests/guest-debug/run-test.py
index d865e46ecd..de6106a5e5 100755
--- a/tests/guest-debug/run-test.py
+++ b/tests/guest-debug/run-test.py
@@ -26,11 +26,12 @@ def get_args():
     parser.add_argument("--qargs", help="Qemu arguments for test")
     parser.add_argument("--binary", help="Binary to debug",
                         required=True)
-    parser.add_argument("--test", help="GDB test script",
-                        required=True)
+    parser.add_argument("--test", help="GDB test script")
     parser.add_argument("--gdb", help="The gdb binary to use",
                         default=None)
+    parser.add_argument("--gdb-args", help="Additional gdb arguments")
     parser.add_argument("--output", help="A file to redirect output to")
+    parser.add_argument("--stderr", help="A file to redirect stderr to")
 
     return parser.parse_args()
 
@@ -58,6 +59,10 @@ def log(output, msg):
         output = open(args.output, "w")
     else:
         output = None
+    if args.stderr:
+        stderr = open(args.stderr, "w")
+    else:
+        stderr = None
 
     socket_dir = TemporaryDirectory("qemu-gdbstub")
     socket_name = os.path.join(socket_dir.name, "gdbstub.socket")
@@ -77,6 +82,8 @@ def log(output, msg):
 
     # Now launch gdb with our test and collect the result
     gdb_cmd = "%s %s" % (args.gdb, args.binary)
+    if args.gdb_args:
+        gdb_cmd += " %s" % (args.gdb_args)
     # run quietly and ignore .gdbinit
     gdb_cmd += " -q -n -batch"
     # disable prompts in case of crash
@@ -84,13 +91,14 @@ def log(output, msg):
     # connect to remote
     gdb_cmd += " -ex 'target remote %s'" % (socket_name)
     # finally the test script itself
-    gdb_cmd += " -x %s" % (args.test)
+    if args.test:
+        gdb_cmd += " -x %s" % (args.test)
 
 
     sleep(1)
     log(output, "GDB CMD: %s" % (gdb_cmd))
 
-    result = subprocess.call(gdb_cmd, shell=True, stdout=output)
+    result = subprocess.call(gdb_cmd, shell=True, stdout=output, stderr=stderr)
 
     # A result of greater than 128 indicates a fatal signal (likely a
     # crash due to gdb internal failure). That's a problem for GDB and
diff --git a/tests/tcg/multiarch/system/Makefile.softmmu-target b/tests/tcg/multiarch/system/Makefile.softmmu-target
index 5f432c95f3..fe40195d39 100644
--- a/tests/tcg/multiarch/system/Makefile.softmmu-target
+++ b/tests/tcg/multiarch/system/Makefile.softmmu-target
@@ -27,6 +27,20 @@ run-gdbstub-memory: memory
 		"-monitor none -display none -chardev file$(COMMA)path=$<.out$(COMMA)id=output $(QEMU_OPTS)" \
 		--bin $< --test $(MULTIARCH_SRC)/gdbstub/memory.py, \
 	softmmu gdbstub support)
+
+run-gdbstub-untimely-packet: hello
+	$(call run-test, $@, $(GDB_SCRIPT) \
+		--gdb $(HAVE_GDB_BIN) \
+		--gdb-args "-ex 'set debug remote 1'" \
+		--output untimely-packet.gdb.out \
+		--stderr untimely-packet.gdb.err \
+		--qemu $(QEMU) \
+		--bin $< --qargs \
+		"-monitor none -display none -chardev file$(COMMA)path=untimely-packet.out$(COMMA)id=output $(QEMU_OPTS)", \
+	"softmmu gdbstub untimely packets")
+	$(call quiet-command, \
+		(! grep -Fq 'Packet instead of Ack, ignoring it' untimely-packet.gdb.err), \
+		"GREP", "file  untimely-packet.gdb.err")
 else
 run-gdbstub-%:
 	$(call skip-test, "gdbstub test $*", "no guest arch support")
@@ -36,4 +50,4 @@ run-gdbstub-%:
 	$(call skip-test, "gdbstub test $*", "need working gdb")
 endif
 
-MULTIARCH_RUNS += run-gdbstub-memory
+MULTIARCH_RUNS += run-gdbstub-memory run-gdbstub-untimely-packet
-- 
2.25.1

Re: [PULL v2 40/44] gdbstub: add test for untimely stop-reply packets
Posted by Richard Henderson 1 year, 1 month ago
On 5/18/23 13:04, Taylor Simpson wrote:
> From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> 
> In the previous commit, we modified gdbstub.c to only send stop-reply
> packets as a response to GDB commands that accept it. Now, let's add a
> test for this intended behavior. Running this test before the fix from
> the previous commit fails as QEMU sends a stop-reply packet
> asynchronously, when GDB was in fact waiting an ACK.
> 
> Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> Acked-by: Alex Bennée <alex.bennee@linaro.org>
> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> Message-Id: <a30d93b9a8d66e9d9294354cfa2fc3af35f00202.1683214375.git.quic_mathbern@quicinc.com>
> ---
>   tests/guest-debug/run-test.py                    | 16 ++++++++++++----
>   .../tcg/multiarch/system/Makefile.softmmu-target | 16 +++++++++++++++-
>   2 files changed, 27 insertions(+), 5 deletions(-)

This test is failing for me on x86_64 and aarch64 host, aarch64 guest:


qemu-system-aarch64: -gdb unix:path=/tmp/tmptlr0fa8hqemu-gdbstub/gdbstub.socket,server=on: 
info: QEMU waiting for connection on: 
disconnected:unix:/tmp/tmptlr0fa8hqemu-gdbstub/gdbstub.socket,server=on
qemu-system-aarch64: warning: gdbstub: client sent packet while target running

   GREP    file
   untimely-packet.gdb.err
make[1]: *** [/home/rth/qemu/src/tests/tcg/multiarch/system/Makefile.softmmu-target:33: 
run-gdbstub-untimely-packet] Error 1

$ gdb --version
GNU gdb (Debian 13.1-3) 13.1


r~

Re: [PULL v2 40/44] gdbstub: add test for untimely stop-reply packets
Posted by Matheus Tavares Bernardino 1 year, 1 month ago
Hi, Richard

Richard Henderson <richard.henderson@linaro.org> wrote:
>
> On 5/18/23 13:04, Taylor Simpson wrote:
> > From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> > 
> > In the previous commit, we modified gdbstub.c to only send stop-reply
> > packets as a response to GDB commands that accept it. Now, let's add a
> > test for this intended behavior. Running this test before the fix from
> > the previous commit fails as QEMU sends a stop-reply packet
> > asynchronously, when GDB was in fact waiting an ACK.
> > 
> > Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> > Acked-by: Alex Bennée <alex.bennee@linaro.org>
> > Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> > Message-Id: <a30d93b9a8d66e9d9294354cfa2fc3af35f00202.1683214375.git.quic_mathbern@quicinc.com>
> > ---
> >   tests/guest-debug/run-test.py                    | 16 ++++++++++++----
> >   .../tcg/multiarch/system/Makefile.softmmu-target | 16 +++++++++++++++-
> >   2 files changed, 27 insertions(+), 5 deletions(-)
> 
> This test is failing for me on x86_64 and aarch64 host, aarch64 guest:
> 
> 
> qemu-system-aarch64: -gdb unix:path=/tmp/tmptlr0fa8hqemu-gdbstub/gdbstub.socket,server=on: 
> info: QEMU waiting for connection on: 
> disconnected:unix:/tmp/tmptlr0fa8hqemu-gdbstub/gdbstub.socket,server=on
> qemu-system-aarch64: warning: gdbstub: client sent packet while target running
> 
>    GREP    file
>    untimely-packet.gdb.err
> make[1]: *** [/home/rth/qemu/src/tests/tcg/multiarch/system/Makefile.softmmu-target:33: 
> run-gdbstub-untimely-packet] Error 1

This looks like the recent breakage I reported at
https://lore.kernel.org/qemu-devel/456ed3318421dd7946bdfb5ceda7e05332da368c.1690910333.git.quic_mathbern@quicinc.com/