Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions vmm_tests/vmm_test_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ fn arch_to_tokens(arch: MachineArch) -> TokenStream {
}

impl Config {
fn name_prefix(&self, specific_vmm: Option<Vmm>) -> String {
fn name_prefix(&self, resolved_vmm: Vmm) -> String {
let arch_prefix = arch_to_str(self.arch);

let vmm_prefix = match (specific_vmm, self.vmm) {
(_, Some(Vmm::OpenVmm)) | (Some(Vmm::OpenVmm), None) => "openvmm",
(_, Some(Vmm::HyperV)) | (Some(Vmm::HyperV), None) => "hyperv",
_ => "",
let vmm_prefix = match resolved_vmm {
Vmm::OpenVmm => "openvmm",
Vmm::HyperV => "hyperv",
};

let firmware_prefix = match &self.firmware {
Expand Down Expand Up @@ -675,10 +674,22 @@ fn make_vmm_test(
let mut tests = TokenStream::new();
// FUTURE: compute all this in code instead of in the macro.
for config in args.configs {
let name = format!("{}_{original_name}", config.name_prefix(specific_vmm));
// Resolve the VMM backend early by combining specific_vmm and config.vmm
let resolved_vmm = match (specific_vmm, config.vmm) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just spitballing here, feel free to say no if you like the match better

if specific_vmm == config.vmm || specific_vmm.is_some() != config.vmm.is_some() {
    specific_vmm.or(config.vmm).ok_or(Error::new(config.span, "vmm must be specified"))?
}
else {
    return Err(Error::new(config.span, "vmm mismatch"))
}

(Some(Vmm::HyperV), Some(Vmm::HyperV))
| (Some(Vmm::HyperV), None)
| (None, Some(Vmm::HyperV)) => Vmm::HyperV,
(Some(Vmm::OpenVmm), Some(Vmm::OpenVmm))
| (Some(Vmm::OpenVmm), None)
| (None, Some(Vmm::OpenVmm)) => Vmm::OpenVmm,
(None, None) => return Err(Error::new(config.span, "vmm must be specified")),
_ => return Err(Error::new(config.span, "vmm mismatch")),
};

let name = format!("{}_{original_name}", config.name_prefix(resolved_vmm));

// Build requirements based on the configuration
let requirements = build_requirements(&config, &name);
// Build requirements based on the configuration and resolved VMM
let requirements = build_requirements(&config.firmware, &name, resolved_vmm);
let requirements = if let Some(req) = requirements {
quote! { Some(#req) }
} else {
Expand All @@ -694,24 +705,17 @@ fn make_vmm_test(
};
let arch = arch_to_tokens(config.arch);

let (cfg_conditions, artifacts, petri_vm_config) = match (specific_vmm, config.vmm) {
(Some(Vmm::HyperV), Some(Vmm::HyperV))
| (Some(Vmm::HyperV), None)
| (None, Some(Vmm::HyperV)) => (
let (cfg_conditions, artifacts, petri_vm_config) = match resolved_vmm {
Vmm::HyperV => (
quote!(#[cfg(windows)]),
quote!(::petri::PetriVmArtifacts::<::petri::hyperv::HyperVPetriBackend>),
quote!(::petri::PetriVmBuilder::<::petri::hyperv::HyperVPetriBackend>),
),

(Some(Vmm::OpenVmm), Some(Vmm::OpenVmm))
| (Some(Vmm::OpenVmm), None)
| (None, Some(Vmm::OpenVmm)) => (
Vmm::OpenVmm => (
quote!(),
quote!(::petri::PetriVmArtifacts::<::petri::openvmm::OpenVmmPetriBackend>),
quote!(::petri::PetriVmBuilder::<::petri::openvmm::OpenVmmPetriBackend>),
),
(None, None) => return Err(Error::new(config.span, "vmm must be specified")),
_ => return Err(Error::new(config.span, "vmm mismatch")),
};

let petri_vm_config = quote!(#petri_vm_config::new(&params, artifacts, &driver)?);
Expand Down Expand Up @@ -746,8 +750,8 @@ fn make_vmm_test(
})
}

// Helper to build requirements TokenStream for a config and specific_vmm
fn build_requirements(config: &Config, name: &str) -> Option<TokenStream> {
// Helper to build requirements TokenStream for firmware and resolved VMM
fn build_requirements(firmware: &Firmware, name: &str, resolved_vmm: Vmm) -> Option<TokenStream> {
let mut requirement_expr: Option<TokenStream> = None;
let mut is_vbs = false;
// Add isolation requirement if specified
Expand All @@ -757,7 +761,7 @@ fn build_requirements(config: &Config, name: &str) -> Option<TokenStream> {
..
},
_,
) = &config.firmware
) = firmware
{
let isolation_requirement = match isolation {
IsolationType::Vbs => {
Expand Down Expand Up @@ -803,7 +807,7 @@ fn build_requirements(config: &Config, name: &str) -> Option<TokenStream> {
};
}

let is_hyperv = config.vmm.is_some() && config.vmm == Some(Vmm::HyperV);
let is_hyperv = resolved_vmm == Vmm::HyperV;

if is_hyperv && is_vbs {
let hyperv_vbs_requirement_expr = quote!(
Expand Down