Use compressed code if the target supports it.
[riscv-tests.git] / debug / openocd.py
index 0c7e7d2a277a5c71d1cf1f067aa5ca4efcdffc7c..50c6f3c9592914d10cede9d5d907fbc75db99d0c 100755 (executable)
@@ -7,7 +7,7 @@ import sys
 
 import targets
 import testlib
-from testlib import assertGreater
+from testlib import assertIn, assertEqual
 
 class OpenOcdTest(testlib.BaseTest):
     def __init__(self, target):
@@ -20,11 +20,50 @@ class OpenOcdTest(testlib.BaseTest):
     def setup(self):
         # pylint: disable=attribute-defined-outside-init
         self.cli = testlib.OpenocdCli()
+        self.cli.command("halt")
+
+    def write_nops(self, count):
+        for address in range(self.target.ram, self.target.ram + 4 * count, 4):
+            # 0x13 is nop
+            self.cli.command("mww 0x%x 0x13" % address)
 
 class RegTest(OpenOcdTest):
     def test(self):
-        output = self.cli.command("reg")
-        assertGreater(len(output), 1)
+        self.write_nops(4)
+
+        regs = self.cli.reg()
+        assertIn("x18", regs)
+
+        self.cli.command("reg x18 0x11782")
+        self.cli.command("step 0x%x" % self.target.ram)
+
+        assertEqual(self.cli.reg("x18"), 0x11782)
+
+class StepTest(OpenOcdTest):
+    def test(self):
+        self.write_nops(4)
+
+        self.cli.command("step 0x%x" % self.target.ram)
+        for i in range(4):
+            pc = self.cli.reg("pc")
+            assertEqual(pc, self.target.ram + 4 * (i+1))
+            self.cli.command("step")
+
+class ResumeTest(OpenOcdTest):
+    def test(self):
+        self.write_nops(16)
+
+        self.cli.command("bp 0x%x 4" % (self.target.ram + 12))
+        self.cli.command("bp 0x%x 4" % (self.target.ram + 24))
+
+        self.cli.command("resume 0x%x" % self.target.ram)
+        assertEqual(self.cli.reg("pc"), self.target.ram + 12)
+
+        self.cli.command("resume")
+        assertEqual(self.cli.reg("pc"), self.target.ram + 24)
+
+        self.cli.command("resume 0x%x" % self.target.ram)
+        assertEqual(self.cli.reg("pc"), self.target.ram + 12)
 
 def main():
     parser = argparse.ArgumentParser(
@@ -40,7 +79,7 @@ def main():
 
     module = sys.modules[__name__]
 
-    return testlib.run_all_tests(module, target, parsed.test, parsed.fail_fast)
+    return testlib.run_all_tests(module, target, parsed)
 
 if __name__ == '__main__':
     sys.exit(main())