diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 3484906a0..4476ea853 100755 --- a/debug/gdbserver.py +++ b/debug/gdbserver.py @@ -409,6 +409,21 @@ class MemTestBlock2(MemTestBlock): def test(self): return self.test_block(2) +class DisconnectTest(GdbTest): + def test(self): + old_values = self.gdb.info_registers("all", ops=20) + self.gdb.disconnect() + self.gdb.connect() + self.gdb.select_hart(self.hart) + new_values = self.gdb.info_registers("all", ops=20) + + regnames = set(old_values.keys()).union(set(new_values.keys())) + for regname in regnames: + if regname in ("mcycle", "minstret", "instret", "cycle"): + continue + assertEqual(old_values[regname], new_values[regname], + "Register %s didn't match" % regname) + class InstantHaltTest(GdbTest): def test(self): """Assert that reset is really resetting what it should.""" @@ -553,7 +568,9 @@ def test(self): last_pc = None advances = 0 jumps = 0 - for _ in range(10): + start = time.time() + count = 10 + for _ in range(count): self.gdb.stepi() pc = self.gdb.p("$pc") assertNotEqual(last_pc, pc) @@ -562,6 +579,8 @@ def test(self): else: jumps += 1 last_pc = pc + end = time.time() + print("%.2f seconds/step" % ((end - start) / count)) # Some basic sanity that we're not running between breakpoints or # something. assertGreater(jumps, 1) diff --git a/debug/targets/RISC-V/spike-2-hwthread.cfg b/debug/targets/RISC-V/spike-2-hwthread.cfg index c378a4574..dc60ced39 100644 --- a/debug/targets/RISC-V/spike-2-hwthread.cfg +++ b/debug/targets/RISC-V/spike-2-hwthread.cfg @@ -25,6 +25,8 @@ foreach t [target names] { riscv expose_custom 1,12345-12348 } +riscv resume_order reversed + init set challenge [riscv authdata_read] diff --git a/debug/testlib.py b/debug/testlib.py index b97b607c3..25ff5becb 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -585,11 +585,6 @@ def __init__(self, target, ports, cmd=None, timeout=60, binaries=None): child.logfile = logfile child.logfile.write(("+ %s\n" % self.cmd).encode()) self.children.append(child) - self.active_child = self.children[0] - - def connect(self): - for port, child, binary in zip(self.ports, self.children, - self.binaries): self.select_child(child) self.wait() self.command("set style enabled off", reset_delays=None) @@ -599,28 +594,42 @@ def connect(self): # Force consistency. self.command("set print entry-values no", reset_delays=None) self.command("set remotetimeout %d" % self.timeout, - reset_delays=None) - self.command("target extended-remote localhost:%d" % port, ops=10, - reset_delays=None) - if binary: - output = self.command("file %s" % binary) - assertIn("Reading symbols", output) - threads = self.threads() - for t in threads: - hartid = None - if t.name: - m = re.search(r"Hart (\d+)", t.name) - if m: - hartid = int(m.group(1)) - if hartid is None: - if self.harts: - hartid = max(self.harts) + 1 - else: - hartid = 0 - # solo: True iff this is the only thread on this child - self.harts[hartid] = {'child': child, - 'thread': t, - 'solo': len(threads) == 1} + reset_delays=None) + self.command("set remotetimeout %d" % self.target.timeout_sec) + self.active_child = self.children[0] + + def connect(self): + with PrivateState(self): + for port, child, binary in zip(self.ports, self.children, + self.binaries): + self.select_child(child) + self.command("target extended-remote localhost:%d" % port, + ops=10, reset_delays=None) + if binary: + output = self.command("file %s" % binary) + assertIn("Reading symbols", output) + threads = self.threads() + for t in threads: + hartid = None + if t.name: + m = re.search(r"Hart (\d+)", t.name) + if m: + hartid = int(m.group(1)) + if hartid is None: + if self.harts: + hartid = max(self.harts) + 1 + else: + hartid = 0 + # solo: True iff this is the only thread on this child + self.harts[hartid] = {'child': child, + 'thread': t, + 'solo': len(threads) == 1} + + def disconnect(self): + with PrivateState(self): + for child in self.children: + self.select_child(child) + self.command("disconnect") def __del__(self): for child in self.children: @@ -1143,9 +1152,6 @@ def classSetup(self): self.logs += self.gdb.lognames() self.gdb.connect() - self.gdb.global_command("set remotetimeout %d" % - self.target.timeout_sec) - for cmd in self.target.gdb_setup: self.gdb.command(cmd) @@ -1236,9 +1242,9 @@ def __init__(self, message=""): Exception.__init__(self) self.message = message -def assertEqual(a, b): +def assertEqual(a, b, comment=None): if a != b: - raise TestFailed("%r != %r" % (a, b)) + raise TestFailed("%r != %r" % (a, b), comment) def assertNotEqual(a, b, comment=None): if a == b: