Implement reading of CSRs.
[riscv-isa-sim.git] / tests / gdbserver-smoke.py
1 #!/usr/bin/python
2
3 import os
4 import testlib
5 import unittest
6 import tempfile
7 import time
8
9 class SmokeTest(unittest.TestCase):
10 def setUp(self):
11 self.tmpf = tempfile.NamedTemporaryFile()
12 testlib.compile("debug.c", self.tmpf.name)
13 self.spike = testlib.spike(self.tmpf.name, halted=False)
14 self.gdb = testlib.Gdb()
15 self.gdb.command("file %s" % self.tmpf.name)
16 self.gdb.command("target extended-remote localhost:9824")
17 self.gdb.command("p i=0");
18
19 def cleanUp(self):
20 self.spike.kill()
21
22 def test_turbostep(self):
23 """Single step until the program exits. TODO"""
24 last_pc = None
25 for _ in range(100):
26 self.gdb.command("stepi")
27 pc = self.gdb.command("p $pc")
28 self.assertNotEqual(last_pc, pc)
29 last_pc = pc
30
31 def test_exit(self):
32 output = self.gdb.command("c")
33 self.assertIn("Continuing", output)
34 self.assertIn("Remote connection closed", output)
35
36 def test_breakpoint(self):
37 self.gdb.command("b print_row")
38 # The breakpoint should be hit exactly 10 times.
39 for _ in range(10):
40 output = self.gdb.command("c")
41 self.assertIn("Continuing", output)
42 self.assertIn("Breakpoint 1", output)
43 output = self.gdb.command("c")
44 self.assertIn("Continuing", output)
45 self.assertIn("Remote connection closed", output)
46
47 def test_registers(self):
48 output = self.gdb.command("info all-registers")
49 self.assertNotIn("Could not", output)
50 for reg in ('zero', 'ra', 'sp', 'gp', 'tp'):
51 self.assertIn(reg, output)
52 # mcpuid is one of the few registers that should have the high bit set
53 # (for rv64).
54 self.assertRegexpMatches(output, ".*mcpuid *0x80")
55
56 # The time register should always be changing.
57 last_time = None
58 for _ in range(5):
59 time = self.gdb.command("p $time").split('=')[-1]
60 self.assertNotEqual(time, last_time)
61 last_time = time
62 self.gdb.command("stepi")
63
64 if __name__ == '__main__':
65 unittest.main()