Skip to content

Commit 5372135

Browse files
authored
Add vsock phd smoketest (#1086)
1 parent 368a222 commit 5372135

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

lib/propolis/src/vsock/poller.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ impl VsockGuestAddr {
805805
}
806806

807807
#[cfg(test)]
808-
mod tests {
808+
mod test {
809809
use std::io::{Read, Write};
810810
use std::net::TcpListener;
811811
use std::sync::atomic::{AtomicUsize, Ordering};

phd-tests/framework/src/test_vm/config.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use propolis_client::{
1111
Board, BootOrderEntry, BootSettings, Chipset, Component, Cpuid,
1212
CpuidEntry, CpuidVendor, GuestHypervisorInterface, InstanceMetadata,
1313
InstanceSpec, MigrationFailureInjector, NvmeDisk, PciPath, SerialPort,
14-
SerialPortNumber, SpecKey, VirtioDisk,
14+
SerialPortNumber, SpecKey, VirtioDisk, VirtioSocket,
1515
},
1616
support::nvme_serial_from_str,
1717
};
@@ -56,6 +56,7 @@ pub struct VmConfig<'dr> {
5656
disks: Vec<DiskRequest<'dr>>,
5757
migration_failure: Option<MigrationFailureInjector>,
5858
guest_hv_interface: Option<GuestHypervisorInterface>,
59+
vsock: Option<VirtioSocket>,
5960
}
6061

6162
impl<'dr> VmConfig<'dr> {
@@ -76,6 +77,7 @@ impl<'dr> VmConfig<'dr> {
7677
disks: Vec::new(),
7778
migration_failure: None,
7879
guest_hv_interface: None,
80+
vsock: None,
7981
};
8082

8183
config.boot_disk(
@@ -121,6 +123,12 @@ impl<'dr> VmConfig<'dr> {
121123
self
122124
}
123125

126+
pub fn vsock(&mut self, guest_cid: u64, pci_device_num: u8) -> &mut Self {
127+
let pci_path = PciPath::new(0, pci_device_num, 0).unwrap();
128+
self.vsock = Some(VirtioSocket { guest_cid, pci_path });
129+
self
130+
}
131+
124132
pub fn fail_migration_exports(&mut self, exports: u32) -> &mut Self {
125133
let injector =
126134
self.migration_failure.get_or_insert(MigrationFailureInjector {
@@ -218,6 +226,7 @@ impl<'dr> VmConfig<'dr> {
218226
disks,
219227
migration_failure,
220228
guest_hv_interface,
229+
vsock,
221230
} = self;
222231
let framework = &ctx.framework;
223232
let bootrom_path = framework
@@ -369,6 +378,13 @@ impl<'dr> VmConfig<'dr> {
369378
assert!(_old.is_none());
370379
}
371380

381+
if let Some(vsock) = vsock {
382+
let _old = spec
383+
.components
384+
.insert("vsock".into(), Component::VirtioSocket(*vsock));
385+
assert!(_old.is_none());
386+
}
387+
372388
if let Some(mig) = migration_failure.as_ref() {
373389
let _old = spec.components.insert(
374390
"migration-failure".into(),

phd-tests/tests/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ mod migrate;
1515
mod server_state_machine;
1616
mod smoke;
1717
mod stats;
18+
mod vsock;

phd-tests/tests/src/vsock.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
use phd_testcase::*;
6+
7+
const GUEST_CID: u64 = 16;
8+
const PCI_DEV_NUM: u8 = 26;
9+
10+
#[phd_testcase]
11+
async fn vsock_smoke_test(ctx: &TestCtx) {
12+
let mut cfg = ctx.vm_config_builder("vsock_smoke_test");
13+
cfg.vsock(GUEST_CID, PCI_DEV_NUM);
14+
15+
let mut vm = ctx.spawn_vm(&cfg, None).await?;
16+
vm.launch().await?;
17+
vm.wait_to_boot().await?;
18+
19+
// This doesn't tell the whole story since linux will sometimes make this
20+
// device available even if the hypervisor does not present the virtio
21+
// device itself. Either way, it would be an error if it's not present.
22+
vm.run_shell_command("test -e /dev/vsock").await?;
23+
}
24+
25+
#[phd_testcase]
26+
async fn vsock_get_cid(ctx: &TestCtx) {
27+
const GET_CID: &str = "/usr/local/bin/getcid";
28+
29+
let mut cfg = ctx.vm_config_builder("vsock_get_cid");
30+
cfg.vsock(GUEST_CID, PCI_DEV_NUM);
31+
32+
let mut vm = ctx.spawn_vm(&cfg, None).await?;
33+
vm.launch().await?;
34+
vm.wait_to_boot().await?;
35+
36+
// If we are not using a modified alpine image with our additional tooling
37+
// we should skip this test entirely.
38+
if vm.run_shell_command(&format!("test -e {GET_CID}")).await.is_err() {
39+
phd_skip!("guest doesn't have getcid installed");
40+
}
41+
42+
let cid = vm.run_shell_command(GET_CID).await?.parse::<u64>()?;
43+
assert_eq!(cid, GUEST_CID, "guest cid matches what was configured");
44+
}

0 commit comments

Comments
 (0)