4a71035e4f3977ea49794450d373db3af26eac4f
[riscv-tests.git] / debug / openocd.py
1 #!/usr/bin/env python
2
3 """Test that OpenOCD can talk to a RISC-V target."""
4
5 import argparse
6 import sys
7
8 import targets
9 import testlib
10 from testlib import assertRegexpMatches
11
12 class OpenOcdTest(testlib.BaseTest):
13 def __init__(self, target):
14 testlib.BaseTest.__init__(self, target)
15 self.gdb = None
16
17 def early_applicable(self):
18 return self.target.openocd_config
19
20 def setup(self):
21 # pylint: disable=attribute-defined-outside-init
22 self.cli = testlib.OpenocdCli()
23
24 class RegTest(OpenOcdTest):
25 def test(self):
26 self.cli.command("halt")
27 output = self.cli.command("reg")
28 assertRegexpMatches(output, r"x18 \(/%d\): 0x[0-9A-F]+" %
29 self.target.xlen)
30
31 def main():
32 parser = argparse.ArgumentParser(
33 description="Test that OpenOCD can talk to a RISC-V target.")
34 targets.add_target_options(parser)
35 testlib.add_test_run_options(parser)
36
37 parsed = parser.parse_args()
38
39 target = parsed.target(parsed.cmd, parsed.run, parsed.isolate)
40 if parsed.xlen:
41 target.xlen = parsed.xlen
42
43 module = sys.modules[__name__]
44
45 return testlib.run_all_tests(module, target, parsed.test, parsed.fail_fast)
46
47 if __name__ == '__main__':
48 sys.exit(main())