Skip to content

Commit afb2f57

Browse files
committed
test(vmm): Add unit test for vendor ID normalization
Add a unit test to verify that update_vendor_id() passes through the vendor ID from the host correctly. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent de67f48 commit afb2f57

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/vmm/src/cpu_config/x86_64/cpuid/normalize.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,43 @@ mod tests {
528528
);
529529
}
530530

531+
#[test]
532+
fn test_update_vendor_id() {
533+
// Check `update_vendor_id()` passes through the vendor ID from the host correctly.
534+
535+
// Pseudo CPUID with invalid vendor ID.
536+
let mut guest_cpuid = Cpuid::Intel(IntelCpuid(BTreeMap::from([(
537+
CpuidKey {
538+
leaf: 0x0,
539+
subleaf: 0x0,
540+
},
541+
CpuidEntry {
542+
flags: KvmCpuidFlags::EMPTY,
543+
result: CpuidRegisters {
544+
eax: 0,
545+
ebx: 0x0123_4567,
546+
ecx: 0x89ab_cdef,
547+
edx: 0x55aa_55aa,
548+
},
549+
},
550+
)])));
551+
552+
// Pass through vendor ID from host.
553+
guest_cpuid.update_vendor_id().unwrap();
554+
555+
// Check if the guest vendor ID matches the host one.
556+
let guest_leaf_0 = guest_cpuid
557+
.get(&CpuidKey {
558+
leaf: 0x0,
559+
subleaf: 0x0,
560+
})
561+
.unwrap();
562+
let host_leaf_0 = cpuid(0x0);
563+
assert_eq!(guest_leaf_0.result.ebx, host_leaf_0.ebx);
564+
assert_eq!(guest_leaf_0.result.ecx, host_leaf_0.ecx);
565+
assert_eq!(guest_leaf_0.result.edx, host_leaf_0.edx);
566+
}
567+
531568
#[test]
532569
fn check_leaf_0xb_subleaf_0x1_added() {
533570
// Check leaf 0xb / subleaf 0x1 is added in `update_extended_topology_entry()` even when it

0 commit comments

Comments
 (0)