| 1 | # |
| 2 | # Test some of the system debug features with the multiarch memory |
| 3 | # test. It is a port of the original vmlinux focused test case but |
| 4 | # using the "memory" test instead. |
| 5 | # |
| 6 | # This is launched via tests/guest-debug/run-test.py |
| 7 | # |
| 8 | |
| 9 | import gdb |
| 10 | from test_gdbstub import gdb_exit, main, report |
| 11 | |
| 12 | |
| 13 | def check_interrupt(thread): |
| 14 | """ |
| 15 | Check that, if thread is resumed, we go back to the same thread when the |
| 16 | program gets interrupted. |
| 17 | """ |
| 18 | |
| 19 | # Switch to the thread we're going to be running the test in. |
| 20 | print("thread ", thread.num) |
| 21 | gdb.execute("thr %d" % thread.num) |
| 22 | |
| 23 | # Enter the loop() function on this thread. |
| 24 | # |
| 25 | # While there are cleaner ways to do this, we want to minimize the number of |
| 26 | # side effects on the gdbstub's internal state, since those may mask bugs. |
| 27 | # Ideally, there should be no difference between what we're doing here and |
| 28 | # the program reaching the loop() function on its own. |
| 29 | # |
| 30 | # For this to be safe, we only need the prologue of loop() to not have |
| 31 | # instructions that may have problems with what we're doing here. We don't |
| 32 | # have to worry about anything else, as this function never returns. |
| 33 | gdb.execute("set $pc = loop") |
| 34 | |
| 35 | # Continue and then interrupt the task. |
| 36 | gdb.post_event(lambda: gdb.execute("interrupt")) |
| 37 | gdb.execute("c") |
| 38 | |
| 39 | # Check whether the thread we're in after the interruption is the same we |
| 40 | # ran continue from. |
| 41 | return (thread.num == gdb.selected_thread().num) |
| 42 | |
| 43 | |
| 44 | def run_test(): |
| 45 | """ |
| 46 | Test if interrupting the code always lands us on the same thread when |
| 47 | running with scheduler-lock enabled. |
| 48 | """ |
| 49 | if len(gdb.selected_inferior().threads()) == 1: |
| 50 | print("SKIP: set to run on a single thread") |
| 51 | gdb_exit(0) |
| 52 | |
| 53 | gdb.execute("set scheduler-locking on") |
| 54 | for thread in gdb.selected_inferior().threads(): |
| 55 | report(check_interrupt(thread), |
| 56 | "thread %d resumes correctly on interrupt" % thread.num) |
| 57 | |
| 58 | |
| 59 | main(run_test) |