Fix the end of MulticoreTest.
[riscv-tests.git] / debug / gdbserver.py
index 2dcd4043c147b338ed2afa5a1420b7c89863c241..dea9990ceca844866e345816c6c1783796099417 100755 (executable)
@@ -205,7 +205,16 @@ class MemTestBlock(GdbTest):
 
 class InstantHaltTest(GdbTest):
     def test(self):
-        assertEqual(self.target.reset_vector, self.gdb.p("$pc"))
+        """Assert that reset is really resetting what it should."""
+        self.gdb.command("monitor reset halt")
+        self.gdb.command("flushregs")
+        threads = self.gdb.threads()
+        pcs = []
+        for t in threads:
+            self.gdb.thread(t)
+            pcs.append(self.gdb.p("$pc"))
+        for pc in pcs:
+            assertEqual(self.target.reset_vector, pc)
         # mcycle and minstret have no defined reset value.
         mstatus = self.gdb.p("$mstatus")
         assertEqual(mstatus & (MSTATUS_MIE | MSTATUS_MPRV |
@@ -215,6 +224,8 @@ class InstantChangePc(GdbTest):
     def test(self):
         """Change the PC right as we come out of reset."""
         # 0x13 is nop
+        self.gdb.command("monitor reset halt")
+        self.gdb.command("flushregs")
         self.gdb.command("p *((int*) 0x%x)=0x13" % self.target.ram)
         self.gdb.command("p *((int*) 0x%x)=0x13" % (self.target.ram + 4))
         self.gdb.command("p *((int*) 0x%x)=0x13" % (self.target.ram + 8))
@@ -318,6 +329,12 @@ class Hwbp1(DebugTest):
         if self.target.instruction_hardware_breakpoint_count < 1:
             return 'not_applicable'
 
+        if not self.target.honors_tdata1_hmode:
+            # Run to main before setting the breakpoint, because startup code
+            # will otherwise clear the trigger that we set.
+            self.gdb.b("main")
+            self.gdb.c()
+
         self.gdb.hbreak("rot13")
         # The breakpoint should be hit exactly 2 times.
         for _ in range(2):
@@ -404,29 +421,27 @@ class MulticoreTest(GdbTest):
 
     def setup(self):
         self.gdb.load()
-        self.gdb.b("main")
-        self.gdb.b("main_end")
-        self.gdb.command("set non-stop on")
-        self.gdb.c()
 
     def test(self):
         threads = self.gdb.threads()
         if len(threads) < 2:
             return 'not_applicable'
-        # Run through the entire loop.
+
         for t in threads:
             self.gdb.thread(t)
             self.gdb.p("$pc=_start")
+
         # Run to main
-        for t in threads:
-            self.gdb.thread(t)
-            self.gdb.c()
+        self.gdb.b("main")
+        self.gdb.c()
         for t in self.gdb.threads():
             assertIn("main", t.frame)
-        # Run to end
-        for t in threads:
-            self.gdb.thread(t)
-            self.gdb.c()
+        self.gdb.command("delete breakpoints")
+
+        # Run through the entire loop.
+        self.gdb.b("main_end")
+        self.gdb.c()
+
         hart_ids = []
         for t in self.gdb.threads():
             assertIn("main_end", t.frame)
@@ -442,24 +457,18 @@ class MulticoreTest(GdbTest):
         # Confirmed that we read different register values for different harts.
         # Write a new value to x1, and run through the add sequence again.
 
-        # This part isn't working right, because gdb doesn't resume Thread 2
-        # when asked. I don't know the root cause for that, but up to this
-        # point the test is still useful.
-
-#        for t in threads:
-#            self.gdb.thread(t)
-#            self.gdb.p("$x1=0x%x" % (int(t.id) + 0x800))
-#            self.gdb.p("$pc=main_post_csrr")
-#        for t in threads:
-#            self.gdb.thread(t)
-#            self.gdb.c()
-#        for t in self.gdb.threads():
-#            assertIn("main_end", t.frame)
-#            # Check register values.
-#            self.gdb.thread(t)
-#            for n in range(1, 32):
-#                value = self.gdb.p("$x%d" % n)
-#                assertEqual(value, int(t.id) + 0x800 + n - 1)
+        for t in threads:
+            self.gdb.thread(t)
+            self.gdb.p("$x1=0x%x" % (int(t.id) * 0x800))
+            self.gdb.p("$pc=main_post_csrr")
+        self.gdb.c()
+        for t in self.gdb.threads():
+            assertIn("main_end", t.frame)
+            # Check register values.
+            self.gdb.thread(t)
+            for n in range(1, 32):
+                value = self.gdb.p("$x%d" % n)
+                assertEqual(value, int(t.id) * 0x800 + n - 1)
 
 class StepTest(GdbTest):
     compile_args = ("programs/step.S", )
@@ -549,6 +558,9 @@ class TriggerStoreAddressInstant(TriggerTest):
         assertEqual(self.gdb.p("$a0"), self.gdb.p("&data"))
 
 class TriggerDmode(TriggerTest):
+    def early_applicable(self):
+        return self.target.honors_tdata1_hmode
+
     def check_triggers(self, tdata1_lsbs, tdata2):
         dmode = 1 << (self.target.xlen-5)
 
@@ -757,8 +769,8 @@ def main():
     # TODO: remove global
     global parsed   # pylint: disable=global-statement
     parsed = parser.parse_args()
+    target = targets.target(parsed)
 
-    target = parsed.target(parsed.server_cmd, parsed.sim_cmd, parsed.isolate)
     if parsed.xlen:
         target.xlen = parsed.xlen