From 016147c6167f714c95dbfe9d99d6b983e6202507 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Fri, 18 May 2018 18:12:00 -0700 Subject: [PATCH] Fix MulticoreRunHaltStepiTest The test actually wasn't checking interrupt counts at all. Fixing it required some other changes: Make sure all harts get to run Add some retries, since on a loaded machine against spike both harts might not get to run, even if you give spike a generous amount of time to do so. --- debug/gdbserver.py | 56 ++++++++++++++++++++++++++++++---------------- debug/testlib.py | 13 +++++++---- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/debug/gdbserver.py b/debug/gdbserver.py index be89d19..257f8d4 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -562,30 +562,48 @@ class MulticoreRunHaltStepiTest(GdbTest): self.gdb.load() for hart in self.target.harts: self.gdb.select_hart(hart) + self.gdb.p("$mhartid") self.gdb.p("$pc=_start") def test(self): previous_hart_count = [0 for h in self.target.harts] previous_interrupt_count = [0 for h in self.target.harts] - for _ in range(10): - self.gdb.c(wait=False) - time.sleep(2) - self.gdb.interrupt() - self.gdb.p("$mie") - self.gdb.p("$mip") - self.gdb.p("$mstatus") - self.gdb.p("$priv") - self.gdb.p("buf", fmt="") - hart_count = self.gdb.p("hart_count") - interrupt_count = self.gdb.p("interrupt_count") - for i, h in enumerate(self.target.harts): - assertGreater(hart_count[i], previous_hart_count[i]) - assertGreater(interrupt_count[i], previous_interrupt_count[i]) - self.gdb.select_hart(h) - pc = self.gdb.p("$pc") - self.gdb.stepi() - stepped_pc = self.gdb.p("$pc") - assertNotEqual(pc, stepped_pc) + # Check 10 times + for i in range(10): + # 3 attempts for each time we want the check to pass + for attempt in range(3): + self.gdb.global_command("echo round %d attempt %d\\n" % (i, + attempt)) + self.gdb.c_all(wait=False) + time.sleep(2) + self.gdb.interrupt_all() + hart_count = self.gdb.p("hart_count") + interrupt_count = self.gdb.p("interrupt_count") + ok = True + for i, h in enumerate(self.target.harts): + if hart_count[i] <= previous_hart_count[i]: + ok = False + break + if interrupt_count[i] <= previous_interrupt_count[i]: + ok = False + break + self.gdb.p("$mie") + self.gdb.p("$mip") + self.gdb.p("$mstatus") + self.gdb.p("$priv") + self.gdb.p("buf", fmt="") + self.gdb.select_hart(h) + pc = self.gdb.p("$pc") + self.gdb.stepi() + stepped_pc = self.gdb.p("$pc") + assertNotEqual(pc, stepped_pc) + previous_hart_count = hart_count + previous_interrupt_count = interrupt_count + if ok: + break + else: + assert False, \ + "hart count or interrupt didn't increment as expected" class MulticoreRunAllHaltOne(GdbTest): compile_args = ("programs/multicore.c", "-DMULTICORE") diff --git a/debug/testlib.py b/debug/testlib.py index fb5bee3..2fd978c 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -477,7 +477,7 @@ class Gdb(object): self.active_child.sendline("c%s" % async) self.active_child.expect("Continuing", timeout=ops * self.timeout) - def c_all(self): + def c_all(self, wait=True): """ Resume every hart. @@ -494,15 +494,20 @@ class Gdb(object): child.sendline("c") child.expect("Continuing") - # Now wait for them all to halt - for child in self.children: - child.expect(r"\(gdb\)") + if wait: + for child in self.children: + child.expect(r"\(gdb\)") def interrupt(self): self.active_child.send("\003") self.active_child.expect(r"\(gdb\)", timeout=6000) return self.active_child.before.strip() + def interrupt_all(self): + for child in self.children: + self.select_child(child) + self.interrupt() + def x(self, address, size='w'): output = self.command("x/%s %s" % (size, address)) value = int(output.split(':')[1].strip(), 0) -- 2.30.2