Skip to main content

flowey_hvlite/pipelines/
cca_tests.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use flowey::node::prelude::ReadVar;
5use flowey::pipeline::prelude::*;
6use std::path::PathBuf;
7
8/// CCA test flows, including installing, updating CCA emulation environment and run OpenVMM tests
9#[derive(clap::Args)]
10pub struct CcaTestsCli {
11    /// Root directory for holding all CCA test related stuff
12    #[clap(long, default_value = "target/cca-test")]
13    pub test_root: PathBuf,
14
15    /// Install CCA emulation environment, including downloading emulator and building all needed firmware
16    #[clap(long)]
17    pub install_emu: bool,
18
19    /// Update CCA emulation environment by rebuilding firmwares, support a few sub-commands
20    #[clap(long)]
21    pub update_emu: bool,
22
23    /// Verbose pipeline output
24    #[clap(long)]
25    pub verbose: bool,
26
27    #[clap(flatten)]
28    pub update_emu_subcmds: CcaTestsUpdateEmuSubCmds,
29}
30
31#[derive(clap::Args)]
32#[clap(next_help_heading = "--update_emu subcommands")]
33pub struct CcaTestsUpdateEmuSubCmds {
34    /// Rebuild the plane0 Linux image from the existing source tree.
35    #[clap(long)]
36    pub rebuild_plane0_linux: bool,
37
38    /// Rebuild the shrinkwrap-generated rootfs image.
39    #[clap(long)]
40    pub rebuild_rootfs: bool,
41
42    /// Update TF-A to specified revision and rebuild.
43    #[clap(long)]
44    pub tfa_rev: Option<String>,
45
46    /// Update TF-RMM to specified revision and rebuild.
47    #[clap(long)]
48    pub tfrmm_rev: Option<String>,
49
50    /// Update plane0 Linux to specified revision and rebuild.
51    #[clap(long)]
52    pub plane0_linux_rev: Option<String>,
53}
54
55impl IntoPipeline for CcaTestsCli {
56    fn into_pipeline(self, backend_hint: PipelineBackendHint) -> anyhow::Result<Pipeline> {
57        let Self {
58            test_root,
59            install_emu,
60            update_emu,
61            verbose,
62            update_emu_subcmds:
63                CcaTestsUpdateEmuSubCmds {
64                    rebuild_plane0_linux,
65                    rebuild_rootfs,
66                    tfa_rev,
67                    tfrmm_rev,
68                    plane0_linux_rev,
69                },
70        } = self;
71
72        let openvmm_repo = flowey_lib_common::git_checkout::RepoSource::ExistingClone(
73            ReadVar::from_static(crate::repo_root()),
74        );
75
76        // Absolute path is expected across cca_tests infrastructure. Relative
77        // paths are resolved from repo root.
78        let test_root = if test_root.is_absolute() {
79            test_root
80        } else {
81            crate::repo_root().join(test_root)
82        };
83
84        let mut pipeline = Pipeline::new();
85
86        if install_emu {
87            let check_job = pipeline
88                .new_job(
89                    FlowPlatform::host(backend_hint),
90                    FlowArch::host(backend_hint),
91                    "cca-tests: check existence of emulation environment needed tools",
92                )
93                .config(flowey_lib_common::install_dist_pkg::Config {
94                    interactive: Some(true),
95                    skip_update: Some(false),
96                })
97                .dep_on(
98                    |ctx| flowey_lib_hvlite::_jobs::local_check_cca_emu_prereq::Params {
99                        done: ctx.new_done_handle(),
100                    },
101                )
102                .finish();
103
104            let install_job = pipeline
105                .new_job(
106                    FlowPlatform::host(backend_hint),
107                    FlowArch::host(backend_hint),
108                    "cca-tests: install emulation environment",
109                )
110                .config(flowey_lib_common::git_checkout::Config {
111                    require_local_clones: Some(false),
112                })
113                .config(flowey_lib_common::install_git::Config {
114                    auto_install: Some(true),
115                })
116                .config(flowey_lib_common::install_dist_pkg::Config {
117                    interactive: Some(true),
118                    skip_update: Some(false),
119                })
120                .dep_on(
121                    |ctx| flowey_lib_hvlite::_jobs::local_install_cca_emu::Params {
122                        test_root: test_root.clone(),
123                        openvmm_root: crate::repo_root(),
124                        done: ctx.new_done_handle(),
125                    },
126                )
127                .finish();
128
129            pipeline.non_artifact_dep(&install_job, &check_job);
130            return Ok(pipeline);
131        }
132
133        let update_job = if update_emu {
134            Some(
135                pipeline
136                    .new_job(
137                        FlowPlatform::host(backend_hint),
138                        FlowArch::host(backend_hint),
139                        "cca-tests: update emulation environment",
140                    )
141                    .dep_on(
142                        |ctx| flowey_lib_hvlite::_jobs::local_update_cca_emu::Params {
143                            test_root: test_root.clone(),
144                            openvmm_root: crate::repo_root(),
145                            sub_cmds: flowey_lib_hvlite::_jobs::local_update_cca_emu::SubCmds {
146                                rebuild_plane0_linux,
147                                rebuild_rootfs,
148                                tfa_rev,
149                                tfrmm_rev,
150                                plane0_linux_rev,
151                            },
152                            done: ctx.new_done_handle(),
153                        },
154                    )
155                    .finish(),
156            )
157        } else {
158            None
159        };
160
161        let test_job = pipeline
162            .new_job(
163                FlowPlatform::host(backend_hint),
164                FlowArch::host(backend_hint),
165                "cca-tests: run cca tests",
166            )
167            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_versions::Request::Init)
168            .dep_on(
169                |_| flowey_lib_hvlite::_jobs::cfg_hvlite_reposource::Params {
170                    hvlite_repo_source: openvmm_repo.clone(),
171                },
172            )
173            .dep_on(|_| flowey_lib_hvlite::_jobs::cfg_common::Params {
174                local_only: Some(flowey_lib_hvlite::_jobs::cfg_common::LocalOnlyParams {
175                    interactive: true,
176                    auto_install: true,
177                    ignore_rust_version: true,
178                }),
179                verbose: ReadVar::from_static(verbose),
180                locked: false,
181                deny_warnings: false,
182                no_incremental: false,
183            })
184            .dep_on(|ctx| flowey_lib_hvlite::_jobs::local_run_cca_test::Params {
185                test_root: test_root.clone(),
186                done: ctx.new_done_handle(),
187            })
188            .finish();
189
190        // Only add dependency if update_job exists
191        if let Some(update_job) = &update_job {
192            pipeline.non_artifact_dep(&test_job, update_job);
193        }
194
195        Ok(pipeline)
196    }
197}