Skip to content

Commit e333aca

Browse files
authored
Add test for SnpVpContext (#82)
Adds test that the SnpVpContext/IGVM_VHS_VP_CONTEXT/IGVM_VHT_VP_CONTEXT type is serialized and deserialized correctly. Adds regression test for #80 (compiler bug, so no code changes needed to fix). Signed-off-by: Adam Dunlap <[email protected]>
1 parent 365065d commit e333aca

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

igvm/src/lib.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4648,7 +4648,48 @@ mod tests {
46484648
Some(IgvmPlatformType::VSM_ISOLATION),
46494649
)
46504650
}
4651-
// Test SNP vp context
4651+
4652+
#[test]
4653+
fn test_snp_vp_context() {
4654+
let raw_header = IGVM_VHS_VP_CONTEXT {
4655+
gpa: 0x1234000.into(),
4656+
compatibility_mask: 0x1,
4657+
file_offset: 1234,
4658+
vp_index: 0xabcd,
4659+
reserved: 0,
4660+
};
4661+
4662+
let mut raw_header_bytes: [u8; 24] = [0; 24];
4663+
raw_header_bytes[..raw_header.as_bytes().len()].copy_from_slice(raw_header.as_bytes());
4664+
4665+
let mut vmsa = SevVmsa::new_box_zeroed().unwrap();
4666+
// Set a couple of random values so it's not just all 0s.
4667+
vmsa.cr2 = 42;
4668+
vmsa.ldtr.attrib = 92;
4669+
4670+
let mut file_data: Vec<u8> = vmsa.as_bytes().to_vec();
4671+
file_data.resize(PAGE_SIZE_4K.try_into().unwrap(), 0);
4672+
4673+
let header = IgvmDirectiveHeader::SnpVpContext {
4674+
gpa: 0x1234000,
4675+
compatibility_mask: 0x1,
4676+
vp_index: 0xabcd,
4677+
vmsa,
4678+
};
4679+
4680+
test_variable_header(
4681+
IgvmRevision::V2 {
4682+
arch: Arch::X64,
4683+
page_size: PAGE_SIZE_4K as u32,
4684+
},
4685+
header,
4686+
1234,
4687+
IgvmVariableHeaderType::IGVM_VHT_VP_CONTEXT,
4688+
raw_header_bytes,
4689+
Some(file_data),
4690+
Some(IgvmPlatformType::SEV_SNP),
4691+
)
4692+
}
46524693

46534694
// Test serialize and deserialize
46544695
}

0 commit comments

Comments
 (0)