Default to openocd, not riscv-openocd
[riscv-tests.git] / debug / testlib.py
index ecb0431e128e5d3941245821c5a275f4eaabe899..27bef1a7699c9d9d0f66a13fe416c0d8e954663a 100644 (file)
@@ -21,12 +21,12 @@ def find_file(path):
 def compile(args, xlen=32): # pylint: disable=redefined-builtin
     cc = os.path.expandvars("$RISCV/bin/riscv64-unknown-elf-gcc")
     cmd = [cc, "-g"]
-    if (xlen == 32):
+    if xlen == 32:
         cmd.append("-march=rv32imac")
         cmd.append("-mabi=ilp32")
     else:
         cmd.append("-march=rv64imac")
-        cmd.append("-mabi=lp64")        
+        cmd.append("-mabi=lp64")
     for arg in args:
         found = find_file(arg)
         if found:
@@ -74,6 +74,8 @@ class Spike(object):
         if timeout:
             cmd = ["timeout", str(timeout)] + cmd
 
+        cmd += ["-m0x10000000:0x10000000"]
+
         if halted:
             cmd.append('-H')
         if with_jtag_gdb:
@@ -130,6 +132,12 @@ class VcsSim(object):
                 stdout=logfile, stderr=logfile)
         done = False
         while not done:
+            # Fail if VCS exits early
+            exit_code = self.process.poll()
+            if exit_code is not None:
+                raise RuntimeError('VCS simulator exited early with status %d'
+                                   % exit_code)
+
             line = listenfile.readline()
             if not line:
                 time.sleep(1)
@@ -153,11 +161,11 @@ class Openocd(object):
         if server_cmd:
             cmd = shlex.split(server_cmd)
         else:
-            openocd = os.path.expandvars("$RISCV/bin/riscv-openocd")
+            openocd = os.path.expandvars("$RISCV/bin/openocd")
             cmd = [openocd]
-            if (debug):
+            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 += [
@@ -176,7 +184,7 @@ class Openocd(object):
         if config:
             f = find_file(config)
             if f is None:
-                print("Unable to read file " + config)
+                print "Unable to read file " + config
                 exit(1)
 
             cmd += ["-f", f]
@@ -368,7 +376,14 @@ def run_all_tests(module, target, parsed):
     global gdb_cmd  # pylint: disable=global-statement
     gdb_cmd = parsed.gdb
 
-    todo = [("ExamineTarget", ExamineTarget)]
+    todo = []
+    if parsed.misaval:
+        target.misa = int(parsed.misaval, 16)
+        print "Assuming $MISA value of 0x%x. Skipping ExamineTarget." % \
+                target.misa
+    else:
+        todo.append(("ExamineTarget", ExamineTarget))
+
     for name in dir(module):
         definition = getattr(module, name)
         if type(definition) == type and hasattr(definition, 'test') and \
@@ -396,12 +411,16 @@ def run_all_tests(module, target, parsed):
     return result
 
 def add_test_run_options(parser):
+
     parser.add_argument("--fail-fast", "-f", action="store_true",
             help="Exit as soon as any test fails.")
     parser.add_argument("test", nargs='*',
             help="Run only tests that are named here.")
     parser.add_argument("--gdb",
             help="The command to use to start gdb.")
+    parser.add_argument("--misaval",
+            help="Don't run ExamineTarget, just assume the misa value which is "
+            "specified.")
 
 def header(title, dash='-'):
     if title: