Fix MulticoreRegTest.
[riscv-tests.git] / debug / testlib.py
index 385034b82a9103989059703c7d5a7e39b185b87a..e1be100f41ad3288eddb7ae41b09160b121c5cfa 100644 (file)
@@ -420,7 +420,17 @@ class Gdb(object):
             self.active_child.expect("Continuing")
 
     def c_all(self):
-        """Resume every hart."""
+        """
+        Resume every hart.
+
+        This function works fine when using multiple gdb sessions, but the
+        caller must be careful when using it nonetheless. gdb's behavior is to
+        not set breakpoints until just before the hart is resumed, and then
+        clears them as soon as the hart halts. That means that you can't set
+        one software breakpoint, and expect multiple harts to hit it. It's
+        possible that the first hart completes set/run/halt/clear before the
+        second hart even gets to resume, so it will never hit the breakpoint.
+        """
         with PrivateState(self):
             for child in self.children:
                 child.sendline("c")
@@ -532,14 +542,16 @@ def run_all_tests(module, target, parsed):
     gdb_cmd = parsed.gdb
 
     todo = []
+    examine_added = False
     for hart in target.harts:
         if parsed.misaval:
             hart.misa = int(parsed.misaval, 16)
             print "Using $misa from command line: 0x%x" % hart.misa
         elif hart.misa:
             print "Using $misa from hart definition: 0x%x" % hart.misa
-        else:
-            todo.append(("ExamineTarget", ExamineTarget, hart))
+        elif not examine_added:
+            todo.append(("ExamineTarget", ExamineTarget, None))
+            examine_added = True
 
     for name in dir(module):
         definition = getattr(module, name)
@@ -788,23 +800,26 @@ class GdbSingleHartTest(GdbTest):
 
 class ExamineTarget(GdbTest):
     def test(self):
-        self.hart.misa = self.gdb.p("$misa")
-
-        txt = "RV"
-        if (self.hart.misa >> 30) == 1:
-            txt += "32"
-        elif (self.hart.misa >> 62) == 2:
-            txt += "64"
-        elif (self.hart.misa >> 126) == 3:
-            txt += "128"
-        else:
-            raise TestFailed("Couldn't determine XLEN from $misa (0x%x)" %
-                    self.hart.misa)
+        for hart in self.target.harts:
+            self.gdb.select_hart(hart)
+
+            hart.misa = self.gdb.p("$misa")
+
+            txt = "RV"
+            if (hart.misa >> 30) == 1:
+                txt += "32"
+            elif (hart.misa >> 62) == 2:
+                txt += "64"
+            elif (hart.misa >> 126) == 3:
+                txt += "128"
+            else:
+                raise TestFailed("Couldn't determine XLEN from $misa (0x%x)" %
+                        self.hart.misa)
 
-        for i in range(26):
-            if self.hart.misa & (1<<i):
-                txt += chr(i + ord('A'))
-        print txt,
+            for i in range(26):
+                if hart.misa & (1<<i):
+                    txt += chr(i + ord('A'))
+            print txt,
 
 class TestFailed(Exception):
     def __init__(self, message):