flowey_lib_hvlite/
test_nextest_vmm_tests_archive.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Run cargo-nextest based VMM tests from a pre-built archive.
5//!
6//! NOTE: The caller is responsible for setting `extra_env` and
7//! `pre_run_deps` to ensure that all tests filtered by
8//! `nextest_filter_expr` are able to run successfully.
9
10use crate::build_nextest_vmm_tests::NextestVmmTestsArchive;
11use crate::run_cargo_nextest_run::NextestProfile;
12use flowey::node::prelude::*;
13use flowey_lib_common::run_cargo_nextest_run::TestResults;
14use std::collections::BTreeMap;
15
16flowey_request! {
17    pub struct Request {
18        /// Pre-built VMM tests nextest archive
19        pub nextest_archive_file: ReadVar<NextestVmmTestsArchive>,
20        /// nextest filter expression for what VMM tests to run
21        pub nextest_filter_expr: Option<String>,
22        /// Nextest profile to use when running the source code
23        pub nextest_profile: NextestProfile,
24        /// Nextest working directory (defaults to repo root)
25        pub nextest_working_dir: Option<ReadVar<PathBuf>>,
26        /// Nextest configuration file (defaults to config in repo)
27        pub nextest_config_file: Option<ReadVar<PathBuf>>,
28        /// Optionally provide the nextest bin to use
29        pub nextest_bin: Option<ReadVar<PathBuf>>,
30        /// Target for the tests to run on
31        pub target: Option<ReadVar<target_lexicon::Triple>>,
32        /// Additional env vars set when executing the tests.
33        pub extra_env: ReadVar<BTreeMap<String, String>>,
34        /// Wait for specified side-effects to resolve before building / running
35        /// any tests. (e.g: to allow for some ambient packages / dependencies
36        /// to get installed).
37        pub pre_run_deps: Vec<ReadVar<SideEffect>>,
38        /// Results of running the tests
39        pub results: WriteVar<TestResults>,
40    }
41}
42
43new_simple_flow_node!(struct Node);
44
45impl SimpleFlowNode for Node {
46    type Request = Request;
47
48    fn imports(ctx: &mut ImportCtx<'_>) {
49        ctx.import::<crate::run_cargo_nextest_run::Node>();
50    }
51
52    fn process_request(request: Self::Request, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
53        let Request {
54            nextest_archive_file,
55            nextest_filter_expr,
56            nextest_profile,
57            nextest_working_dir,
58            nextest_config_file,
59            nextest_bin,
60            target,
61            extra_env,
62            mut pre_run_deps,
63            results,
64        } = request;
65
66        if !matches!(ctx.backend(), FlowBackend::Local)
67            && matches!(ctx.platform(), FlowPlatform::Linux(_))
68        {
69            pre_run_deps.push({
70                ctx.emit_rust_step("ensure /dev/kvm is accessible", |_| {
71                    |_| {
72                        let sh = xshell::Shell::new()?;
73                        xshell::cmd!(sh, "sudo chmod a+rw /dev/kvm").run()?;
74                        Ok(())
75                    }
76                })
77            });
78        }
79
80        let nextest_archive = nextest_archive_file.map(ctx, |x| x.archive_file);
81
82        ctx.req(crate::run_cargo_nextest_run::Request {
83            friendly_name: "vmm_tests".into(),
84            run_kind: flowey_lib_common::run_cargo_nextest_run::NextestRunKind::RunFromArchive {
85                archive_file: nextest_archive,
86                target,
87                nextest_bin,
88            },
89            nextest_profile,
90            nextest_filter_expr,
91            nextest_working_dir,
92            nextest_config_file,
93            run_ignored: false,
94            extra_env: Some(extra_env),
95            pre_run_deps,
96            results,
97        });
98
99        Ok(())
100    }
101}