MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / test_error_to_trap_cause

Function test_error_to_trap_cause

crates/virtual-machine/tests/vm_traps.rs:69–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67
68 #[test]
69 fn test_error_to_trap_cause() {
70 // Test instruction access fault
71 let err = VmError::InstructionAccessFault(0x1234);
72 let (cause, tval) = traps::error_to_trap_cause(&err).expect("error should map to a trap");
73 assert_eq!(cause, traps::CAUSE_INSN_ACCESS_FAULT);
74 assert_eq!(tval, 0x1234);
75
76 // Test illegal instruction
77 let err = VmError::IllegalInstruction(0xDEAD);
78 let (cause, tval) = traps::error_to_trap_cause(&err).expect("error should map to a trap");
79 assert_eq!(cause, traps::CAUSE_ILLEGAL_INSN);
80 assert_eq!(tval, 0xDEAD);
81
82 // Test load access fault
83 let err = VmError::LoadAccessFault(0x5678);
84 let (cause, tval) = traps::error_to_trap_cause(&err).expect("error should map to a trap");
85 assert_eq!(cause, traps::CAUSE_LOAD_ACCESS_FAULT);
86 assert_eq!(tval, 0x5678);
87
88 // Test that ecall cannot be trapped
89 let err = VmError::Ecall;
90 assert!(traps::error_to_trap_cause(&err).is_none());
91 }
92}

Callers

nothing calls this directly

Calls 1

error_to_trap_causeFunction · 0.85

Tested by

no test coverage detected