Fail if simulator exits early.
[riscv-tests.git] / debug / testlib.py
index a66d59a7b450baf63e7b99aa6c50ef6e0ded3fec..3d08e9b33e172388433950d74f5de40cbb27d2fb 100644 (file)
@@ -67,17 +67,20 @@ class Spike(object):
             spike = os.path.expandvars("$RISCV/bin/spike")
             cmd = [spike]
         if xlen == 32:
-            cmd += ["--isa", "RV32"]
+            cmd += ["--isa", "RV32G"]
+        else:
+            cmd += ["--isa", "RV64G"]
 
         if timeout:
             cmd = ["timeout", str(timeout)] + cmd
 
+        cmd += ["-m0x10000000:0x10000000"]
+
         if halted:
             cmd.append('-H')
         if with_jtag_gdb:
             cmd += ['--rbb-port', '0']
             os.environ['REMOTE_BITBANG_HOST'] = 'localhost'
-        cmd.append("-m32")
         cmd.append('programs/infinite_loop')
         if binary:
             cmd.append(binary)
@@ -113,7 +116,7 @@ class Spike(object):
 class VcsSim(object):
     def __init__(self, sim_cmd=None, debug=False):
         if sim_cmd:
-            cmd = shlex.split(simv)
+            cmd = shlex.split(sim_cmd)
         else:
             cmd = ["simv"]
         cmd += ["+jtag_vpi_enable"]
@@ -129,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)
@@ -367,7 +376,13 @@ 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 \
@@ -395,12 +410,15 @@ 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:
@@ -538,7 +556,8 @@ class GdbTest(BaseTest):
             self.gdb.command(
                     "target extended-remote localhost:%d" % self.server.port)
 
-        self.gdb.p("$priv=3")
+        # FIXME: OpenOCD doesn't handle PRIV now
+        #self.gdb.p("$priv=3")
 
     def classTeardown(self):
         del self.gdb