petri_artifacts_vmm_test/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! `petri` test artifacts used by in-tree VMM tests
5
6#![forbid(unsafe_code)]
7
8/// Artifact declarations
9pub mod artifacts {
10    use petri_artifacts_core::declare_artifacts;
11
12    macro_rules! openvmm_native {
13        ($id_ty:ty, $os:literal, $arch:literal) => {
14            /// openvmm "native" executable (i.e:
15            /// [`OPENVMM_WIN_X64`](const@OPENVMM_WIN_X64) when compiled on windows x86_64,
16            /// [`OPENVMM_LINUX_AARCH64`](const@OPENVMM_LINUX_AARCH64) when compiled on linux aarch64,
17            /// etc...)
18            // xtask-fmt allow-target-arch oneoff-petri-native-test-deps
19            #[cfg(all(target_os = $os, target_arch = $arch))]
20            pub const OPENVMM_NATIVE: petri_artifacts_core::ArtifactHandle<$id_ty> =
21                petri_artifacts_core::ArtifactHandle::new();
22        };
23    }
24
25    openvmm_native!(OPENVMM_WIN_X64, "windows", "x86_64");
26    openvmm_native!(OPENVMM_LINUX_X64, "linux", "x86_64");
27    openvmm_native!(OPENVMM_WIN_AARCH64, "windows", "aarch64");
28    openvmm_native!(OPENVMM_LINUX_AARCH64, "linux", "aarch64");
29    openvmm_native!(OPENVMM_MACOS_AARCH64, "macos", "aarch64");
30
31    declare_artifacts! {
32        /// openvmm windows x86_64 executable
33        OPENVMM_WIN_X64,
34        /// openvmm linux x86_64 executable
35        OPENVMM_LINUX_X64,
36        /// openvmm windows aarch64 executable
37        OPENVMM_WIN_AARCH64,
38        /// openvmm linux aarch64 executable
39        OPENVMM_LINUX_AARCH64,
40        /// openvmm macos aarch64 executable
41        OPENVMM_MACOS_AARCH64,
42    }
43
44    /// Loadable artifacts
45    pub mod loadable {
46        use petri_artifacts_common::tags::IsLoadable;
47        use petri_artifacts_common::tags::MachineArch;
48        use petri_artifacts_core::declare_artifacts;
49
50        macro_rules! linux_direct_native {
51            ($id_kernel_ty:ty, $id_initrd_ty:ty, $arch:literal) => {
52                /// Test linux direct kernel (from OpenVMM deps) for the target architecture
53                // xtask-fmt allow-target-arch oneoff-petri-native-test-deps
54                #[cfg(target_arch = $arch)]
55                pub const LINUX_DIRECT_TEST_KERNEL_NATIVE: petri_artifacts_core::ArtifactHandle<
56                    $id_kernel_ty,
57                > = petri_artifacts_core::ArtifactHandle::new();
58                /// Test linux direct initrd (from OpenVMM deps) for the target architecture
59                // xtask-fmt allow-target-arch oneoff-petri-native-test-deps
60                #[cfg(target_arch = $arch)]
61                pub const LINUX_DIRECT_TEST_INITRD_NATIVE: petri_artifacts_core::ArtifactHandle<
62                    $id_initrd_ty,
63                > = petri_artifacts_core::ArtifactHandle::new();
64            };
65        }
66
67        linux_direct_native!(
68            LINUX_DIRECT_TEST_KERNEL_X64,
69            LINUX_DIRECT_TEST_INITRD_X64,
70            "x86_64"
71        );
72        linux_direct_native!(
73            LINUX_DIRECT_TEST_KERNEL_AARCH64,
74            LINUX_DIRECT_TEST_INITRD_AARCH64,
75            "aarch64"
76        );
77
78        declare_artifacts! {
79            /// Test linux direct kernel (from OpenVMM deps)
80            LINUX_DIRECT_TEST_KERNEL_X64,
81            /// Test linux direct initrd (from OpenVMM deps)
82            LINUX_DIRECT_TEST_INITRD_X64,
83            /// Test linux direct kernel (from OpenVMM deps)
84            LINUX_DIRECT_TEST_KERNEL_AARCH64,
85            /// Test linux direct initrd (from OpenVMM deps)
86            LINUX_DIRECT_TEST_INITRD_AARCH64,
87            /// PCAT firmware DLL
88            PCAT_FIRMWARE_X64,
89            /// SVGA firmware DLL
90            SVGA_FIRMWARE_X64,
91            /// UEFI firmware for x64
92            UEFI_FIRMWARE_X64,
93            /// UEFI firmware for aarch64
94            UEFI_FIRMWARE_AARCH64,
95        }
96
97        impl IsLoadable for LINUX_DIRECT_TEST_KERNEL_X64 {
98            const ARCH: MachineArch = MachineArch::X86_64;
99        }
100
101        impl IsLoadable for LINUX_DIRECT_TEST_INITRD_X64 {
102            const ARCH: MachineArch = MachineArch::X86_64;
103        }
104
105        impl IsLoadable for LINUX_DIRECT_TEST_KERNEL_AARCH64 {
106            const ARCH: MachineArch = MachineArch::Aarch64;
107        }
108
109        impl IsLoadable for LINUX_DIRECT_TEST_INITRD_AARCH64 {
110            const ARCH: MachineArch = MachineArch::Aarch64;
111        }
112
113        impl IsLoadable for PCAT_FIRMWARE_X64 {
114            const ARCH: MachineArch = MachineArch::X86_64;
115        }
116
117        impl IsLoadable for SVGA_FIRMWARE_X64 {
118            const ARCH: MachineArch = MachineArch::X86_64;
119        }
120
121        impl IsLoadable for UEFI_FIRMWARE_X64 {
122            const ARCH: MachineArch = MachineArch::X86_64;
123        }
124
125        impl IsLoadable for UEFI_FIRMWARE_AARCH64 {
126            const ARCH: MachineArch = MachineArch::Aarch64;
127        }
128    }
129
130    /// OpenHCL IGVM artifacts
131    pub mod openhcl_igvm {
132        use petri_artifacts_common::tags::IsLoadable;
133        use petri_artifacts_common::tags::IsOpenhclIgvm;
134        use petri_artifacts_common::tags::MachineArch;
135        use petri_artifacts_core::declare_artifacts;
136
137        declare_artifacts! {
138            /// OpenHCL IGVM (standard)
139            LATEST_STANDARD_X64,
140            /// OpenHCL IGVM (standard, with VTL2 dev kernel)
141            LATEST_STANDARD_DEV_KERNEL_X64,
142            /// OpenHCL IGVM (for CVM)
143            LATEST_CVM_X64,
144            /// OpenHCL IGVM (using a linux direct-boot test image instead of UEFI)
145            LATEST_LINUX_DIRECT_TEST_X64,
146            /// OpenHCL IGVM (standard AARCH64)
147            LATEST_STANDARD_AARCH64,
148        }
149
150        impl IsLoadable for LATEST_STANDARD_X64 {
151            const ARCH: MachineArch = MachineArch::X86_64;
152        }
153        impl IsOpenhclIgvm for LATEST_STANDARD_X64 {}
154
155        impl IsLoadable for LATEST_STANDARD_DEV_KERNEL_X64 {
156            const ARCH: MachineArch = MachineArch::X86_64;
157        }
158        impl IsOpenhclIgvm for LATEST_STANDARD_DEV_KERNEL_X64 {}
159
160        impl IsLoadable for LATEST_CVM_X64 {
161            const ARCH: MachineArch = MachineArch::X86_64;
162        }
163        impl IsOpenhclIgvm for LATEST_CVM_X64 {}
164
165        impl IsLoadable for LATEST_LINUX_DIRECT_TEST_X64 {
166            const ARCH: MachineArch = MachineArch::X86_64;
167        }
168        impl IsOpenhclIgvm for LATEST_LINUX_DIRECT_TEST_X64 {}
169
170        impl IsLoadable for LATEST_STANDARD_AARCH64 {
171            const ARCH: MachineArch = MachineArch::Aarch64;
172        }
173        impl IsOpenhclIgvm for LATEST_STANDARD_AARCH64 {}
174
175        /// OpenHCL usermode binary
176        pub mod um_bin {
177            use petri_artifacts_core::declare_artifacts;
178
179            declare_artifacts! {
180                /// Usermode binary for Linux direct
181                LATEST_LINUX_DIRECT_TEST_X64
182            }
183        }
184
185        /// OpenHCL debugging symbols for the usermode binary
186        pub mod um_dbg {
187            use petri_artifacts_core::declare_artifacts;
188
189            declare_artifacts! {
190                /// Usermode symbols for Linux direct
191                LATEST_LINUX_DIRECT_TEST_X64
192            }
193        }
194    }
195
196    /// Test VHD artifacts
197    pub mod test_vhd {
198        use crate::tags::IsHostedOnHvliteAzureBlobStore;
199        use petri_artifacts_common::tags::GuestQuirks;
200        use petri_artifacts_common::tags::IsTestVhd;
201        use petri_artifacts_common::tags::MachineArch;
202        use petri_artifacts_common::tags::OsFlavor;
203        use petri_artifacts_core::declare_artifacts;
204
205        declare_artifacts! {
206            /// guest_test_uefi.img, built for x86_64 from the in-tree `guest_test_uefi` codebase.
207            GUEST_TEST_UEFI_X64,
208            /// guest_test_uefi.img, built for aarch64 from the in-tree `guest_test_uefi` codebase.
209            GUEST_TEST_UEFI_AARCH64,
210        }
211
212        impl IsTestVhd for GUEST_TEST_UEFI_X64 {
213            const OS_FLAVOR: OsFlavor = OsFlavor::Uefi;
214            const ARCH: MachineArch = MachineArch::X86_64;
215        }
216
217        impl IsTestVhd for GUEST_TEST_UEFI_AARCH64 {
218            const OS_FLAVOR: OsFlavor = OsFlavor::Uefi;
219            const ARCH: MachineArch = MachineArch::Aarch64;
220        }
221
222        // NOTE: GUEST_TEST_UEFI is not hosted on the HvLite Azure Blob Store. It is
223        // built just-in-time, using the code that is present in-tree, under
224        // `guest_test_uefi`.
225
226        declare_artifacts! {
227            /// Generation 1 windows test image
228            GEN1_WINDOWS_DATA_CENTER_CORE2022_X64
229        }
230
231        impl IsTestVhd for GEN1_WINDOWS_DATA_CENTER_CORE2022_X64 {
232            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
233            const ARCH: MachineArch = MachineArch::X86_64;
234        }
235
236        impl IsHostedOnHvliteAzureBlobStore for GEN1_WINDOWS_DATA_CENTER_CORE2022_X64 {
237            const FILENAME: &'static str =
238                "WindowsServer-2022-datacenter-core-smalldisk-20348.1906.230803.vhd";
239            const SIZE: u64 = 32214352384;
240        }
241
242        declare_artifacts! {
243            /// Generation 2 windows test image
244            GEN2_WINDOWS_DATA_CENTER_CORE2022_X64
245        }
246
247        impl IsTestVhd for GEN2_WINDOWS_DATA_CENTER_CORE2022_X64 {
248            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
249            const ARCH: MachineArch = MachineArch::X86_64;
250        }
251
252        impl IsHostedOnHvliteAzureBlobStore for GEN2_WINDOWS_DATA_CENTER_CORE2022_X64 {
253            const FILENAME: &'static str =
254                "WindowsServer-2022-datacenter-core-smalldisk-g2-20348.1906.230803.vhd";
255            const SIZE: u64 = 32214352384;
256        }
257
258        declare_artifacts! {
259            /// Generation 2 windows test image
260            GEN2_WINDOWS_DATA_CENTER_CORE2025_X64
261        }
262
263        impl IsTestVhd for GEN2_WINDOWS_DATA_CENTER_CORE2025_X64 {
264            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
265            const ARCH: MachineArch = MachineArch::X86_64;
266        }
267
268        impl IsHostedOnHvliteAzureBlobStore for GEN2_WINDOWS_DATA_CENTER_CORE2025_X64 {
269            const FILENAME: &'static str =
270                "WindowsServer-2025-datacenter-core-smalldisk-g2-26100.3476.250306.vhd";
271            const SIZE: u64 = 32214352384;
272        }
273
274        declare_artifacts! {
275            /// FreeBSD 13.2
276            FREE_BSD_13_2_X64
277        }
278
279        impl IsTestVhd for FREE_BSD_13_2_X64 {
280            const OS_FLAVOR: OsFlavor = OsFlavor::FreeBsd;
281            const ARCH: MachineArch = MachineArch::X86_64;
282
283            fn quirks() -> GuestQuirks {
284                GuestQuirks {
285                    // FreeBSD will ignore shutdown requests that arrive too
286                    // early in the boot process.
287                    hyperv_shutdown_ic_sleep: Some(std::time::Duration::from_secs(15)),
288                }
289            }
290        }
291
292        impl IsHostedOnHvliteAzureBlobStore for FREE_BSD_13_2_X64 {
293            const FILENAME: &'static str = "FreeBSD-13.2-RELEASE-amd64.vhd";
294            const SIZE: u64 = 6477005312;
295        }
296
297        declare_artifacts! {
298            /// Ubuntu 2204 Server
299            UBUNTU_2204_SERVER_X64
300        }
301
302        impl IsTestVhd for UBUNTU_2204_SERVER_X64 {
303            const OS_FLAVOR: OsFlavor = OsFlavor::Linux;
304            const ARCH: MachineArch = MachineArch::X86_64;
305        }
306
307        impl IsHostedOnHvliteAzureBlobStore for UBUNTU_2204_SERVER_X64 {
308            const FILENAME: &'static str = "ubuntu-22.04-server-cloudimg-amd64.vhd";
309            const SIZE: u64 = 2361655808;
310        }
311
312        declare_artifacts! {
313            /// Ubuntu 24.04 Server Aarch64
314            UBUNTU_2404_SERVER_AARCH64
315        }
316
317        impl IsTestVhd for UBUNTU_2404_SERVER_AARCH64 {
318            const OS_FLAVOR: OsFlavor = OsFlavor::Linux;
319            const ARCH: MachineArch = MachineArch::Aarch64;
320        }
321
322        impl IsHostedOnHvliteAzureBlobStore for UBUNTU_2404_SERVER_AARCH64 {
323            const FILENAME: &'static str = "ubuntu-24.04-server-cloudimg-arm64.vhd";
324            const SIZE: u64 = 3758211584;
325        }
326    }
327
328    /// Test ISO artifacts
329    pub mod test_iso {
330        use crate::tags::IsHostedOnHvliteAzureBlobStore;
331        use petri_artifacts_common::tags::GuestQuirks;
332        use petri_artifacts_common::tags::IsTestIso;
333        use petri_artifacts_common::tags::MachineArch;
334        use petri_artifacts_common::tags::OsFlavor;
335        use petri_artifacts_core::declare_artifacts;
336
337        declare_artifacts! {
338            /// FreeBSD 13.2
339            FREE_BSD_13_2_X64
340        }
341
342        impl IsTestIso for FREE_BSD_13_2_X64 {
343            const OS_FLAVOR: OsFlavor = OsFlavor::FreeBsd;
344            const ARCH: MachineArch = MachineArch::X86_64;
345
346            fn quirks() -> GuestQuirks {
347                GuestQuirks {
348                    // FreeBSD will ignore shutdown requests that arrive too
349                    // early in the boot process.
350                    //
351                    // Time is set to 5s longer than the VHD, to account for ISO
352                    // boot being slower.
353                    hyperv_shutdown_ic_sleep: Some(std::time::Duration::from_secs(20)),
354                }
355            }
356        }
357
358        impl IsHostedOnHvliteAzureBlobStore for FREE_BSD_13_2_X64 {
359            const FILENAME: &'static str = "FreeBSD-13.2-RELEASE-amd64-dvd1.iso";
360            const SIZE: u64 = 4245487616;
361        }
362    }
363
364    /// Test VMGS artifacts
365    pub mod test_vmgs {
366        use crate::tags::IsHostedOnHvliteAzureBlobStore;
367        use petri_artifacts_core::declare_artifacts;
368
369        declare_artifacts! {
370            /// VMGS file containing a UEFI boot entry
371            ///
372            /// The file was generated by booting an arbitrary Windows VHD
373            /// (different from the ones used for testing in CI) in OpenVMM
374            /// with a persistent VMGS file enabled. This is useful for testing
375            /// whether default_boot_always_attempt works to boot other VHDs.
376            VMGS_WITH_BOOT_ENTRY,
377        }
378
379        impl IsHostedOnHvliteAzureBlobStore for VMGS_WITH_BOOT_ENTRY {
380            const FILENAME: &'static str = "sample-vmgs.vhd";
381            const SIZE: u64 = 4194816;
382        }
383    }
384
385    /// TMK-related artifacts
386    pub mod tmks {
387        use petri_artifacts_core::declare_artifacts;
388
389        macro_rules! tmk_native {
390            ($id_ty:ty, $os:literal, $arch:literal) => {
391                /// tmk_vmm "native" executable
392                // xtask-fmt allow-target-arch oneoff-petri-native-test-deps
393                #[cfg(all(target_os = $os, target_arch = $arch))]
394                pub const TMK_VMM_NATIVE: petri_artifacts_core::ArtifactHandle<$id_ty> =
395                    petri_artifacts_core::ArtifactHandle::new();
396            };
397        }
398
399        tmk_native!(TMK_VMM_WIN_X64, "windows", "x86_64");
400        tmk_native!(TMK_VMM_LINUX_X64, "linux", "x86_64");
401        tmk_native!(TMK_VMM_WIN_AARCH64, "windows", "aarch64");
402        tmk_native!(TMK_VMM_LINUX_AARCH64, "linux", "aarch64");
403        tmk_native!(TMK_VMM_MACOS_AARCH64, "macos", "aarch64");
404
405        declare_artifacts! {
406            /// TMK VMM for Windows x64
407            TMK_VMM_WIN_X64,
408            /// TMK VMM for Linux x64
409            TMK_VMM_LINUX_X64,
410            /// TMK VMM for MacOS x64
411            TMK_VMM_WIN_AARCH64,
412            /// TMK VMM for Linux aarch64
413            TMK_VMM_LINUX_AARCH64,
414            /// TMK VMM for MacOS aarch64
415            TMK_VMM_MACOS_AARCH64,
416            /// TMK VMM for Linux musl x64
417            TMK_VMM_LINUX_X64_MUSL,
418            /// TMK VMM for Linux musl aarch64
419            TMK_VMM_LINUX_AARCH64_MUSL,
420            /// TMK binary for x64
421            SIMPLE_TMK_X64,
422            /// TMK binary for aarch64
423            SIMPLE_TMK_AARCH64,
424        }
425    }
426}
427
428/// Artifact tag trait declarations
429pub mod tags {
430    use petri_artifacts_core::ArtifactId;
431
432    /// Artifact is associated with a file hosted in HvLite's microsoft-internal
433    /// Azure Blob Store.
434    pub trait IsHostedOnHvliteAzureBlobStore: ArtifactId {
435        /// Filename in the blob store
436        const FILENAME: &'static str;
437        /// Size of the file in bytes
438        const SIZE: u64;
439    }
440}