1from __future__ import print_function 2# 3# Test the SVE registers are visable and changeable via gdbstub 4# 5# This is launched via tests/guest-debug/run-test.py 6# 7 8import gdb 9import sys 10 11MAGIC = 0xDEADBEEF 12 13failcount = 0 14 15def 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 23 24def run_test(): 25 "Run through the tests one by one" 26 27 gdb.execute("info registers") 28 report(True, "info registers") 29 30 gdb.execute("info registers vector") 31 report(True, "info registers vector") 32 33 # Now all the zregs 34 frame = gdb.selected_frame() 35 for i in range(0, 32): 36 rname = "z%d" % (i) 37 zreg = frame.read_register(rname) 38 report(True, "Reading %s" % rname) 39 for j in range(0, 4): 40 cmd = "set $%s.q.u[%d] = 0x%x" % (rname, j, MAGIC) 41 gdb.execute(cmd) 42 report(True, "%s" % cmd) 43 for j in range(0, 4): 44 reg = "$%s.q.u[%d]" % (rname, j) 45 v = gdb.parse_and_eval(reg) 46 report(str(v.type) == "uint128_t", "size of %s" % (reg)) 47 for j in range(0, 8): 48 cmd = "set $%s.d.u[%d] = 0x%x" % (rname, j, MAGIC) 49 gdb.execute(cmd) 50 report(True, "%s" % cmd) 51 for j in range(0, 8): 52 reg = "$%s.d.u[%d]" % (rname, j) 53 v = gdb.parse_and_eval(reg) 54 report(str(v.type) == "uint64_t", "size of %s" % (reg)) 55 report(int(v) == MAGIC, "%s is 0x%x" % (reg, MAGIC)) 56 57# 58# This runs as the script it sourced (via -x, via run-test.py) 59# 60try: 61 inferior = gdb.selected_inferior() 62 if inferior.was_attached == False: 63 print("SKIPPING (failed to attach)", file=sys.stderr) 64 exit(0) 65 arch = inferior.architecture() 66 report(arch.name() == "aarch64", "connected to aarch64") 67except (gdb.error, AttributeError): 68 print("SKIPPING (not connected)", file=sys.stderr) 69 exit(0) 70 71try: 72 # These are not very useful in scripts 73 gdb.execute("set pagination off") 74 gdb.execute("set confirm off") 75 76 # Run the actual tests 77 run_test() 78except: 79 print ("GDB Exception: %s" % (sys.exc_info()[0])) 80 failcount += 1 81 82print("All tests complete: %d failures" % failcount) 83 84exit(failcount) 85