Skip to content

Commit deb2792

Browse files
petri: add with_nic helper to config (#796)
Currently, mana tests write a good amount of boilerplate code to add devices. This change adds a `with_nic` helper to streamline writing mana tests.
1 parent fe54baf commit deb2792

File tree

6 files changed

+56
-55
lines changed

6 files changed

+56
-55
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -5148,6 +5148,7 @@ dependencies = [
51485148
"fscommon",
51495149
"futures",
51505150
"futures-concurrency",
5151+
"gdma_resources",
51515152
"get_resources",
51525153
"gptman",
51535154
"guid",
@@ -5166,6 +5167,7 @@ dependencies = [
51665167
"mesh",
51675168
"mesh_process",
51685169
"mesh_worker",
5170+
"net_backend_resources",
51695171
"nvme_resources",
51705172
"pal",
51715173
"pal_async",
@@ -8494,13 +8496,11 @@ dependencies = [
84948496
"anyhow",
84958497
"build_rs_guest_arch",
84968498
"disk_backend_resources",
8497-
"gdma_resources",
84988499
"guid",
84998500
"hvlite_defs",
85008501
"hvlite_ttrpc_vmservice",
85018502
"mesh",
85028503
"mesh_rpc",
8503-
"net_backend_resources",
85048504
"nvme_resources",
85058505
"pal_async",
85068506
"petri",

petri/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ hvlite_helpers.workspace = true
2020
hvlite_pcat_locator.workspace = true
2121
hyperv_ic_resources.workspace = true
2222
hyperv_secure_boot_templates.workspace = true
23+
gdma_resources.workspace = true
2324
vmbus_serial_resources.workspace = true
2425
underhill_confidentiality.workspace = true
2526
vtl2_settings_proto.workspace = true
2627
disk_backend_resources.workspace = true
2728
framebuffer.workspace = true
2829
get_resources.workspace = true
2930
ide_resources.workspace = true
31+
net_backend_resources.workspace = true
3032
nvme_resources.workspace = true
3133
scsidisk_resources.workspace = true
3234
serial_core.workspace = true

petri/src/vm/openvmm/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub(crate) const SCSI_INSTANCE: Guid =
5151
pub(crate) const BOOT_NVME_INSTANCE: Guid =
5252
Guid::from_static_str("92bc8346-718b-449a-8751-edbf3dcd27e4");
5353

54+
/// The instance guid for the MANA nic automatically added when specifying `PetriVmConfigOpenVmm::with_nic`
55+
const MANA_INSTANCE: Guid = Guid::from_static_str("f9641cf4-d915-4743-a7d8-efa75db7b85a");
56+
5457
/// The namespace ID for the NVMe controller automatically added for boot media.
5558
pub(crate) const BOOT_NVME_NSID: u32 = 37;
5659

petri/src/vm/openvmm/modify.rs

+36
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
//! Helpers to modify a [`PetriVmConfigOpenVmm`] from its defaults.
55
66
use super::PetriVmConfigOpenVmm;
7+
use super::MANA_INSTANCE;
78
use chipset_resources::battery::BatteryDeviceHandleX64;
89
use chipset_resources::battery::HostBatteryUpdate;
910
use fs_err::File;
11+
use gdma_resources::GdmaDeviceHandle;
12+
use gdma_resources::VportDefinition;
1013
use hvlite_defs::config::Config;
14+
use hvlite_defs::config::DeviceVtl;
1115
use hvlite_defs::config::LoadMode;
16+
use hvlite_defs::config::VpciDeviceConfig;
1217
use hvlite_defs::config::Vtl2BaseAddressType;
1318
use petri_artifacts_common::tags::IsOpenhclIgvm;
1419
use petri_artifacts_core::ArtifactHandle;
@@ -131,6 +136,37 @@ impl PetriVmConfigOpenVmm {
131136
self
132137
}
133138

139+
/// Enable an emulated mana device for the VM.
140+
pub fn with_nic(mut self) -> Self {
141+
self.config.vpci_devices.push(VpciDeviceConfig {
142+
vtl: DeviceVtl::Vtl2,
143+
instance_id: MANA_INSTANCE,
144+
resource: GdmaDeviceHandle {
145+
vports: vec![VportDefinition {
146+
mac_address: [0x00, 0x15, 0x5D, 0x12, 0x12, 0x12].into(),
147+
endpoint: net_backend_resources::consomme::ConsommeHandle { cidr: None }
148+
.into_resource(),
149+
}],
150+
}
151+
.into_resource(),
152+
});
153+
154+
self.vtl2_settings
155+
.as_mut()
156+
.unwrap()
157+
.dynamic
158+
.as_mut()
159+
.unwrap()
160+
.nic_devices
161+
.push(vtl2_settings_proto::NicDeviceLegacy {
162+
instance_id: MANA_INSTANCE.to_string(),
163+
subordinate_instance_id: None,
164+
max_sub_channels: None,
165+
});
166+
167+
self
168+
}
169+
134170
/// Add custom command line arguments to OpenHCL.
135171
pub fn with_openhcl_command_line(mut self, additional_cmdline: &str) -> Self {
136172
if !self.firmware.is_openhcl() {

vmm_tests/vmm_tests/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ tracing.workspace = true
3838

3939
hvlite_ttrpc_vmservice.workspace = true
4040

41-
gdma_resources.workspace = true
42-
net_backend_resources.workspace = true
43-
4441
mesh_rpc.workspace = true
4542

4643
[build-dependencies]

vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_linux_direct.rs

+13-50
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
use anyhow::Context;
77
use disk_backend_resources::layer::RamDiskLayerHandle;
88
use disk_backend_resources::LayeredDiskHandle;
9-
use gdma_resources::GdmaDeviceHandle;
10-
use gdma_resources::VportDefinition;
119
use guid::Guid;
1210
use hvlite_defs::config::DeviceVtl;
1311
use hvlite_defs::config::VpciDeviceConfig;
@@ -16,7 +14,6 @@ use mesh::rpc::RpcSend;
1614
use nvme_resources::NamespaceDefinition;
1715
use nvme_resources::NvmeControllerHandle;
1816
use petri::openvmm::PetriVmConfigOpenVmm;
19-
use petri::openvmm::PetriVmOpenVmm;
2017
use petri::pipette::cmd;
2118
use petri::pipette::PipetteClient;
2219
use petri::OpenHclServicingFlags;
@@ -48,52 +45,11 @@ async fn validate_mana_nic(agent: &PipetteClient) -> Result<(), anyhow::Error> {
4845
Ok(())
4946
}
5047

51-
/// Boot an OpenHCL Linux direct VM with a MANA nic assigned to VTL2 (backed by
52-
/// the MANA emulator), and vmbus relay. This should expose a nic to VTL0 via
53-
/// vmbus.
54-
async fn boot_openhcl_linux_mana_nic(
55-
config: PetriVmConfigOpenVmm,
56-
) -> Result<(PetriVmOpenVmm, PipetteClient), anyhow::Error> {
57-
const MANA_INSTANCE: Guid = Guid::from_static_str("27b553e8-8b39-411b-a55f-839971a7884f");
58-
59-
let (vm, agent) = config
60-
.with_vmbus_redirect()
61-
.with_custom_config(|c| {
62-
c.vpci_devices.push(VpciDeviceConfig {
63-
vtl: DeviceVtl::Vtl2,
64-
instance_id: MANA_INSTANCE,
65-
resource: GdmaDeviceHandle {
66-
vports: vec![VportDefinition {
67-
mac_address: [0x00, 0x15, 0x5D, 0x12, 0x12, 0x12].into(),
68-
endpoint: net_backend_resources::consomme::ConsommeHandle { cidr: None }
69-
.into_resource(),
70-
}],
71-
}
72-
.into_resource(),
73-
});
74-
})
75-
.with_custom_vtl2_settings(|v| {
76-
v.dynamic
77-
.as_mut()
78-
.unwrap()
79-
.nic_devices
80-
.push(vtl2_settings_proto::NicDeviceLegacy {
81-
instance_id: MANA_INSTANCE.to_string(),
82-
subordinate_instance_id: None,
83-
max_sub_channels: None,
84-
})
85-
})
86-
.run()
87-
.await?;
88-
89-
Ok((vm, agent))
90-
}
91-
9248
/// Test an OpenHCL Linux direct VM with a MANA nic assigned to VTL2 (backed by
9349
/// the MANA emulator), and vmbus relay.
9450
#[openvmm_test(openhcl_linux_direct_x64)]
9551
async fn mana_nic(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Error> {
96-
let (vm, agent) = boot_openhcl_linux_mana_nic(config).await?;
52+
let (vm, agent) = config.with_vmbus_redirect().with_nic().run().await?;
9753

9854
validate_mana_nic(&agent).await?;
9955

@@ -108,10 +64,12 @@ async fn mana_nic(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Error> {
10864
/// the shared pool dma path.
10965
#[openvmm_test(openhcl_linux_direct_x64)]
11066
async fn mana_nic_shared_pool(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Error> {
111-
let (vm, agent) = boot_openhcl_linux_mana_nic(
112-
config.with_openhcl_command_line("OPENHCL_ENABLE_SHARED_VISIBILITY_POOL=1"),
113-
)
114-
.await?;
67+
let (vm, agent) = config
68+
.with_vmbus_redirect()
69+
.with_nic()
70+
.with_openhcl_command_line("OPENHCL_ENABLE_SHARED_VISIBILITY_POOL=1")
71+
.run()
72+
.await?;
11573

11674
validate_mana_nic(&agent).await?;
11775

@@ -126,7 +84,12 @@ async fn mana_nic_shared_pool(config: PetriVmConfigOpenVmm) -> Result<(), anyhow
12684
/// nic is still functional.
12785
#[openvmm_test(openhcl_linux_direct_x64)]
12886
async fn mana_nic_servicing(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Error> {
129-
let (mut vm, agent) = boot_openhcl_linux_mana_nic(config).await?;
87+
let (mut vm, agent) = config
88+
.with_vmbus_redirect()
89+
.with_nic()
90+
.with_openhcl_command_line("OPENHCL_ENABLE_SHARED_VISIBILITY_POOL=1")
91+
.run()
92+
.await?;
13093

13194
validate_mana_nic(&agent).await?;
13295

0 commit comments

Comments
 (0)