debug: Don't halt out of reset. It's unrealistic. Use a program which loops (actually...
[riscv-tests.git] / debug / testlib.py
index 71bd60966abdab6cb5ab8298de91e49db3b67418..a66d59a7b450baf63e7b99aa6c50ef6e0ded3fec 100644 (file)
@@ -57,14 +57,15 @@ def unused_port():
 class Spike(object):
     logname = "spike.log"
 
-    def __init__(self, cmd, binary=None, halted=False, with_jtag_gdb=True,
+    def __init__(self, sim_cmd, binary=None, halted=False, with_jtag_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)
+        if sim_cmd:
+            cmd = shlex.split(sim_cmd)
         else:
-            cmd = ["spike"]
+            spike = os.path.expandvars("$RISCV/bin/spike")
+            cmd = [spike]
         if xlen == 32:
             cmd += ["--isa", "RV32"]
 
@@ -77,7 +78,7 @@ class Spike(object):
             cmd += ['--rbb-port', '0']
             os.environ['REMOTE_BITBANG_HOST'] = 'localhost'
         cmd.append("-m32")
-        cmd.append('pk')
+        cmd.append('programs/infinite_loop')
         if binary:
             cmd.append(binary)
         logfile = open(self.logname, "w")
@@ -110,8 +111,8 @@ class Spike(object):
         return self.process.wait(*args, **kwargs)
 
 class VcsSim(object):
-    def __init__(self, simv=None, debug=False):
-        if simv:
+    def __init__(self, sim_cmd=None, debug=False):
+        if sim_cmd:
             cmd = shlex.split(simv)
         else:
             cmd = ["simv"]
@@ -147,12 +148,15 @@ class VcsSim(object):
 class Openocd(object):
     logname = "openocd.log"
 
-    def __init__(self, cmd=None, config=None, debug=False):
-        if cmd:
-            cmd = shlex.split(cmd)
+    def __init__(self, server_cmd=None, config=None, debug=False):
+        if server_cmd:
+            cmd = shlex.split(server_cmd)
         else:
-            cmd = ["openocd", "-d"]
-
+            openocd = os.path.expandvars("$RISCV/bin/riscv-openocd")
+            cmd = [openocd]
+            if (debug):
+                cmd.append("-d")
+        
         # This command needs to come before any config scripts on the command
         # line, since they are executed in order.
         cmd += [
@@ -191,7 +195,7 @@ class Openocd(object):
         messaged = False
         while True:
             log = open(Openocd.logname).read()
-            if "OK GO NOW" in log:
+            if "Ready for Remote Connections" in log:
                 break
             if not self.process.poll() is None:
                 raise Exception(