c3c2ecad016241087e6e6bb3bb51e0cacefbcaca
9 class DebugTest(unittest
.TestCase
):
11 self
.binary
= testlib
.compile("debug.c")
12 self
.spike
, self
.port
= testlib
.spike(self
.binary
, halted
=False)
13 self
.gdb
= testlib
.Gdb()
14 self
.gdb
.command("file %s" % self
.binary
)
15 self
.gdb
.command("target extended-remote localhost:%d" % self
.port
)
16 self
.gdb
.command("p i=0");
22 def test_turbostep(self
):
23 """Single step a bunch of times."""
26 self
.gdb
.command("stepi")
27 pc
= self
.gdb
.command("p $pc")
28 self
.assertNotEqual(last_pc
, pc
)
32 output
= self
.gdb
.command("c")
33 self
.assertIn("Continuing", output
)
34 self
.assertIn("Remote connection closed", output
)
36 def test_breakpoint(self
):
37 self
.gdb
.command("b print_row")
38 # The breakpoint should be hit exactly 10 times.
40 output
= self
.gdb
.command("c")
41 self
.assertIn("Continuing", output
)
42 self
.assertIn("length=%d" % i
, output
)
43 self
.assertIn("Breakpoint 1", output
)
44 output
= self
.gdb
.command("c")
45 self
.assertIn("Continuing", output
)
46 self
.assertIn("Remote connection closed", output
)
48 def test_registers(self
):
49 # Try both forms to test gdb.
50 for cmd
in ("info all-registers", "info registers all"):
51 output
= self
.gdb
.command(cmd
)
52 self
.assertNotIn("Could not", output
)
53 for reg
in ('zero', 'ra', 'sp', 'gp', 'tp'):
54 self
.assertIn(reg
, output
)
55 # mcpuid is one of the few registers that should have the high bit set
57 # Leave this commented out until gdb and spike agree on the encoding of
58 # mcpuid (which is going to be renamed to misa in any case).
59 #self.assertRegexpMatches(output, ".*mcpuid *0x80")
61 # The time register should always be changing.
64 time
= self
.gdb
.p("$time")
65 self
.assertNotEqual(time
, last_time
)
67 self
.gdb
.command("stepi")
69 class RegsTest(unittest
.TestCase
):
71 self
.binary
= testlib
.compile("regs.s")
72 self
.spike
, self
.port
= testlib
.spike(self
.binary
, halted
=False)
73 self
.gdb
= testlib
.Gdb()
74 self
.gdb
.command("file %s" % self
.binary
)
75 self
.gdb
.command("target extended-remote localhost:%d" % self
.port
)
81 def test_write_gprs(self
):
82 # Note a0 is missing from this list since it's used to hold the
84 regs
= ("ra", "sp", "gp", "tp", "t0", "t1", "t2", "fp", "s1",
85 "a1", "a2", "a3", "a4", "a5", "a6", "a7", "s2", "s3", "s4",
86 "s5", "s6", "s7", "s8", "s9", "s10", "s11", "t3", "t4", "t5",
89 self
.gdb
.command("p $pc=write_regs")
90 for i
, r
in enumerate(regs
):
91 self
.gdb
.command("p $%s=%d" % (r
, (0xdeadbeef<<i
)+17))
92 self
.gdb
.command("p $a0=data")
93 self
.gdb
.command("b all_done")
94 output
= self
.gdb
.command("c")
95 self
.assertIn("Breakpoint 1", output
)
97 # Just to get this data in the log.
98 self
.gdb
.command("x/30gx data")
99 self
.gdb
.command("info registers")
100 for n
in range(len(regs
)):
101 self
.assertEqual(self
.gdb
.x("data+%d" % (8*n
), 'g'),
104 def test_write_csrs(self
):
105 # As much a test of gdb as of the simulator.
106 self
.gdb
.p("$mscratch=0")
108 self
.assertEqual(self
.gdb
.p("$mscratch"), 0)
109 self
.gdb
.p("$mscratch=123")
111 self
.assertEqual(self
.gdb
.p("$mscratch"), 123)
113 self
.gdb
.command("p $fflags=9")
114 self
.gdb
.command("p $pc=write_regs")
115 self
.gdb
.command("p $a0=data")
116 self
.gdb
.command("b all_done")
117 self
.gdb
.command("c")
119 self
.assertEqual(9, self
.gdb
.p("$fflags"))
120 self
.assertEqual(9, self
.gdb
.p("$x1"))
121 self
.assertEqual(9, self
.gdb
.p("$csr1"))
123 if __name__
== '__main__':