Skip to content

Commit

Permalink
kernel/cpu/vc: Enable port IO string test_in_svsm
Browse files Browse the repository at this point in the history
With the #VC handler now supporting ins/outs instructions, the test case
test_port_io_string_16_get_last() can be enabled. The test case is also
extended to test rep insw by reading data from the test port and writing
to the memory.

Signed-off-by: Chuanxiao Dong <[email protected]>
  • Loading branch information
cxdong committed Jul 24, 2024
1 parent c332795 commit c0b0a76
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions kernel/src/cpu/vc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,13 @@ mod tests {

fn rep_outsw(port: u16, data: &[u16]) {
unsafe {
asm!("rep outsw", in("dx") port, in("rsi") data.as_ptr(), in("rcx") data.len(), options(att_syntax))
asm!("rep outsw", in("dx") port, in("rsi") data.as_ptr(), inout("rcx") data.len() => _, options(att_syntax))
}
}

fn rep_insw(port: u16, data: &mut [u16]) {
unsafe {
asm!("rep insw", in("dx") port, in("rdi") data.as_ptr(), inout("rcx") data.len() => _, options(att_syntax))
}
}

Expand Down Expand Up @@ -481,15 +487,20 @@ mod tests {
}

#[test]
// #[cfg_attr(not(test_in_svsm), ignore = "Can only be run inside guest")]
#[ignore = "Currently unhandled by #VC handler"]
#[cfg_attr(not(test_in_svsm), ignore = "Can only be run inside guest")]
fn test_port_io_string_16_get_last() {
const TEST_DATA: &[u16] = &[0x1234, 0x5678, 0x9abc, 0xdef0];
verify_ghcb_gets_altered(|| rep_outsw(TESTDEV_ECHO_LAST_PORT, TEST_DATA));
assert_eq!(
TEST_DATA.last().unwrap(),
&verify_ghcb_gets_altered(|| inw(TESTDEV_ECHO_LAST_PORT))
);

let mut test_data: [u16; 4] = [0; 4];
verify_ghcb_gets_altered(|| rep_insw(TESTDEV_ECHO_LAST_PORT, &mut test_data));
for d in test_data.iter() {
assert_eq!(d, TEST_DATA.last().unwrap());
}
}

#[test]
Expand Down

0 comments on commit c0b0a76

Please sign in to comment.