Skip to content

Commit 241d8e3

Browse files
committed
test: add Rust integration tests for PCI-enabled uVMs
We have a couple of Rust integration tests that check building and booting of microVMs works correctly. Add variants for PCI-enabled microVMs. Signed-off-by: Babis Chalios <[email protected]>
1 parent 5331d63 commit 241d8e3

File tree

2 files changed

+59
-25
lines changed

2 files changed

+59
-25
lines changed

src/vmm/src/test_utils/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn create_vmm(
6969
_kernel_image: Option<&str>,
7070
is_diff: bool,
7171
boot_microvm: bool,
72+
pci_enabled: bool,
7273
) -> (Arc<Mutex<Vmm>>, EventManager) {
7374
let mut event_manager = EventManager::new().unwrap();
7475
let empty_seccomp_filters = get_empty_filters();
@@ -82,14 +83,16 @@ pub fn create_vmm(
8283
None => boot_source_cfg.into(),
8384
};
8485
let mock_vm_res = MockVmResources::new().with_boot_source(boot_source_cfg);
85-
let resources: VmResources = if is_diff {
86+
let mut resources: VmResources = if is_diff {
8687
mock_vm_res
8788
.with_vm_config(MockVmConfig::new().with_dirty_page_tracking().into())
8889
.into()
8990
} else {
9091
mock_vm_res.into()
9192
};
9293

94+
resources.pci_enabled = pci_enabled;
95+
9396
let vmm = build_microvm_for_boot(
9497
&InstanceInfo::default(),
9598
&resources,
@@ -106,16 +109,24 @@ pub fn create_vmm(
106109
}
107110

108111
pub fn default_vmm(kernel_image: Option<&str>) -> (Arc<Mutex<Vmm>>, EventManager) {
109-
create_vmm(kernel_image, false, true)
112+
create_vmm(kernel_image, false, true, false)
110113
}
111114

112115
pub fn default_vmm_no_boot(kernel_image: Option<&str>) -> (Arc<Mutex<Vmm>>, EventManager) {
113-
create_vmm(kernel_image, false, false)
116+
create_vmm(kernel_image, false, false, false)
117+
}
118+
119+
pub fn default_vmm_pci_no_boot(kernel_image: Option<&str>) -> (Arc<Mutex<Vmm>>, EventManager) {
120+
create_vmm(kernel_image, false, false, true)
114121
}
115122

116123
#[cfg(target_arch = "x86_64")]
117124
pub fn dirty_tracking_vmm(kernel_image: Option<&str>) -> (Arc<Mutex<Vmm>>, EventManager) {
118-
create_vmm(kernel_image, true, true)
125+
create_vmm(kernel_image, true, true, false)
126+
}
127+
128+
pub fn default_vmm_pci(kernel_image: Option<&str>) -> (Arc<Mutex<Vmm>>, EventManager) {
129+
create_vmm(kernel_image, false, true, false)
119130
}
120131

121132
#[allow(clippy::undocumented_unsafe_blocks)]

src/vmm/tests/integration_tests.rs

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::io::{Seek, SeekFrom};
5+
use std::sync::{Arc, Mutex};
56
use std::thread;
67
use std::time::Duration;
78

@@ -15,7 +16,9 @@ use vmm::rpc_interface::{
1516
use vmm::seccomp::get_empty_filters;
1617
use vmm::snapshot::Snapshot;
1718
use vmm::test_utils::mock_resources::{MockVmResources, NOISY_KERNEL_IMAGE};
18-
use vmm::test_utils::{create_vmm, default_vmm, default_vmm_no_boot};
19+
use vmm::test_utils::{
20+
create_vmm, default_vmm, default_vmm_no_boot, default_vmm_pci, default_vmm_pci_no_boot,
21+
};
1922
use vmm::vmm_config::balloon::BalloonDeviceConfig;
2023
use vmm::vmm_config::boot_source::BootSourceConfig;
2124
use vmm::vmm_config::drive::BlockDeviceConfig;
@@ -26,9 +29,23 @@ use vmm::vmm_config::snapshot::{
2629
CreateSnapshotParams, LoadSnapshotParams, MemBackendConfig, MemBackendType, SnapshotType,
2730
};
2831
use vmm::vmm_config::vsock::VsockDeviceConfig;
29-
use vmm::{DumpCpuConfigError, EventManager, FcExitCode};
32+
use vmm::{DumpCpuConfigError, EventManager, FcExitCode, Vmm};
3033
use vmm_sys_util::tempfile::TempFile;
3134

35+
fn check_booted_microvm(vmm: Arc<Mutex<Vmm>>, mut evmgr: EventManager) {
36+
// On x86_64, the vmm should exit once its workload completes and signals the exit event.
37+
// On aarch64, the test kernel doesn't exit, so the vmm is force-stopped.
38+
#[cfg(target_arch = "x86_64")]
39+
evmgr.run_with_timeout(500).unwrap();
40+
#[cfg(target_arch = "aarch64")]
41+
vmm.lock().unwrap().stop(FcExitCode::Ok);
42+
43+
assert_eq!(
44+
vmm.lock().unwrap().shutdown_exit_code(),
45+
Some(FcExitCode::Ok)
46+
);
47+
}
48+
3249
#[test]
3350
fn test_build_and_boot_microvm() {
3451
// Error case: no boot source configured.
@@ -47,33 +64,24 @@ fn test_build_and_boot_microvm() {
4764
}
4865

4966
// Success case.
50-
let (vmm, mut _evmgr) = default_vmm(None);
51-
52-
// On x86_64, the vmm should exit once its workload completes and signals the exit event.
53-
// On aarch64, the test kernel doesn't exit, so the vmm is force-stopped.
54-
#[cfg(target_arch = "x86_64")]
55-
_evmgr.run_with_timeout(500).unwrap();
56-
#[cfg(target_arch = "aarch64")]
57-
vmm.lock().unwrap().stop(FcExitCode::Ok);
67+
let (vmm, evmgr) = default_vmm(None);
68+
check_booted_microvm(vmm, evmgr);
5869

59-
assert_eq!(
60-
vmm.lock().unwrap().shutdown_exit_code(),
61-
Some(FcExitCode::Ok)
62-
);
70+
// microVM with PCI
71+
let (vmm, evmgr) = default_vmm_pci(None);
72+
check_booted_microvm(vmm, evmgr);
6373
}
6474

65-
#[test]
66-
fn test_build_microvm() {
75+
fn check_build_microvm(vmm: Arc<Mutex<Vmm>>, mut evmgr: EventManager) {
6776
// The built microVM should be in the `VmState::Paused` state here.
68-
let (vmm, mut _evtmgr) = default_vmm_no_boot(None);
6977
assert_eq!(vmm.lock().unwrap().instance_info().state, VmState::Paused);
7078

7179
// The microVM should be able to resume and exit successfully.
7280
// On x86_64, the vmm should exit once its workload completes and signals the exit event.
7381
// On aarch64, the test kernel doesn't exit, so the vmm is force-stopped.
7482
vmm.lock().unwrap().resume_vm().unwrap();
7583
#[cfg(target_arch = "x86_64")]
76-
_evtmgr.run_with_timeout(500).unwrap();
84+
evmgr.run_with_timeout(500).unwrap();
7785
#[cfg(target_arch = "aarch64")]
7886
vmm.lock().unwrap().stop(FcExitCode::Ok);
7987
assert_eq!(
@@ -83,10 +91,14 @@ fn test_build_microvm() {
8391
}
8492

8593
#[test]
86-
fn test_pause_resume_microvm() {
87-
// Tests that pausing and resuming a microVM work as expected.
88-
let (vmm, _) = default_vmm(None);
94+
fn test_build_microvm() {
95+
let (vmm, evtmgr) = default_vmm_no_boot(None);
96+
check_build_microvm(vmm, evtmgr);
97+
let (vmm, evtmgr) = default_vmm_pci_no_boot(None);
98+
check_build_microvm(vmm, evtmgr);
99+
}
89100

101+
fn pause_resume_microvm(vmm: Arc<Mutex<Vmm>>) {
90102
let mut api_controller = RuntimeApiController::new(VmResources::default(), vmm.clone());
91103

92104
// There's a race between this thread and the vcpu thread, but this thread
@@ -100,6 +112,17 @@ fn test_pause_resume_microvm() {
100112
vmm.lock().unwrap().stop(FcExitCode::Ok);
101113
}
102114

115+
#[test]
116+
fn test_pause_resume_microvm() {
117+
// Tests that pausing and resuming a microVM work as expected.
118+
let (vmm, _) = default_vmm(None);
119+
120+
pause_resume_microvm(vmm);
121+
122+
let (vmm, _) = default_vmm_pci(None);
123+
pause_resume_microvm(vmm);
124+
}
125+
103126
#[test]
104127
fn test_dirty_bitmap_error() {
105128
// Error case: dirty tracking disabled.

0 commit comments

Comments
 (0)