Skip to content

Commit

Permalink
Manually exclude write protection for tests with writeable .text section
Browse files Browse the repository at this point in the history
  • Loading branch information
piotro888 committed Oct 22, 2023
1 parent afc4023 commit d1dd839
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions test/regression/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def write(self, req: WriteRequest) -> WriteReply:
return WriteReply(status=ReplyStatus.ERROR)


def load_segments_from_elf(file_path: str) -> list[RandomAccessMemory]:
def load_segments_from_elf(file_path: str, *, disable_write_protection: bool = False) -> list[RandomAccessMemory]:
segments: list[RandomAccessMemory] = []

with open(file_path, "rb") as f:
Expand All @@ -162,7 +162,7 @@ def align_down(n: int) -> int:
flags = SegmentFlags(0)
if flags_raw & P_FLAGS.PF_R:
flags |= SegmentFlags.READ
if flags_raw & P_FLAGS.PF_W:
if flags_raw & P_FLAGS.PF_W or disable_write_protection:
flags |= SegmentFlags.WRITE
if flags_raw & P_FLAGS.PF_X:
flags |= SegmentFlags.EXECUTABLE
Expand Down
9 changes: 8 additions & 1 deletion test/regression/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
test_dir = Path(__file__).parent.parent
riscv_tests_dir = test_dir.joinpath("external/riscv-tests")

# disable write protection for specific tests with writes to .text section
exclude_write_protection = ["rv32uc-rvc"]


class MMIO(MemorySegment):
def __init__(self, on_finish: Callable[[], None]):
Expand All @@ -31,7 +34,11 @@ async def run_test(sim_backend: SimulationBackend, test_name: str):
mmio = MMIO(lambda: sim_backend.stop())

mem_segments: list[MemorySegment] = []
mem_segments += load_segments_from_elf(str(riscv_tests_dir.joinpath("test-" + test_name)))
print(test_name)
mem_segments += load_segments_from_elf(
str(riscv_tests_dir.joinpath("test-" + test_name)),
disable_write_protection=test_name in exclude_write_protection,
)
mem_segments.append(mmio)

mem_model = CoreMemoryModel(mem_segments)
Expand Down

0 comments on commit d1dd839

Please sign in to comment.