Skip to content

Commit 995fa25

Browse files
committed
debug: CeaseRunTest -> UnavailableRunTest
Use new spike mechanism to test OpenOCD behavior when the current hart becomes unavailable while running. Create ThreadTerminated exception.
1 parent ba831d0 commit 995fa25

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

debug/gdbserver.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from testlib import TestNotApplicable, CompileError
2121
from testlib import UnknownThread
2222
from testlib import CouldNotReadRegisters, CommandException
23+
from testlib import ThreadTerminated
2324

2425
MSTATUS_UIE = 0x00000001
2526
MSTATUS_SIE = 0x00000002
@@ -1879,22 +1880,36 @@ def test(self):
18791880
except CouldNotReadRegisters:
18801881
pass
18811882

1882-
class CeaseRunTest(ProgramTest):
1883+
class UnavailableRunTest(ProgramTest):
18831884
"""Test that we work correctly when the hart we're debugging ceases to
18841885
respond."""
18851886
def early_applicable(self):
1886-
return self.hart.support_cease
1887+
return self.hart.support_cease or \
1888+
self.target.support_unavailable_control
18871889

18881890
def test(self):
18891891
self.gdb.b("main")
18901892
output = self.gdb.c()
18911893
assertIn("Breakpoint", output)
18921894
assertIn("main", output)
18931895

1894-
self.gdb.p("$pc=precease")
1896+
if self.target.support_unavailable_control:
1897+
self.gdb.p("$pc=loop_forever")
1898+
else:
1899+
self.gdb.p("$pc=cease")
18951900
self.gdb.c(wait=False)
1901+
if self.target.support_unavailable_control:
1902+
self.server.wait_until_running([self.hart])
1903+
self.server.command(
1904+
f"riscv dmi_write 0x1f 0x{(~(1<<self.hart.id))&0x3:x}")
18961905
self.gdb.expect(r"\S+ became unavailable.")
18971906
self.gdb.interrupt()
1907+
# gdb might automatically switch to the available hart.
1908+
try:
1909+
self.gdb.select_hart(self.hart)
1910+
except ThreadTerminated:
1911+
# GDB sees that the thread is gone. Count this as success.
1912+
return
18981913
try:
18991914
self.gdb.p("$pc")
19001915
assert False, ("Registers shouldn't be accessible when the hart is "

debug/testlib.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ class UnknownThread(Exception):
555555
def __init__(self, explanation):
556556
Exception.__init__(self, explanation)
557557

558+
class ThreadTerminated(Exception):
559+
pass
560+
558561
Thread = collections.namedtuple('Thread', ('id', 'description', 'target_id',
559562
'name', 'frame'))
560563

@@ -762,6 +765,8 @@ def select_hart(self, hart):
762765
output = self.command(f"thread {h['thread'].id}", ops=5)
763766
if "Unknown" in output:
764767
raise UnknownThread(output)
768+
if f"Thread ID {h['thread'].id} has terminated" in output:
769+
raise ThreadTerminated(output)
765770

766771
def push_state(self):
767772
self.stack.append({

0 commit comments

Comments
 (0)