Skip to main content

flowey_hvlite/pipelines/
vmm_tests_run_target.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Run VMM tests on a target system with artifacts built by `VmmTestsRun`.
5
6use crate::pipelines::vmm_tests_run::VmmTestTargetCli;
7use crate::pipelines::vmm_tests_run::resolve_target;
8use anyhow::Context;
9use flowey::node::prelude::ReadVar;
10use flowey::pipeline::prelude::*;
11use flowey_lib_hvlite::init_vmm_tests_env::PetriParams;
12use flowey_lib_hvlite::install_vmm_tests_external_deps::VmmTestsExternalDeps;
13use flowey_lib_hvlite::install_vmm_tests_external_deps::VmmTestsExternalDepsLinux;
14use flowey_lib_hvlite::install_vmm_tests_external_deps::VmmTestsExternalDepsWindows;
15use petri_artifacts_vmm_test::ErasedVmmTestImage;
16use petri_artifacts_vmm_test::parse_vmm_test_image;
17use std::num::NonZeroU64;
18use std::path::PathBuf;
19
20/// Run VMM tests on a target system with artifacts built by `VmmTestsRun`.
21#[derive(clap::Args)]
22pub struct VmmTestsRunTargetCli {
23    /// Specify what target to build the VMM tests for
24    ///
25    /// If not specified, defaults to the current host target.
26    #[clap(long)]
27    target: Option<VmmTestTargetCli>,
28
29    /// Directory for the output artifacts.
30    #[clap(long)]
31    dir: PathBuf,
32
33    /// Test filter (nextest filter expression)
34    #[clap(long, default_value = "all()")]
35    filter: String,
36
37    /// The test artifacts to download.
38    #[clap(long, value_delimiter = ',', value_parser = parse_vmm_test_image)]
39    artifacts: Vec<ErasedVmmTestImage>,
40
41    /// Prep steps variants to run
42    #[clap(long, value_delimiter = ',')]
43    prep_steps: Vec<String>,
44
45    /// pass `--verbose` to cargo
46    #[clap(long)]
47    verbose: bool,
48
49    /// Automatically install any missing required dependencies.
50    #[clap(long)]
51    install_missing_deps: bool,
52
53    /// Skip the interactive VHD download prompt
54    #[clap(long)]
55    skip_vhd_prompt: bool,
56
57    /// use the nextest CI profile rather than the default one
58    #[clap(long)]
59    ci_profile: bool,
60
61    /// Don't reuse prepped vhds, even if they already exist.
62    /// Use when making changes to prep_steps
63    #[clap(long)]
64    no_reuse_prepped_vhds: bool,
65
66    /// Whether the tests selected require hardware isolation
67    #[clap(long)]
68    needs_hardware_isolation: bool,
69
70    /// Whether the tests selected require the test igvm agent
71    #[clap(long)]
72    needs_igvm_agent: bool,
73
74    /// How many times to run the tests
75    #[clap(long)]
76    repetitions: Option<u64>,
77}
78
79impl IntoPipeline for VmmTestsRunTargetCli {
80    fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> {
81        if !matches!(backend_hint, PipelineBackendHint::Local) {
82            anyhow::bail!("vmm-tests-run-target is for local use only")
83        }
84
85        let Self {
86            target,
87            dir,
88            filter,
89            artifacts,
90            prep_steps,
91            verbose,
92            install_missing_deps,
93            skip_vhd_prompt,
94            ci_profile,
95            no_reuse_prepped_vhds,
96            needs_hardware_isolation,
97            needs_igvm_agent,
98            repetitions,
99        } = self;
100
101        let repetitions =
102            NonZeroU64::new(repetitions.unwrap_or(1)).context("repetitions must not be zero")?;
103
104        let target = resolve_target(target, backend_hint)?;
105
106        let external_deps = match target.as_triple().operating_system {
107            target_lexicon::OperatingSystem::Windows => {
108                VmmTestsExternalDeps::Windows(VmmTestsExternalDepsWindows {
109                    hyperv: true, // TODO
110                    whp: true,    // TODO
111                    hardware_isolation: needs_hardware_isolation,
112                })
113            }
114            target_lexicon::OperatingSystem::Linux => {
115                VmmTestsExternalDeps::Linux(VmmTestsExternalDepsLinux {
116                    hugetlb_2mb_overcommit_pages: None, // TODO
117                    prepare_vhost_vsock: false,         // TODO
118                })
119            }
120            _ => unreachable!(),
121        };
122
123        let mut pipeline = Pipeline::new();
124
125        let mut job = pipeline.new_job(
126            FlowPlatform::host(backend_hint),
127            FlowArch::host(backend_hint),
128            "run vmm tests on target system",
129        );
130
131        job = job.dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request::Init);
132
133        job = job
134            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params {
135                local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams {
136                    interactive: true,
137                    auto_install: install_missing_deps,
138                    ignore_rust_version: true,
139                }),
140                verbose: ReadVar::from_static(verbose),
141                locked: false,
142                deny_warnings: false,
143                no_incremental: false,
144            })
145            .dep_on(
146                |ctx| flowey_lib_hvlite::_jobs::local_run_nextest_vmm_tests::Params {
147                    target,
148                    test_content_dir: dir,
149                    filter,
150                    downloaded_artifacts: artifacts,
151                    external_deps,
152                    prep_steps_variants: prep_steps,
153                    needs_test_igvm_agent_rpc_server: needs_igvm_agent,
154                    skip_vhd_prompt,
155                    nextest_profile: if ci_profile {
156                        flowey_lib_hvlite::run_cargo_nextest_run::NextestProfile::Ci
157                    } else {
158                        flowey_lib_hvlite::run_cargo_nextest_run::NextestProfile::Default
159                    },
160                    petri_params: PetriParams {
161                        disable_remote_artifacts: false,
162                        reuse_prepped_vhds: !no_reuse_prepped_vhds,
163                        require_2mb_hugetlb: false, // TODO
164                    },
165                    repetitions,
166                    done: ctx.new_done_handle(),
167                },
168            );
169
170        job.finish();
171
172        Ok(pipeline)
173    }
174}