770e77ad1e9c6621642e00811efdb1092d4a996c
[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 tearDown(self):
20 self.spike.kill()
21 self.spike.wait()
22
23 def test_turbostep(self):
24 """Single step until the program exits. TODO"""
25 last_pc = None
26 for _ in range(100):
27 self.gdb.command("stepi")
28 pc = self.gdb.command("p $pc")
29 self.assertNotEqual(last_pc, pc)
30 last_pc = pc
31
32 def test_exit(self):
33 output = self.gdb.command("c")
34 self.assertIn("Continuing", output)
35 self.assertIn("Remote connection closed", output)
36
37 def test_breakpoint(self):
38 self.gdb.command("b print_row")
39 # The breakpoint should be hit exactly 10 times.
40 for _ in range(10):
41 output = self.gdb.command("c")
42 self.assertIn("Continuing", 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)
47
48 def test_registers(self):
49 output = self.gdb.command("info all-registers")
50 self.assertNotIn("Could not", output)
51 for reg in ('zero', 'ra', 'sp', 'gp', 'tp'):
52 self.assertIn(reg, output)
53 # mcpuid is one of the few registers that should have the high bit set
54 # (for rv64).
55 self.assertRegexpMatches(output, ".*mcpuid *0x80")
56
57 # The time register should always be changing.
58 last_time = None
59 for _ in range(5):
60 time = self.gdb.command("p $time").split('=')[-1]
61 self.assertNotEqual(time, last_time)
62 last_time = time
63 self.gdb.command("stepi")
64
65 if __name__ == '__main__':
66 unittest.main()