1from __future__ import print_function
2#
3# Test the SVE ZReg reports the right amount of data. It uses the
4# sve-ioctl test and examines the register data each time the
5# __sve_ld_done breakpoint is hit.
6#
7# This is launched via tests/guest-debug/run-test.py
8#
9
10import gdb
11from test_gdbstub import main, report
12
13initial_vlen = 0
14
15
16class TestBreakpoint(gdb.Breakpoint):
17    def __init__(self, sym_name="__sve_ld_done"):
18        super(TestBreakpoint, self).__init__(sym_name)
19        # self.sym, ok = gdb.lookup_symbol(sym_name)
20
21    def stop(self):
22        val_i = gdb.parse_and_eval('i')
23        global initial_vlen
24        try:
25            for i in range(0, int(val_i)):
26                val_z = gdb.parse_and_eval("$z0.b.u[%d]" % i)
27                report(int(val_z) == i, "z0.b.u[%d] == %d" % (i, i))
28            for i in range(i + 1, initial_vlen):
29                val_z = gdb.parse_and_eval("$z0.b.u[%d]" % i)
30                report(int(val_z) == 0, "z0.b.u[%d] == 0" % (i))
31        except gdb.error:
32            report(False, "checking zregs (out of range)")
33
34        # Check the aliased V registers are set and GDB has correctly
35        # created them for us having recognised and handled SVE.
36        try:
37            for i in range(0, 16):
38                val_z = gdb.parse_and_eval("$z0.b.u[%d]" % i)
39                val_v = gdb.parse_and_eval("$v0.b.u[%d]" % i)
40                report(int(val_z) == int(val_v),
41                       "v0.b.u[%d] == z0.b.u[%d]" % (i, i))
42        except gdb.error:
43            report(False, "checking vregs (out of range)")
44
45
46def run_test():
47    "Run through the tests one by one"
48
49    print ("Setup breakpoint")
50    bp = TestBreakpoint()
51
52    global initial_vlen
53    vg = gdb.parse_and_eval("$vg")
54    initial_vlen = int(vg) * 8
55
56    gdb.execute("c")
57
58
59main(run_test, expected_arch="aarch64")
60