Skip to content

Commit 7b34e73

Browse files
andreeaflorescualxiord
authored andcommitted
make test_irq_chip x86 specific
The test was previously marked as x86_64 and aarch64 compatible. On aarch64 we were testing only the error case. On older kernel versions, creating an irqchip before creating the vCPU would return an error. This restrictions is not in place anymore on Linux Kernel 4.15. Since we cannot test this error path anymore on aarch64, the test is now labeled as x86 specific. Also updated the test to set the irq_base of the PIC and check that this value is appropriately updated. Signed-off-by: Andreea Florescu <[email protected]>
1 parent f372a9d commit 7b34e73

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

src/ioctls/vm.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ impl AsRawFd for VmFd {
11091109
#[cfg(test)]
11101110
mod tests {
11111111
use super::*;
1112-
use {Cap, Kvm};
1112+
use Kvm;
11131113

11141114
use libc::EFD_NONBLOCK;
11151115

@@ -1136,34 +1136,31 @@ mod tests {
11361136
}
11371137

11381138
#[test]
1139-
#[cfg(any(
1140-
target_arch = "x86",
1141-
target_arch = "x86_64",
1142-
target_arch = "arm",
1143-
target_arch = "aarch64"
1144-
))]
1139+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
11451140
fn test_irq_chip() {
1141+
use Cap;
1142+
11461143
let kvm = Kvm::new().unwrap();
11471144
assert!(kvm.check_extension(Cap::Irqchip));
11481145
let vm = kvm.create_vm().unwrap();
1149-
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
1150-
assert!(vm.create_irq_chip().is_ok());
1151-
} else if cfg!(any(target_arch = "arm", target_arch = "aarch64")) {
1152-
// On arm, we expect this to fail as the irq chip needs to be created after the vcpus.
1153-
assert!(vm.create_irq_chip().is_err());
1154-
}
1146+
assert!(vm.create_irq_chip().is_ok());
11551147

1156-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
1157-
{
1158-
let mut irqchip = kvm_irqchip::default();
1159-
irqchip.chip_id = KVM_IRQCHIP_PIC_MASTER;
1160-
vm.get_irqchip(&mut irqchip).unwrap();
1161-
vm.set_irqchip(&irqchip).unwrap();
1162-
let mut other_irqchip = kvm_irqchip::default();
1163-
other_irqchip.chip_id = KVM_IRQCHIP_PIC_MASTER;
1164-
vm.get_irqchip(&mut other_irqchip).unwrap();
1165-
unsafe { assert_eq!(irqchip.chip.dummy[..], other_irqchip.chip.dummy[..]) };
1148+
let mut irqchip = kvm_irqchip::default();
1149+
irqchip.chip_id = KVM_IRQCHIP_PIC_MASTER;
1150+
// Set the irq_base to a non-default value to check that set & get work.
1151+
unsafe {
1152+
irqchip.chip.pic.irq_base = 10;
11661153
}
1154+
assert!(vm.set_irqchip(&irqchip).is_ok());
1155+
1156+
// We initialize a dummy irq chip (`other_irqchip`) in which the
1157+
// function `get_irqchip` returns its result.
1158+
let mut other_irqchip = kvm_irqchip::default();
1159+
other_irqchip.chip_id = KVM_IRQCHIP_PIC_MASTER;
1160+
assert!(vm.get_irqchip(&mut other_irqchip).is_ok());
1161+
1162+
// Safe because we know that the irqchip type is PIC.
1163+
unsafe { assert_eq!(irqchip.chip.pic, other_irqchip.chip.pic) };
11671164
}
11681165

11691166
#[test]

0 commit comments

Comments
 (0)