aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2023-07-06 14:41:02 -0700
committerTim Newsome <tim@sifive.com>2023-07-17 09:35:00 -0700
commitba831d02bdb4249ef744bd04da6c912680c7b66e (patch)
tree751ba413a8eb563a06772facfc74f2d60fc39072
parente1cb5be2709f461459b07221a15587e388fa90be (diff)
downloadriscv-tests-ba831d02bdb4249ef744bd04da6c912680c7b66e.zip
riscv-tests-ba831d02bdb4249ef744bd04da6c912680c7b66e.tar.gz
riscv-tests-ba831d02bdb4249ef744bd04da6c912680c7b66e.tar.bz2
debug: CeaseMultiTest -> UnavailableMultiTest
Use the new spike mechanism to test OpenOCD behavior when a hart becomes unavailable while running. Create CommandException.
-rwxr-xr-xdebug/gdbserver.py19
-rw-r--r--debug/testlib.py19
2 files changed, 30 insertions, 8 deletions
diff --git a/debug/gdbserver.py b/debug/gdbserver.py
index 04180c3..bf04f2e 100755
--- a/debug/gdbserver.py
+++ b/debug/gdbserver.py
@@ -19,7 +19,7 @@ from testlib import assertGreater, assertRegex, assertLess
from testlib import GdbTest, GdbSingleHartTest, TestFailed
from testlib import TestNotApplicable, CompileError
from testlib import UnknownThread
-from testlib import CouldNotReadRegisters
+from testlib import CouldNotReadRegisters, CommandException
MSTATUS_UIE = 0x00000001
MSTATUS_SIE = 0x00000002
@@ -1807,14 +1807,16 @@ class EbreakTest(GdbSingleHartTest):
output = self.gdb.c()
assertIn("_exit", output)
-class CeaseMultiTest(GdbTest):
- """Test that we work correctly when a hart ceases to respond (e.g. because
+class UnavailableMultiTest(GdbTest):
+ """Test that we work correctly when a hart becomes unavailable (e.g. because
it's powered down)."""
compile_args = ("programs/counting_loop.c", "-DDEFINE_MALLOC",
"-DDEFINE_FREE")
def early_applicable(self):
- return self.hart.support_cease and len(self.target.harts) > 1
+ return (self.hart.support_cease or
+ self.target.support_unavailable_control) \
+ and len(self.target.harts) > 1
def setup(self):
ProgramTest.setup(self)
@@ -1822,7 +1824,12 @@ class CeaseMultiTest(GdbTest):
def test(self):
# Run all the way to the infinite loop in exit
- self.gdb.c(wait=False)
+ self.gdb.c_all(wait=False)
+ # Other hart should have become unavailable.
+ if self.target.support_unavailable_control:
+ self.server.wait_until_running(self.target.harts)
+ self.server.command(
+ f"riscv dmi_write 0x1f 0x{(1<<self.hart.id)&0x3:x}")
self.gdb.expect(r"\S+ became unavailable.")
self.gdb.interrupt()
@@ -1834,7 +1841,7 @@ class CeaseMultiTest(GdbTest):
self.gdb.p("$misa")
assert False, \
"Shouldn't be able to access unavailable hart."
- except UnknownThread:
+ except (UnknownThread, CommandException):
pass
# Check that the main hart can still be debugged.
diff --git a/debug/testlib.py b/debug/testlib.py
index 5c09f0a..fd9882a 100644
--- a/debug/testlib.py
+++ b/debug/testlib.py
@@ -652,6 +652,15 @@ def parse_rhs(text):
raise TestLibError(f"Unexpected input: {tokens!r}")
return result
+class CommandException(Exception):
+ pass
+
+class CommandSendTimeout(CommandException):
+ pass
+
+class CommandCompleteTimeout(CommandException):
+ pass
+
class Gdb:
"""A single gdb class which can interact with one or more gdb instances."""
@@ -780,8 +789,14 @@ class Gdb:
reset_delays=None)
timeout = max(1, ops) * self.timeout
self.active_child.sendline(command)
- self.active_child.expect("\n", timeout=timeout)
- self.active_child.expect(r"\(gdb\)", timeout=timeout)
+ try:
+ self.active_child.expect("\n", timeout=timeout)
+ except pexpect.exceptions.TIMEOUT as exc:
+ raise CommandSendTimeout(command) from exc
+ try:
+ self.active_child.expect(r"\(gdb\)", timeout=timeout)
+ except pexpect.exceptions.TIMEOUT as exc:
+ raise CommandCompleteTimeout(command) from exc
output = self.active_child.before.decode("utf-8", errors="ignore")
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
return ansi_escape.sub('', output).strip()