aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/multiarch/gdbstub/interrupt.py
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2023-08-31 08:29:00 -0400
committerStefan Hajnoczi <stefanha@redhat.com>2023-08-31 08:29:00 -0400
commitdb1a88a5acc0df7d8a941aa772ef63c8941d1893 (patch)
tree67cb563f7738f508faaf35cab798fabf70b8f1fa /tests/tcg/multiarch/gdbstub/interrupt.py
parent156618d9ea67f2f2e31d9dedd97f2dcccbe6808c (diff)
parent8dd7a4b3487ab93ff8fddc5f818942ff39d4550f (diff)
Merge tag 'pull-maintainer-ominbus-300823-1' of https://gitlab.com/stsquad/qemu into staging
testing and gdbstub updates: - enable ccache for gitlab builds - fix various test info leakages for non V=1 - update style to allow loop vars - bump FreeBSD to v13.2 - clean-up gdbstub tests - various gdbstub doc and refactorings # -----BEGIN PGP SIGNATURE----- # # iQEzBAABCgAdFiEEZoWumedRZ7yvyN81+9DbCVqeKkQFAmTvS2AACgkQ+9DbCVqe # KkRiRwgAhsinp2/KgnvkD0n6deQy/JWg9MfYIvvZacKEakIfQvCDoJ752AUZzUTw # ggQ+W2KuaoHTzwG+AOMLdzulkmspQ8xeFuD2aIpFjRMnZrO9jN2T4L0vcGLAd95c # 9QLqPeH8xRdhuK28+ILuYzKOKBcefQ44ufMLpxrS2iNITEsSg/Tw3MU91hbct49g # 3OR4bD1ueG5Ib/lXp8V/4GnRmfLdnp3k0i/6OHriq7Mpz4Lia67WblVsPEple66U # n7JCo2sI5/m+6p2tvKs7rH60xc8s1Za3kbK4ggEq3LVRfzVOordZqO+1ep6wklTY # 6nP9Ry9nZG3gqCmcNXfhoofm0vHaZA== # =Km9m # -----END PGP SIGNATURE----- # gpg: Signature made Wed 30 Aug 2023 10:00:00 EDT # gpg: using RSA key 6685AE99E75167BCAFC8DF35FBD0DB095A9E2A44 # gpg: Good signature from "Alex Bennée (Master Work Key) <alex.bennee@linaro.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: 6685 AE99 E751 67BC AFC8 DF35 FBD0 DB09 5A9E 2A44 * tag 'pull-maintainer-ominbus-300823-1' of https://gitlab.com/stsquad/qemu: gdbstub: move comment for gdb_register_coprocessor gdbstub: replace global gdb_has_xml with a function gdbstub: refactor get_feature_xml gdbstub: remove unused user_ctx field gdbstub: fixes cases where wrong threads were reported to GDB on SIGINT tests/tcg: clean-up gdb confirm/pagination settings tests: remove test-gdbstub.py .gitlab-ci.d/cirrus.yml: Update FreeBSD to v13.2 docs/style: permit inline loop variables tests/tcg: remove quoting for info output tests/docker: cleanup non-verbose output gitlab: enable ccache for many build jobs Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'tests/tcg/multiarch/gdbstub/interrupt.py')
-rw-r--r--tests/tcg/multiarch/gdbstub/interrupt.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/gdbstub/interrupt.py b/tests/tcg/multiarch/gdbstub/interrupt.py
new file mode 100644
index 0000000000..e222ac94c5
--- /dev/null
+++ b/tests/tcg/multiarch/gdbstub/interrupt.py
@@ -0,0 +1,97 @@
+from __future__ import print_function
+#
+# Test some of the softmmu debug features with the multiarch memory
+# test. It is a port of the original vmlinux focused test case but
+# using the "memory" test instead.
+#
+# This is launched via tests/guest-debug/run-test.py
+#
+
+import gdb
+import sys
+
+failcount = 0
+
+
+def report(cond, msg):
+ "Report success/fail of test"
+ if cond:
+ print("PASS: %s" % (msg))
+ else:
+ print("FAIL: %s" % (msg))
+ global failcount
+ failcount += 1
+
+
+def check_interrupt(thread):
+ """
+ Check that, if thread is resumed, we go back to the same thread when the
+ program gets interrupted.
+ """
+
+ # Switch to the thread we're going to be running the test in.
+ print("thread ", thread.num)
+ gdb.execute("thr %d" % thread.num)
+
+ # Enter the loop() function on this thread.
+ #
+ # While there are cleaner ways to do this, we want to minimize the number of
+ # side effects on the gdbstub's internal state, since those may mask bugs.
+ # Ideally, there should be no difference between what we're doing here and
+ # the program reaching the loop() function on its own.
+ #
+ # For this to be safe, we only need the prologue of loop() to not have
+ # instructions that may have problems with what we're doing here. We don't
+ # have to worry about anything else, as this function never returns.
+ gdb.execute("set $pc = loop")
+
+ # Continue and then interrupt the task.
+ gdb.post_event(lambda: gdb.execute("interrupt"))
+ gdb.execute("c")
+
+ # Check whether the thread we're in after the interruption is the same we
+ # ran continue from.
+ return (thread.num == gdb.selected_thread().num)
+
+
+def run_test():
+ """
+ Test if interrupting the code always lands us on the same thread when
+ running with scheduler-lock enabled.
+ """
+
+ gdb.execute("set scheduler-locking on")
+ for thread in gdb.selected_inferior().threads():
+ report(check_interrupt(thread),
+ "thread %d resumes correctly on interrupt" % thread.num)
+
+
+#
+# This runs as the script it sourced (via -x, via run-test.py)
+#
+try:
+ inferior = gdb.selected_inferior()
+ arch = inferior.architecture()
+ print("ATTACHED: %s" % arch.name())
+except (gdb.error, AttributeError):
+ print("SKIPPING (not connected)", file=sys.stderr)
+ exit(0)
+
+if gdb.parse_and_eval('$pc') == 0:
+ print("SKIP: PC not set")
+ exit(0)
+if len(gdb.selected_inferior().threads()) == 1:
+ print("SKIP: set to run on a single thread")
+ exit(0)
+
+try:
+ # Run the actual tests
+ run_test()
+except (gdb.error):
+ print("GDB Exception: %s" % (sys.exc_info()[0]))
+ failcount += 1
+ pass
+
+# Finally kill the inferior and exit gdb with a count of failures
+gdb.execute("kill")
+exit(failcount)