Skip to content

Fix misleading debug output when unpriv test traps#1441

Open
Jjateen wants to merge 1 commit intoriscv:act4from
Jjateen:fix/trap-debug-1359
Open

Fix misleading debug output when unpriv test traps#1441
Jjateen wants to merge 1 commit intoriscv:act4from
Jjateen:fix/trap-debug-1359

Conversation

@Jjateen
Copy link
Copy Markdown
Contributor

@Jjateen Jjateen commented May 6, 2026

When the M-mode trap handler aborted a test due to an unsupported instruction, failure_type 3 fell through to failedtest_saveresults_int, which reconstructed a non-existent beq/ld instruction pair and filled failing_reg, failing_value, and expected_value with garbage. The reporter then printed those garbage values as "Bad Value" / "Expected Value", making the output look like a register comparison failure rather than a trap abort.

Two fixes in rvtest_failure_code.h:

  • Add a dispatch for failure_type == 3 at failedtest_saveresults that branches to a new failedtest_saveresults_trap label, bypassing the integer beq/ld reconstruction entirely and jumping straight to the common string-pointer loading path.
  • After printing "RVCP: Test Info:" in failedtest_report, check for failure_type == 3 and branch directly to failedtest_report_traphandler, skipping the instruction / approximate address / register / bad-value / expected-value fields that are meaningless for a trap abort.

After the fix the output for a trapped test is:

RVCP-SUMMARY: TEST FAILED - Test File "..."
RVCP: DEBUG INFORMATION FOLLOWS
RVCP: Test Info: "The trap handler aborted the test before normal completion!"
RVCP: Address of instruction that trapped (XEPC): 0x...
RVCP: Instruction that trapped: 0x...
RVCP: END OF DEBUG INFORMATION

This applies to both the ref-model build step (where sail now produces a clear trap message before exiting non-zero) and to the selfcheck ELF running on the DUT.

Fixes #1359.

@Jjateen Jjateen changed the title Fix misleading debug output when unpriv test traps (#1359) Fix misleading debug output when unpriv test traps May 6, 2026
@Jjateen Jjateen force-pushed the fix/trap-debug-1359 branch from 5b3fc47 to dedf93b Compare May 6, 2026 11:20
When the M-mode trap handler aborted a test due to an unsupported
instruction, failure_type 3 fell through to failedtest_saveresults_int,
which reconstructed a non-existent beq/ld instruction pair and filled
failing_reg, failing_value, and expected_value with garbage. The reporter
then printed those garbage values as "Bad Value" / "Expected Value",
making the output look like a register comparison failure rather than
a trap abort.

Two fixes in rvtest_failure_code.h:
- Add a dispatch for failure_type == 3 at failedtest_saveresults that
  branches to a new failedtest_saveresults_trap label, bypassing the
  integer beq/ld reconstruction entirely and jumping straight to the
  common string-pointer loading path.
- After printing "RVCP: Test Info:" in failedtest_report, check for
  failure_type == 3 and branch directly to failedtest_report_traphandler,
  skipping the instruction / approximate address / register / bad-value /
  expected-value fields that are meaningless for a trap abort.

After the fix the output for a trapped test is:

  RVCP-SUMMARY: TEST FAILED - Test File "..."
  RVCP: DEBUG INFORMATION FOLLOWS
  RVCP: Test Info: "The trap handler aborted the test before normal completion!"
  RVCP: Address of instruction that trapped (XEPC): 0x...
  RVCP: Instruction that trapped: 0x...
  RVCP: END OF DEBUG INFORMATION

This applies to both the ref-model build step (where sail now produces a
clear trap message before exiting non-zero) and to the selfcheck ELF
running on the DUT.

Fixes riscv#1359.
@Jjateen Jjateen force-pushed the fix/trap-debug-1359 branch from dedf93b to 00298c0 Compare May 6, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading debug information when an unpriv test traps

1 participant