From 515d185db118a54e920514c6fc7783d95b530d4c Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Fri, 12 Nov 2021 11:29:20 -0800 Subject: Create DisconnectTest. (#364) Disconnects from gdb, and then reconnects, making sure that didn't change any of the registers. This test will start passing when https://github.com/riscv/riscv-openocd/pull/661 merges. --- debug/gdbserver.py | 15 ++++++++++++ debug/testlib.py | 70 +++++++++++++++++++++++++++++------------------------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/debug/gdbserver.py b/debug/gdbserver.py index 69bb3b1..4476ea8 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.""" diff --git a/debug/testlib.py b/debug/testlib.py index b97b607..25ff5be 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -585,11 +585,6 @@ class Gdb: 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 @@ class Gdb: # 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 @@ class GdbTest(BaseTest): 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 @@ class TestNotApplicable(Exception): 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: -- cgit v1.1