Write command to logfile.
[riscv-tests.git] / debug / testlib.py
index bb604a7dcf4928f55dee37b91642c3c0c3a4faef..0e5f35dd9a8c0b6b0d92ab45dedbbfc5a42b7805 100644 (file)
@@ -42,13 +42,15 @@ def unused_port():
     return port
 
 class Spike(object):
-    def __init__(self, cmd, binary=None, halted=False, with_gdb=True, timeout=None):
+    def __init__(self, cmd, binary=None, halted=False, with_gdb=True, timeout=None,
+            xlen=64):
         """Launch spike. Return tuple of its process and the port it's running on."""
         if cmd:
             cmd = shlex.split(cmd)
         else:
             cmd = ["spike"]
-        #cmd.append("-l")    #<<<
+        if (xlen == 32):
+            cmd += ["--isa", "RV32"]
 
         if timeout:
             cmd = ["timeout", str(timeout)] + cmd
@@ -87,6 +89,7 @@ class Openocd(object):
         if debug:
             cmd.append("-d")
         logfile = open("openocd.log", "w")
+        logfile.write("+ %s\n" % " ".join(cmd))
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile,
                 stderr=logfile)
         # TODO: Pick a random port
@@ -100,11 +103,13 @@ class Openocd(object):
             pass
 
 class Gdb(object):
-    def __init__(self):
-        path = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")
+    def __init__(self,
+            path=os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gdb")):
         self.child = pexpect.spawn(path)
         self.child.logfile = file("gdb.log", "w")
+        self.child.logfile.write("+ %s\n" % path)
         self.wait()
+        self.command("set confirm off")
         self.command("set width 0")
         self.command("set height 0")
         # Force consistency.
@@ -150,7 +155,7 @@ class Gdb(object):
         return output
 
     def load(self):
-        output = self.command("load", timeout=120)
+        output = self.command("load", timeout=60)
         assert "failed" not in  output
         assert "Transfer rate" in output
 
@@ -159,3 +164,9 @@ class Gdb(object):
         assert "not defined" not in output
         assert "Breakpoint" in output
         return output
+
+    def hbreak(self, location):
+        output = self.command("hbreak %s" % location)
+        assert "not defined" not in output
+        assert "Hardware assisted breakpoint" in output
+        return output