Skip to content

Commit ba831d0

Browse files
committed
debug: CeaseMultiTest -> UnavailableMultiTest
Use the new spike mechanism to test OpenOCD behavior when a hart becomes unavailable while running. Create CommandException.
1 parent e1cb5be commit ba831d0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

debug/gdbserver.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from testlib import GdbTest, GdbSingleHartTest, TestFailed
2020
from testlib import TestNotApplicable, CompileError
2121
from testlib import UnknownThread
22-
from testlib import CouldNotReadRegisters
22+
from testlib import CouldNotReadRegisters, CommandException
2323

2424
MSTATUS_UIE = 0x00000001
2525
MSTATUS_SIE = 0x00000002
@@ -1807,22 +1807,29 @@ def test(self):
18071807
output = self.gdb.c()
18081808
assertIn("_exit", output)
18091809

1810-
class CeaseMultiTest(GdbTest):
1811-
"""Test that we work correctly when a hart ceases to respond (e.g. because
1810+
class UnavailableMultiTest(GdbTest):
1811+
"""Test that we work correctly when a hart becomes unavailable (e.g. because
18121812
it's powered down)."""
18131813
compile_args = ("programs/counting_loop.c", "-DDEFINE_MALLOC",
18141814
"-DDEFINE_FREE")
18151815

18161816
def early_applicable(self):
1817-
return self.hart.support_cease and len(self.target.harts) > 1
1817+
return (self.hart.support_cease or
1818+
self.target.support_unavailable_control) \
1819+
and len(self.target.harts) > 1
18181820

18191821
def setup(self):
18201822
ProgramTest.setup(self)
18211823
self.parkOtherHarts()
18221824

18231825
def test(self):
18241826
# Run all the way to the infinite loop in exit
1825-
self.gdb.c(wait=False)
1827+
self.gdb.c_all(wait=False)
1828+
# Other hart should have become unavailable.
1829+
if self.target.support_unavailable_control:
1830+
self.server.wait_until_running(self.target.harts)
1831+
self.server.command(
1832+
f"riscv dmi_write 0x1f 0x{(1<<self.hart.id)&0x3:x}")
18261833
self.gdb.expect(r"\S+ became unavailable.")
18271834
self.gdb.interrupt()
18281835

@@ -1834,7 +1841,7 @@ def test(self):
18341841
self.gdb.p("$misa")
18351842
assert False, \
18361843
"Shouldn't be able to access unavailable hart."
1837-
except UnknownThread:
1844+
except (UnknownThread, CommandException):
18381845
pass
18391846

18401847
# Check that the main hart can still be debugged.

debug/testlib.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,15 @@ def parse_rhs(text):
652652
raise TestLibError(f"Unexpected input: {tokens!r}")
653653
return result
654654

655+
class CommandException(Exception):
656+
pass
657+
658+
class CommandSendTimeout(CommandException):
659+
pass
660+
661+
class CommandCompleteTimeout(CommandException):
662+
pass
663+
655664
class Gdb:
656665
"""A single gdb class which can interact with one or more gdb instances."""
657666

@@ -780,8 +789,14 @@ def command(self, command, ops=1, reset_delays=0):
780789
reset_delays=None)
781790
timeout = max(1, ops) * self.timeout
782791
self.active_child.sendline(command)
783-
self.active_child.expect("\n", timeout=timeout)
784-
self.active_child.expect(r"\(gdb\)", timeout=timeout)
792+
try:
793+
self.active_child.expect("\n", timeout=timeout)
794+
except pexpect.exceptions.TIMEOUT as exc:
795+
raise CommandSendTimeout(command) from exc
796+
try:
797+
self.active_child.expect(r"\(gdb\)", timeout=timeout)
798+
except pexpect.exceptions.TIMEOUT as exc:
799+
raise CommandCompleteTimeout(command) from exc
785800
output = self.active_child.before.decode("utf-8", errors="ignore")
786801
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
787802
return ansi_escape.sub('', output).strip()

0 commit comments

Comments
 (0)