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