Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangliu committed Jun 5, 2021
1 parent aa59b37 commit c0b6d85
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,8 @@ mod tests {

use super::*;
use ioctls::system::Kvm;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use vmm_sys_util::fam::FamStruct;
#[cfg(any(
target_arch = "x86",
target_arch = "x86_64",
Expand Down Expand Up @@ -1512,16 +1514,18 @@ mod tests {
let kvm = Kvm::new().unwrap();
if kvm.check_extension(Cap::ExtCpuid) {
let vm = kvm.create_vm().unwrap();
let mut cpuid = kvm.get_supported_cpuid(KVM_MAX_CPUID_ENTRIES).unwrap();
//let mut cpuid = kvm.get_supported_cpuid(KVM_MAX_CPUID_ENTRIES).unwrap();
let mut cpuid = kvm.get_supported_cpuid(48).unwrap();
let ncpuids = cpuid.as_slice().len();
assert_eq!(cpuid.as_fam_struct_ref().len(), ncpuids);
assert!(ncpuids <= KVM_MAX_CPUID_ENTRIES);
let vcpu = vm.create_vcpu(0).unwrap();

// Setting Manufacturer ID
{
let entries = cpuid.as_mut_slice();
for entry in entries.iter_mut() {
if entry.function == 0 {
if entry.function == 0 && entry.index == 0 && entry.flags == 0 {
// " KVMKVMKVM "
entry.ebx = 0x4b4d564b;
entry.ecx = 0x564b4d56;
Expand All @@ -1531,8 +1535,12 @@ mod tests {
}
vcpu.set_cpuid2(&cpuid).unwrap();
let cpuid_0 = vcpu.get_cpuid2(ncpuids).unwrap();
assert_eq!(
cpuid.as_fam_struct_ref().len(),
cpuid_0.as_fam_struct_ref().len()
);
for entry in cpuid_0.as_slice() {
if entry.function == 0 {
if entry.function == 0 && entry.index == 0 && entry.flags == 0 {
assert_eq!(entry.ebx, 0x4b4d564b);
assert_eq!(entry.ecx, 0x564b4d56);
assert_eq!(entry.edx, 0x4d);
Expand Down Expand Up @@ -1561,6 +1569,41 @@ mod tests {
}
}

#[cfg(target_arch = "x86_64")]
#[test]
fn test_set_cpuid_one_entry() {
let kvm = Kvm::new().unwrap();
if kvm.check_extension(Cap::ExtCpuid) {
let vm = kvm.create_vm().unwrap();
let mut cpuid = CpuId::new(1).unwrap();
let ncpuids = cpuid.as_slice().len();
assert_eq!(ncpuids, 1);
assert_eq!(cpuid.as_fam_struct_ref().len(), ncpuids);
let vcpu = vm.create_vcpu(0).unwrap();

// Setting Manufacturer ID
{
let entries = cpuid.as_mut_slice();
// " KVMKVMKVM "
entries[0].ebx = 0x4b4d564b;
entries[0].ecx = 0x564b4d56;
entries[0].edx = 0x4d;
}
vcpu.set_cpuid2(&cpuid).unwrap();
let cpuid_0 = vcpu.get_cpuid2(ncpuids).unwrap();
assert_eq!(
cpuid.as_fam_struct_ref().len(),
cpuid_0.as_fam_struct_ref().len()
);
assert_eq!(cpuid, cpuid_0);
for entry in cpuid_0.as_slice() {
assert_eq!(entry.ebx, 0x4b4d564b);
assert_eq!(entry.ecx, 0x564b4d56);
assert_eq!(entry.edx, 0x4d);
}
}
}

#[cfg(target_arch = "x86_64")]
#[allow(non_snake_case)]
#[test]
Expand Down

0 comments on commit c0b6d85

Please sign in to comment.