From d69764058472bd9e697414c5196fef61fb14808a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 9 Nov 2018 00:00:02 +0000 Subject: [PATCH] add more gdb tests --- .../arch/aarch64/{floating_point.S => fadd.S} | 20 +++++++++++++ baremetal/arch/aarch64/fadd.py | 30 +++++++++++++++++++ baremetal/arch/aarch64/regs.S | 19 ++++++++++++ baremetal/arch/aarch64/regs.py | 10 +++++++ run-gdb | 10 ++++++- test-gdb | 12 ++++++++ 6 files changed, 100 insertions(+), 1 deletion(-) rename baremetal/arch/aarch64/{floating_point.S => fadd.S} (52%) create mode 100644 baremetal/arch/aarch64/fadd.py create mode 100644 baremetal/arch/aarch64/regs.S create mode 100644 baremetal/arch/aarch64/regs.py diff --git a/baremetal/arch/aarch64/floating_point.S b/baremetal/arch/aarch64/fadd.S similarity index 52% rename from baremetal/arch/aarch64/floating_point.S rename to baremetal/arch/aarch64/fadd.S index e5ebebe..8afd1cb 100644 --- a/baremetal/arch/aarch64/floating_point.S +++ b/baremetal/arch/aarch64/fadd.S @@ -4,8 +4,11 @@ main: /* 1.5 + 2.5 == 4.0 */ fmov d0, #1.5 + /* test-gdb-d0 */ fmov d1, #2.5 + /* test-gdb-d1 */ fadd d2, d0, d1 + /* test-gdb-d2 */ fmov d3, #4.0 fcmp d2, d3 beq 1f @@ -14,7 +17,11 @@ main: /* Now in 32-bit. */ fmov s0, #1.5 + /* test-gdb-s0 */ fmov s1, #2.5 + /* test-gdb-s1 */ + fadd s2, s0, s1 + /* test-gdb-s2 */ fadd s2, s0, s1 fmov s3, #4.0 fcmp s2, s3 @@ -22,4 +29,17 @@ main: bl assert_fail 1: + /* Higher registers. */ + fmov d28, #1.5 + /* test-gdb-d28 */ + fmov d29, #2.5 + /* test-gdb-d29 */ + fadd d30, d28, d29 + /* test-gdb-d30 */ + fmov d31, #4.0 + /* test-gdb-d31 */ + fcmp d30, d31 + beq 1f + bl assert_fail +1: ret diff --git a/baremetal/arch/aarch64/fadd.py b/baremetal/arch/aarch64/fadd.py new file mode 100644 index 0000000..da57db9 --- /dev/null +++ b/baremetal/arch/aarch64/fadd.py @@ -0,0 +1,30 @@ +def test(self): + self.sendline('tbreak main') + self.sendline('continue') + + # Double. + self.continue_to('d0') + assert self.get_float('$d0') == 1.5 + self.continue_to('d1') + assert self.get_float('$d1') == 2.5 + self.continue_to('d2') + assert self.get_float('$d2') == 4.0 + + # Single. + self.continue_to('s0') + assert self.get_float('$s0') == 1.5 + self.continue_to('s1') + assert self.get_float('$s1') == 2.5 + self.continue_to('s2') + assert self.get_float('$s2') == 4.0 + + # High registers.. + self.continue_to('d28') + assert self.get_float('$d28') == 1.5 + self.continue_to('d29') + assert self.get_float('$d29') == 2.5 + self.continue_to('d30') + assert self.get_float('$d30') == 4.0 + self.continue_to('d31') + assert self.get_float('$d31') == 4.0 + diff --git a/baremetal/arch/aarch64/regs.S b/baremetal/arch/aarch64/regs.S new file mode 100644 index 0000000..f7f626f --- /dev/null +++ b/baremetal/arch/aarch64/regs.S @@ -0,0 +1,19 @@ +/* Test that we can move: + * - set registers + * - read x30 */ +.global main +main: + /* test-gdb-before-x29 */ + mov x0, #1 + /* test-gdb-x0 */ + mov x1, #2 + /* test-gdb-x1 */ + + mov x29, #1 + /* test-gdb-x29 */ + mov x30, #2 + /* test-gdb-x30 */ + + /* Exit required since we meesed up with x30 which is the lr. */ + mov x0, #0 + bl exit diff --git a/baremetal/arch/aarch64/regs.py b/baremetal/arch/aarch64/regs.py new file mode 100644 index 0000000..fdad4ec --- /dev/null +++ b/baremetal/arch/aarch64/regs.py @@ -0,0 +1,10 @@ +def test(self): + self.sendline('tbreak main') + self.sendline('continue') + self.continue_to('x1') + self.sendline('set $x30 = 3') + self.continue_to('x29') + assert self.get_int('$x29') == 1 + assert self.get_int('$x30') == 3 + self.continue_to('x30') + assert self.get_int('$x30') == 2 diff --git a/run-gdb b/run-gdb index 1b88247..c6cad13 100755 --- a/run-gdb +++ b/run-gdb @@ -64,6 +64,10 @@ class GdbTestcase: self.sendline('printf "%d\\n", {}'.format(int_id)) return int(self.before()) + def get_float(self, float_id): + self.sendline('printf "%f\\n", {}'.format(float_id)) + return float(self.before()) + def find_line(self, lineid): ''' Search for the first line that contains a comment line @@ -107,7 +111,11 @@ def main(args, extra_args=None): elif args.verbose: # The output of this would affect the tests. # https://stackoverflow.com/questions/13496389/gdb-remote-protocol-how-to-analyse-packets - before.extend(['-ex', 'set debug remote 1', common.Newline]) + # Also be opinionated and set remotetimeout to allow you to step debug the emulator at the same time. + before.extend([ + '-ex', 'set debug remote 1', common.Newline, + '-ex', 'set remotetimeout 99999', common.Newline, + ]) if args.break_at is not None: break_at = ['-ex', 'break {}'.format(args.break_at), common.Newline] else: diff --git a/test-gdb b/test-gdb index a9ae048..e118b8c 100755 --- a/test-gdb +++ b/test-gdb @@ -8,6 +8,9 @@ wait ./run --arch arm --background --baremetal arch/arm/add --wait-gdb & ./run-gdb --arch arm --baremetal arch/arm/add --test "$@" wait +./run --arch aarch64 --background --baremetal add --wait-gdb & +./run-gdb --arch aarch64 --baremetal add --test "$@" +wait ./run --arch aarch64 --background --baremetal arch/aarch64/add --wait-gdb & ./run-gdb --arch aarch64 --baremetal arch/aarch64/add --test "$@" wait @@ -19,6 +22,15 @@ wait ./run --arch arm --background --baremetal arch/arm/add --gem5 --wait-gdb & ./run-gdb --arch arm --baremetal arch/arm/add --gem5 --test "$@" wait +./run --arch aarch64 --background --baremetal add --gem5 --wait-gdb & +./run-gdb --arch aarch64 --baremetal add --gem5 --test "$@" +wait ./run --arch aarch64 --background --baremetal arch/aarch64/add --gem5 --wait-gdb & ./run-gdb --arch aarch64 --baremetal arch/aarch64/add --gem5 --test "$@" wait +./run --arch aarch64 --background --baremetal arch/aarch64/regs --gem5 --wait-gdb & +./run-gdb --arch aarch64 --baremetal arch/aarch64/regs --gem5 --test "$@" +wait +./run --arch aarch64 --background --baremetal arch/aarch64/fadd --gem5 --wait-gdb & +./run-gdb --arch aarch64 --baremetal arch/aarch64/fadd --gem5 --test "$@" +wait