xref: /qemu/tests/tcg/s390x/gdbstub/test-svc.py (revision cb2d7e63d19794c5344d438d943a8680d6756bdc)
1be4a4cb4SIlya Leoshkevich"""Test single-stepping SVC.
2be4a4cb4SIlya Leoshkevich
3be4a4cb4SIlya LeoshkevichThis runs as a sourced script (via -x, via run-test.py)."""
4be4a4cb4SIlya Leoshkevichfrom __future__ import print_function
5be4a4cb4SIlya Leoshkevichimport gdb
6be4a4cb4SIlya Leoshkevichimport sys
7be4a4cb4SIlya Leoshkevich
8be4a4cb4SIlya Leoshkevich
9be4a4cb4SIlya Leoshkevichn_failures = 0
10be4a4cb4SIlya Leoshkevich
11be4a4cb4SIlya Leoshkevich
12be4a4cb4SIlya Leoshkevichdef report(cond, msg):
13be4a4cb4SIlya Leoshkevich    """Report success/fail of a test"""
14be4a4cb4SIlya Leoshkevich    if cond:
15be4a4cb4SIlya Leoshkevich        print("PASS: {}".format(msg))
16be4a4cb4SIlya Leoshkevich    else:
17be4a4cb4SIlya Leoshkevich        print("FAIL: {}".format(msg))
18be4a4cb4SIlya Leoshkevich        global n_failures
19be4a4cb4SIlya Leoshkevich        n_failures += 1
20be4a4cb4SIlya Leoshkevich
21be4a4cb4SIlya Leoshkevich
22be4a4cb4SIlya Leoshkevichdef run_test():
23be4a4cb4SIlya Leoshkevich    """Run through the tests one by one"""
24be4a4cb4SIlya Leoshkevich    report("lghi\t" in gdb.execute("x/i $pc", False, True), "insn #1")
25be4a4cb4SIlya Leoshkevich    gdb.execute("si")
26be4a4cb4SIlya Leoshkevich    report("larl\t" in gdb.execute("x/i $pc", False, True), "insn #2")
27be4a4cb4SIlya Leoshkevich    gdb.execute("si")
28*cb2d7e63SIlya Leoshkevich    report("lgrl\t" in gdb.execute("x/i $pc", False, True), "insn #3")
29be4a4cb4SIlya Leoshkevich    gdb.execute("si")
30be4a4cb4SIlya Leoshkevich    report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #4")
31be4a4cb4SIlya Leoshkevich    gdb.execute("si")
32be4a4cb4SIlya Leoshkevich    report("xgr\t" in gdb.execute("x/i $pc", False, True), "insn #5")
33be4a4cb4SIlya Leoshkevich    gdb.execute("si")
34be4a4cb4SIlya Leoshkevich    report("svc\t" in gdb.execute("x/i $pc", False, True), "insn #6")
35be4a4cb4SIlya Leoshkevich    gdb.execute("si")
36be4a4cb4SIlya Leoshkevich
37be4a4cb4SIlya Leoshkevich
38be4a4cb4SIlya Leoshkevichdef main():
39be4a4cb4SIlya Leoshkevich    """Prepare the environment and run through the tests"""
40be4a4cb4SIlya Leoshkevich    try:
41be4a4cb4SIlya Leoshkevich        inferior = gdb.selected_inferior()
42be4a4cb4SIlya Leoshkevich        print("ATTACHED: {}".format(inferior.architecture().name()))
43be4a4cb4SIlya Leoshkevich    except (gdb.error, AttributeError):
44be4a4cb4SIlya Leoshkevich        print("SKIPPING (not connected)")
45be4a4cb4SIlya Leoshkevich        exit(0)
46be4a4cb4SIlya Leoshkevich
47be4a4cb4SIlya Leoshkevich    if gdb.parse_and_eval('$pc') == 0:
48be4a4cb4SIlya Leoshkevich        print("SKIP: PC not set")
49be4a4cb4SIlya Leoshkevich        exit(0)
50be4a4cb4SIlya Leoshkevich
51be4a4cb4SIlya Leoshkevich    try:
52be4a4cb4SIlya Leoshkevich        # These are not very useful in scripts
53be4a4cb4SIlya Leoshkevich        gdb.execute("set pagination off")
54be4a4cb4SIlya Leoshkevich        gdb.execute("set confirm off")
55be4a4cb4SIlya Leoshkevich
56be4a4cb4SIlya Leoshkevich        # Run the actual tests
57be4a4cb4SIlya Leoshkevich        run_test()
58be4a4cb4SIlya Leoshkevich    except gdb.error:
59be4a4cb4SIlya Leoshkevich        report(False, "GDB Exception: {}".format(sys.exc_info()[0]))
60be4a4cb4SIlya Leoshkevich    print("All tests complete: %d failures" % n_failures)
61be4a4cb4SIlya Leoshkevich    exit(n_failures)
62be4a4cb4SIlya Leoshkevich
63be4a4cb4SIlya Leoshkevich
64be4a4cb4SIlya Leoshkevichmain()
65