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() for t in self.gdb.threads(): assertIn("main", t.frame) # Run to end for t in threads: self.gdb.thread(t) self.gdb.c() hart_ids = [] for t in self.gdb.threads(): assertIn("main_end", t.frame) # Check register values. self.gdb.thread(t) hart_id = self.gdb.p("$x1") assertNotIn(hart_id, hart_ids) hart_ids.append(hart_id) for n in range(2, 32): value = self.gdb.p("$x%d" % n) assertEqual(value, hart_ids[-1] + n - 1)
def test(self): if self.gdb.one_hart_per_gdb() or not self.server.smp(): return 'not_applicable' old_mtime = set() for _ in range(5): self.gdb.c_all(wait=False) time.sleep(2) self.gdb.interrupt_all() mtime_value = [] counter = [] for hart in self.target.harts: self.gdb.select_hart(hart) mv = self.gdb.p("mtime_value") assertNotIn(mv, old_mtime, "mtime doesn't appear to be changing at all") mtime_value.append(mv) c = self.gdb.p("counter") assertNotEqual(c, 0, "counter didn't increment; code didn't run?") counter.append(c) self.gdb.p("counter=0") old_mtime.update(mtime_value) mtime_spread = max(mtime_value) - min(mtime_value) print "mtime_spread:", mtime_spread counter_spread = max(counter) - min(counter) print "counter_spread:", counter_spread assertLess(mtime_spread, 100 * len(self.target.harts), "Harts don't halt around the same time.")
def test(self): # Get to a point in the code where some registers have actually been # used. self.gdb.b("rot13") self.gdb.c() self.gdb.c() # Try both forms to test gdb. for cmd in ("info all-registers", "info registers all"): output = self.gdb.command(cmd) assertNotIn("Could not", output) for reg in ('zero', 'ra', 'sp', 'gp', 'tp'): assertIn(reg, output) #TODO # mcpuid is one of the few registers that should have the high bit set # (for rv64). # Leave this commented out until gdb and spike agree on the encoding of # mcpuid (which is going to be renamed to misa in any case). #assertRegexpMatches(output, ".*mcpuid *0x80") #TODO: # The instret register should always be changing. #last_instret = None #for _ in range(5): # instret = self.gdb.p("$instret") # assertNotEqual(instret, last_instret) # last_instret = instret # self.gdb.stepi() self.exit()
def test(self): if self.gdb.one_hart_per_gdb(): raise TestNotApplicable # Set breakpoint near '_start' label to increase the chances of a # situation when all harts hit breakpoint immediately and # simultaneously. self.gdb.b("set_trap_handler") # Check that all harts hit breakpoint one by one. for _ in range(len(self.target.harts)): output = self.gdb.c() assertIn("hit Breakpoint", output) assertIn("set_trap_handler", output) assertNotIn("received signal SIGTRAP", output)
def test(self): if self.gdb.one_hart_per_gdb(): return 'not_applicable' # Set breakpoint near '_start' label to increase the chances of a # situation when all harts hit breakpoint immediately and # simultaneously. self.gdb.b("set_trap_handler") # Check that all harts hit breakpoint one by one. for _ in range(len(self.target.harts)): output = self.gdb.c() assertIn("hit Breakpoint", output) assertIn("set_trap_handler", output) assertNotIn("received signal SIGTRAP", output)
def test(self): threads = self.gdb.threads() if len(threads) < 2: return 'not_applicable' for t in threads: self.gdb.thread(t) self.gdb.p("$pc=_start") # Run to main self.gdb.b("main") self.gdb.c() for t in self.gdb.threads(): assertIn("main", t.frame) 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) # Check register values. self.gdb.thread(t) hart_id = self.gdb.p("$x1") assertNotIn(hart_id, hart_ids) hart_ids.append(hart_id) for n in range(2, 32): value = self.gdb.p("$x%d" % n) assertEqual(value, hart_ids[-1] + n - 1) # Confirmed that we read different register values for different harts. # Write a new value to x1, and run through the add sequence again. 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)
def test(self): # Run to main for hart in self.target.harts: self.gdb.select_hart(hart) self.gdb.b("main") self.gdb.c() assertIn("main", self.gdb.where()) self.gdb.command("delete breakpoints") # Run through the entire loop. for hart in self.target.harts: self.gdb.select_hart(hart) self.gdb.b("main_end") self.gdb.c() assertIn("main_end", self.gdb.where()) hart_ids = [] for hart in self.target.harts: self.gdb.select_hart(hart) # Check register values. x1 = self.gdb.p("$x1") hart_id = self.gdb.p("$mhartid") assertEqual(x1, hart_id) assertNotIn(hart_id, hart_ids) hart_ids.append(hart_id) for n in range(2, 32): value = self.gdb.p("$x%d" % n) assertEqual(value, hart_ids[-1] + n - 1) # Confirmed that we read different register values for different harts. # Write a new value to x1, and run through the add sequence again. for hart in self.target.harts: self.gdb.select_hart(hart) self.gdb.p("$x1=0x%x" % (hart.index * 0x800)) self.gdb.p("$pc=main_post_csrr") self.gdb.c() for hart in self.target.harts: self.gdb.select_hart(hart) assertIn("main", self.gdb.where()) # Check register values. for n in range(1, 32): value = self.gdb.p("$x%d" % n) assertEqual(value, hart.index * 0x800 + n - 1)
def test(self): if self.gdb.one_hart_per_gdb() or not self.server.smp(): raise TestNotApplicable old_mtime = set() for _ in range(5): self.gdb.c_all(wait=False) time.sleep(2) self.gdb.interrupt_all() mtime_value = [] counter = [] for hart in self.target.harts: self.gdb.select_hart(hart) mv = self.gdb.p("$s2") assertNotIn(mv, old_mtime, "mtime doesn't appear to be changing at all") mtime_value.append(mv) c = self.gdb.p("$s0") assertNotEqual(c, 0, "counter didn't increment; code didn't run?") counter.append(c) # Reset the counter for the next round. self.gdb.p("$s0=0") old_mtime.update(mtime_value) mtime_spread = max(mtime_value) - min(mtime_value) print "mtime_spread:", mtime_spread counter_spread = max(counter) - min(counter) print "counter_spread:", counter_spread assertLess(mtime_spread, 101 * (len(self.target.harts) - 1), "Harts don't halt around the same time.") # spike executes normal code 5000 instructions at a time, so we # expect 5k instructions to be executed on one hart before the # other gets to go. Our loop (unoptimized) is quite a few # instructions, but allow for 5k anyway. assertLess(counter_spread, 5001 * (len(self.target.harts) - 1), "Harts don't resume around the same time.")
def test(self): if self.gdb.one_hart_per_gdb() or not self.server.smp(): return 'not_applicable' old_mtime = set() for _ in range(5): self.gdb.c_all(wait=False) time.sleep(2) self.gdb.interrupt_all() mtime_value = [] counter = [] for hart in self.target.harts: self.gdb.select_hart(hart) mv = self.gdb.p("$s2") assertNotIn(mv, old_mtime, "mtime doesn't appear to be changing at all") mtime_value.append(mv) c = self.gdb.p("$s0") assertNotEqual(c, 0, "counter didn't increment; code didn't run?") counter.append(c) # Reset the counter for the next round. self.gdb.p("$s0=0") old_mtime.update(mtime_value) mtime_spread = max(mtime_value) - min(mtime_value) print "mtime_spread:", mtime_spread counter_spread = max(counter) - min(counter) print "counter_spread:", counter_spread assertLess(mtime_spread, 101 * (len(self.target.harts) - 1), "Harts don't halt around the same time.") # spike executes normal code 5000 instructions at a time, so we # expect 5k instructions to be executed on one hart before the # other gets to go. Our loop (unoptimized) is quite a few # instructions, but allow for 5k anyway. assertLess(counter_spread, 5001 * (len(self.target.harts) - 1), "Harts don't resume around the same time.")