Skip to main content

flowey_lib_hvlite/
test_nextest_unit_tests_archive.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Run cargo-nextest based unit tests from a pre-built archive.
5//!
6//! In the context of hvlite, we consider a "unit-test" to be any test which
7//! doesn't require any special dependencies (e.g: additional binaries, disk
8//! images, etc...), and can be run simply by invoking the test bin itself.
9
10use crate::build_nextest_unit_tests::NextestUnitTestArchive;
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 unit tests nextest archive
19        pub nextest_archive_file: ReadVar<NextestUnitTestArchive>,
20        /// Nextest profile to use when running the source code
21        pub nextest_profile: NextestProfile,
22        /// Optionally provide the nextest bin to use
23        pub nextest_bin: Option<ReadVar<PathBuf>>,
24        /// Target for the tests to run on
25        pub target: Option<target_lexicon::Triple>,
26        /// Results of running the tests
27        pub results: WriteVar<TestResults>,
28    }
29}
30
31new_flow_node!(struct Node);
32
33impl FlowNode for Node {
34    type Request = Request;
35
36    fn imports(ctx: &mut ImportCtx<'_>) {
37        ctx.import::<crate::run_cargo_nextest_run::Node>();
38    }
39
40    fn emit(requests: Vec<Self::Request>, ctx: &mut NodeCtx<'_>) -> anyhow::Result<()> {
41        for Request {
42            nextest_archive_file,
43            nextest_profile,
44            nextest_bin,
45            target,
46            results,
47        } in requests
48        {
49            let nextest_archive = nextest_archive_file.map(ctx, |x| x.archive_file);
50
51            ctx.req(crate::run_cargo_nextest_run::Request {
52                friendly_name: "unit-tests".into(),
53                run_kind:
54                    flowey_lib_common::run_cargo_nextest_run::NextestRunKind::RunFromArchive {
55                        archive_file: nextest_archive,
56                        target,
57                        nextest_bin,
58                    },
59                nextest_profile,
60                nextest_filter_expr: None,
61                nextest_working_dir: None,
62                nextest_config_file: None,
63                run_ignored: false,
64                // Prevent tests from silently skipping when optional
65                // dependencies (e.g., Windows SDK DLLs) are missing.
66                extra_env: Some(ReadVar::from_static(BTreeMap::from([(
67                    "OPENVMM_NO_TEST_SKIP".into(),
68                    "1".into(),
69                )]))),
70                pre_run_deps: Vec::new(), // FIXME: ensure all deps are installed
71                results,
72            })
73        }
74
75        Ok(())
76    }
77}