crosvm/devices/tests/irqchip/kvm/mod.rs
Dennis Kempin 2f5eb3ac64 Extract devices integration tests
This change moves most ircchip tests into an integration test.
These tests rely on kvm, and if they do not - reuse much of the
test code from each other, so they need to move together.

Note: This removes the apic_timer test. The test has been disabled
for a while due to it's use of sleep in unit tests.

We cannot support it as an integration test either, since it combines
the sleep with a FakeClock. userspace.rs swaps the real clock for
FakeClock when compiled with cfg(test), but integration tests do not
compile with cfg(test), so we cannot use the FakeClock.

The biggest side-effect is faster execution as we can run all other 300+
tests in parallel and via user-space emulation, significantly cutting
down on the test times. It also allows those tests to run in a
podman container.

BUG=b:244620308
TEST=CQ

Change-Id: I1728a736d27e924daf228752711435885dacfa6a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3977111
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-10-26 17:53:08 +00:00

57 lines
1.9 KiB
Rust

// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![cfg(unix)]
mod x86_64;
use hypervisor::kvm::Kvm;
use hypervisor::kvm::KvmVm;
use hypervisor::MPState;
use hypervisor::Vm;
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
use hypervisor::VmAArch64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use hypervisor::VmX86_64;
use vm_memory::GuestMemory;
use devices::irqchip::IrqChip;
use devices::irqchip::KvmKernelIrqChip;
#[test]
fn create_kvm_kernel_irqchip() {
let kvm = Kvm::new().expect("failed to instantiate Kvm");
let mem = GuestMemory::new(&[]).unwrap();
let vm = KvmVm::new(&kvm, mem, Default::default()).expect("failed to instantiate vm");
let mut chip = KvmKernelIrqChip::new(vm.try_clone().expect("failed to clone vm"), 1)
.expect("failed to instantiate KvmKernelIrqChip");
let vcpu = vm.create_vcpu(0).expect("failed to instantiate vcpu");
chip.add_vcpu(0, vcpu.as_vcpu())
.expect("failed to add vcpu");
}
#[test]
fn mp_state() {
let kvm = Kvm::new().expect("failed to instantiate Kvm");
let mem = GuestMemory::new(&[]).unwrap();
let vm = KvmVm::new(&kvm, mem, Default::default()).expect("failed to instantiate vm");
let mut chip = KvmKernelIrqChip::new(vm.try_clone().expect("failed to clone vm"), 1)
.expect("failed to instantiate KvmKernelIrqChip");
let vcpu = vm.create_vcpu(0).expect("failed to instantiate vcpu");
chip.add_vcpu(0, vcpu.as_vcpu())
.expect("failed to add vcpu");
let state = chip.get_mp_state(0).expect("failed to get mp state");
assert_eq!(state, MPState::Runnable);
chip.set_mp_state(0, &MPState::Stopped)
.expect("failed to set mp state");
let state = chip.get_mp_state(0).expect("failed to get mp state");
assert_eq!(state, MPState::Stopped);
}