vmm_test_images/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! A crate containing the list of images stored in Azure Blob Storage for
5//! in-tree VMM tests.
6//!
7//! NOTE: with the introduction of
8//! [`petri_artifacts_vmm_test::artifacts::test_vhd`], this crate no longer
9//! contains any interesting metadata about any VHDs, and only serves as a
10//! bridge between the new petri artifact types in `test_vhd`, and existing code
11//! that uses these types in flowey / xtask.
12//!
13//! FUTURE: this crate should be removed entirely, and flowey / xtask should be
14//! updated to use the underlying artifact types themselves.
15
16#![forbid(unsafe_code)]
17
18use petri_artifacts_vmm_test::tags::IsHostedOnHvliteAzureBlobStore;
19
20/// The VHDs currently stored in Azure Blob Storage.
21#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
22#[cfg_attr(feature = "clap", clap(rename_all = "verbatim"))]
23#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
24#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
25#[expect(missing_docs)] // Self-describing names
26pub enum KnownTestArtifacts {
27    Gen1WindowsDataCenterCore2022X64Vhd,
28    Gen2WindowsDataCenterCore2022X64Vhd,
29    Gen2WindowsDataCenterCore2025X64Vhd,
30    FreeBsd13_2X64Vhd,
31    FreeBsd13_2X64Iso,
32    Ubuntu2404ServerX64Vhd,
33    Ubuntu2504ServerX64Vhd,
34    Ubuntu2404ServerAarch64Vhd,
35    Windows11EnterpriseAarch64Vhdx,
36    VmgsWithBootEntry,
37}
38
39struct KnownTestArtifactMeta {
40    variant: KnownTestArtifacts,
41    filename: &'static str,
42    size: u64,
43}
44
45impl KnownTestArtifactMeta {
46    const fn new(variant: KnownTestArtifacts, filename: &'static str, size: u64) -> Self {
47        Self {
48            variant,
49            filename,
50            size,
51        }
52    }
53}
54
55// linear scan to find entries is OK, given how few entries there are
56const KNOWN_TEST_ARTIFACT_METADATA: &[KnownTestArtifactMeta] = &[
57    KnownTestArtifactMeta::new(
58        KnownTestArtifacts::Gen1WindowsDataCenterCore2022X64Vhd,
59        petri_artifacts_vmm_test::artifacts::test_vhd::GEN1_WINDOWS_DATA_CENTER_CORE2022_X64::FILENAME,
60        petri_artifacts_vmm_test::artifacts::test_vhd::GEN1_WINDOWS_DATA_CENTER_CORE2022_X64::SIZE,
61    ),
62    KnownTestArtifactMeta::new(
63        KnownTestArtifacts::Gen2WindowsDataCenterCore2022X64Vhd,
64        petri_artifacts_vmm_test::artifacts::test_vhd::GEN2_WINDOWS_DATA_CENTER_CORE2022_X64::FILENAME,
65        petri_artifacts_vmm_test::artifacts::test_vhd::GEN2_WINDOWS_DATA_CENTER_CORE2022_X64::SIZE,
66    ),
67    KnownTestArtifactMeta::new(
68        KnownTestArtifacts::Gen2WindowsDataCenterCore2025X64Vhd,
69        petri_artifacts_vmm_test::artifacts::test_vhd::GEN2_WINDOWS_DATA_CENTER_CORE2025_X64::FILENAME,
70        petri_artifacts_vmm_test::artifacts::test_vhd::GEN2_WINDOWS_DATA_CENTER_CORE2025_X64::SIZE,
71    ),
72    KnownTestArtifactMeta::new(
73        KnownTestArtifacts::FreeBsd13_2X64Vhd,
74        petri_artifacts_vmm_test::artifacts::test_vhd::FREE_BSD_13_2_X64::FILENAME,
75        petri_artifacts_vmm_test::artifacts::test_vhd::FREE_BSD_13_2_X64::SIZE,
76    ),
77    KnownTestArtifactMeta::new(
78        KnownTestArtifacts::FreeBsd13_2X64Iso,
79        petri_artifacts_vmm_test::artifacts::test_iso::FREE_BSD_13_2_X64::FILENAME,
80        petri_artifacts_vmm_test::artifacts::test_iso::FREE_BSD_13_2_X64::SIZE,
81    ),
82    KnownTestArtifactMeta::new(
83        KnownTestArtifacts::Ubuntu2404ServerX64Vhd,
84        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2404_SERVER_X64::FILENAME,
85        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2404_SERVER_X64::SIZE,
86    ),
87        KnownTestArtifactMeta::new(
88        KnownTestArtifacts::Ubuntu2504ServerX64Vhd,
89        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2504_SERVER_X64::FILENAME,
90        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2504_SERVER_X64::SIZE,
91    ),
92    KnownTestArtifactMeta::new(
93        KnownTestArtifacts::Ubuntu2404ServerAarch64Vhd,
94        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2404_SERVER_AARCH64::FILENAME,
95        petri_artifacts_vmm_test::artifacts::test_vhd::UBUNTU_2404_SERVER_AARCH64::SIZE,
96    ),
97    KnownTestArtifactMeta::new(
98        KnownTestArtifacts::Windows11EnterpriseAarch64Vhdx,
99        petri_artifacts_vmm_test::artifacts::test_vhd::WINDOWS_11_ENTERPRISE_AARCH64::FILENAME,
100        petri_artifacts_vmm_test::artifacts::test_vhd::WINDOWS_11_ENTERPRISE_AARCH64::SIZE
101    ),
102    KnownTestArtifactMeta::new(
103        KnownTestArtifacts::VmgsWithBootEntry,
104        petri_artifacts_vmm_test::artifacts::test_vmgs::VMGS_WITH_BOOT_ENTRY::FILENAME,
105        petri_artifacts_vmm_test::artifacts::test_vmgs::VMGS_WITH_BOOT_ENTRY::SIZE,
106    ),
107];
108
109impl KnownTestArtifacts {
110    /// Get the name of the image.
111    pub fn name(self) -> String {
112        format!("{:?}", self)
113    }
114
115    /// Get the filename of the image.
116    pub fn filename(self) -> &'static str {
117        KNOWN_TEST_ARTIFACT_METADATA
118            .iter()
119            .find(|KnownTestArtifactMeta { variant, .. }| *variant == self)
120            .unwrap()
121            .filename
122    }
123
124    /// Get the image from its filename.
125    pub fn from_filename(filename: &str) -> Option<Self> {
126        Some(
127            KNOWN_TEST_ARTIFACT_METADATA
128                .iter()
129                .find(|KnownTestArtifactMeta { filename: s, .. }| *s == filename)?
130                .variant,
131        )
132    }
133
134    /// Get the expected file size of the image.
135    pub fn file_size(self) -> u64 {
136        KNOWN_TEST_ARTIFACT_METADATA
137            .iter()
138            .find(|KnownTestArtifactMeta { variant, .. }| *variant == self)
139            .unwrap()
140            .size
141    }
142}