Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / multiarch / gdbstub / sha1.py
blob423b720e6da8f842bffe6e48351277c596673a3e
1 from __future__ import print_function
3 # A very simple smoke test for debugging the SHA1 userspace test on
4 # each target.
6 # This is launched via tests/guest-debug/run-test.py
9 import gdb
10 import sys
12 initial_vlen = 0
13 failcount = 0
15 def report(cond, msg):
16 "Report success/fail of test"
17 if cond:
18 print("PASS: %s" % (msg))
19 else:
20 print("FAIL: %s" % (msg))
21 global failcount
22 failcount += 1
24 def check_break(sym_name):
25 "Setup breakpoint, continue and check we stopped."
26 sym, ok = gdb.lookup_symbol(sym_name)
27 bp = gdb.Breakpoint(sym_name)
29 gdb.execute("c")
31 # hopefully we came back
32 end_pc = gdb.parse_and_eval('$pc')
33 report(bp.hit_count == 1,
34 "break @ %s (%s %d hits)" % (end_pc, sym.value(), bp.hit_count))
36 bp.delete()
38 def run_test():
39 "Run through the tests one by one"
41 check_break("SHA1Init")
43 # Check step and inspect values. We do a double next after the
44 # breakpoint as depending on the version of gdb we may step the
45 # preamble and not the first actual line of source.
46 gdb.execute("next")
47 gdb.execute("next")
48 val_ctx = gdb.parse_and_eval("context->state[0]")
49 exp_ctx = 0x67452301
50 report(int(val_ctx) == exp_ctx, "context->state[0] == %x" % exp_ctx);
52 gdb.execute("next")
53 val_ctx = gdb.parse_and_eval("context->state[1]")
54 exp_ctx = 0xEFCDAB89
55 report(int(val_ctx) == exp_ctx, "context->state[1] == %x" % exp_ctx);
57 # finally check we don't barf inspecting registers
58 gdb.execute("info registers")
61 # This runs as the script it sourced (via -x, via run-test.py)
63 try:
64 inferior = gdb.selected_inferior()
65 arch = inferior.architecture()
66 print("ATTACHED: %s" % arch.name())
67 except (gdb.error, AttributeError):
68 print("SKIPPING (not connected)", file=sys.stderr)
69 exit(0)
71 if gdb.parse_and_eval('$pc') == 0:
72 print("SKIP: PC not set")
73 exit(0)
75 try:
76 # These are not very useful in scripts
77 gdb.execute("set pagination off")
78 gdb.execute("set confirm off")
80 # Run the actual tests
81 run_test()
82 except (gdb.error):
83 print ("GDB Exception: %s" % (sys.exc_info()[0]))
84 failcount += 1
85 pass
87 print("All tests complete: %d failures" % failcount)
88 exit(failcount)