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            /// OpenHCL IGVM (standard AARCH64, with VTL2 dev kernel)
149            LATEST_STANDARD_DEV_KERNEL_AARCH64
150        }
151
152        impl IsLoadable for LATEST_STANDARD_X64 {
153            const ARCH: MachineArch = MachineArch::X86_64;
154        }
155        impl IsOpenhclIgvm for LATEST_STANDARD_X64 {}
156
157        impl IsLoadable for LATEST_STANDARD_DEV_KERNEL_X64 {
158            const ARCH: MachineArch = MachineArch::X86_64;
159        }
160        impl IsOpenhclIgvm for LATEST_STANDARD_DEV_KERNEL_X64 {}
161
162        impl IsLoadable for LATEST_CVM_X64 {
163            const ARCH: MachineArch = MachineArch::X86_64;
164        }
165        impl IsOpenhclIgvm for LATEST_CVM_X64 {}
166
167        impl IsLoadable for LATEST_LINUX_DIRECT_TEST_X64 {
168            const ARCH: MachineArch = MachineArch::X86_64;
169        }
170        impl IsOpenhclIgvm for LATEST_LINUX_DIRECT_TEST_X64 {}
171
172        impl IsLoadable for LATEST_STANDARD_AARCH64 {
173            const ARCH: MachineArch = MachineArch::Aarch64;
174        }
175        impl IsOpenhclIgvm for LATEST_STANDARD_AARCH64 {}
176
177        impl IsLoadable for LATEST_STANDARD_DEV_KERNEL_AARCH64 {
178            const ARCH: MachineArch = MachineArch::Aarch64;
179        }
180        impl IsOpenhclIgvm for LATEST_STANDARD_DEV_KERNEL_AARCH64 {}
181
182        /// OpenHCL usermode binary
183        pub mod um_bin {
184            use petri_artifacts_core::declare_artifacts;
185
186            declare_artifacts! {
187                /// Usermode binary for Linux direct
188                LATEST_LINUX_DIRECT_TEST_X64
189            }
190        }
191
192        /// OpenHCL debugging symbols for the usermode binary
193        pub mod um_dbg {
194            use petri_artifacts_core::declare_artifacts;
195
196            declare_artifacts! {
197                /// Usermode symbols for Linux direct
198                LATEST_LINUX_DIRECT_TEST_X64
199            }
200        }
201    }
202
203    /// Test VHD artifacts
204    pub mod test_vhd {
205        use crate::tags::IsHostedOnHvliteAzureBlobStore;
206        use petri_artifacts_common::tags::GuestQuirks;
207        use petri_artifacts_common::tags::IsTestVhd;
208        use petri_artifacts_common::tags::MachineArch;
209        use petri_artifacts_common::tags::OsFlavor;
210        use petri_artifacts_core::declare_artifacts;
211
212        declare_artifacts! {
213            /// guest_test_uefi.img, built for x86_64 from the in-tree `guest_test_uefi` codebase.
214            GUEST_TEST_UEFI_X64,
215            /// guest_test_uefi.img, built for aarch64 from the in-tree `guest_test_uefi` codebase.
216            GUEST_TEST_UEFI_AARCH64,
217        }
218
219        impl IsTestVhd for GUEST_TEST_UEFI_X64 {
220            const OS_FLAVOR: OsFlavor = OsFlavor::Uefi;
221            const ARCH: MachineArch = MachineArch::X86_64;
222        }
223
224        impl IsTestVhd for GUEST_TEST_UEFI_AARCH64 {
225            const OS_FLAVOR: OsFlavor = OsFlavor::Uefi;
226            const ARCH: MachineArch = MachineArch::Aarch64;
227        }
228
229        // NOTE: GUEST_TEST_UEFI is not hosted on the HvLite Azure Blob Store. It is
230        // built just-in-time, using the code that is present in-tree, under
231        // `guest_test_uefi`.
232
233        declare_artifacts! {
234            /// Generation 1 windows test image
235            GEN1_WINDOWS_DATA_CENTER_CORE2022_X64
236        }
237
238        impl IsTestVhd for GEN1_WINDOWS_DATA_CENTER_CORE2022_X64 {
239            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
240            const ARCH: MachineArch = MachineArch::X86_64;
241        }
242
243        impl IsHostedOnHvliteAzureBlobStore for GEN1_WINDOWS_DATA_CENTER_CORE2022_X64 {
244            const FILENAME: &'static str =
245                "WindowsServer-2022-datacenter-core-smalldisk-20348.1906.230803.vhd";
246            const SIZE: u64 = 32214352384;
247        }
248
249        declare_artifacts! {
250            /// Generation 2 windows test image
251            GEN2_WINDOWS_DATA_CENTER_CORE2022_X64
252        }
253
254        impl IsTestVhd for GEN2_WINDOWS_DATA_CENTER_CORE2022_X64 {
255            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
256            const ARCH: MachineArch = MachineArch::X86_64;
257        }
258
259        impl IsHostedOnHvliteAzureBlobStore for GEN2_WINDOWS_DATA_CENTER_CORE2022_X64 {
260            const FILENAME: &'static str =
261                "WindowsServer-2022-datacenter-core-smalldisk-g2-20348.1906.230803.vhd";
262            const SIZE: u64 = 32214352384;
263        }
264
265        declare_artifacts! {
266            /// Generation 2 windows test image
267            GEN2_WINDOWS_DATA_CENTER_CORE2025_X64
268        }
269
270        impl IsTestVhd for GEN2_WINDOWS_DATA_CENTER_CORE2025_X64 {
271            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
272            const ARCH: MachineArch = MachineArch::X86_64;
273        }
274
275        impl IsHostedOnHvliteAzureBlobStore for GEN2_WINDOWS_DATA_CENTER_CORE2025_X64 {
276            const FILENAME: &'static str =
277                "WindowsServer-2025-datacenter-core-smalldisk-g2-26100.3476.250306.vhd";
278            const SIZE: u64 = 32214352384;
279        }
280
281        declare_artifacts! {
282            /// FreeBSD 13.2
283            FREE_BSD_13_2_X64
284        }
285
286        impl IsTestVhd for FREE_BSD_13_2_X64 {
287            const OS_FLAVOR: OsFlavor = OsFlavor::FreeBsd;
288            const ARCH: MachineArch = MachineArch::X86_64;
289
290            fn quirks() -> GuestQuirks {
291                GuestQuirks {
292                    // FreeBSD will ignore shutdown requests that arrive too
293                    // early in the boot process.
294                    hyperv_shutdown_ic_sleep: Some(std::time::Duration::from_secs(15)),
295                }
296            }
297        }
298
299        impl IsHostedOnHvliteAzureBlobStore for FREE_BSD_13_2_X64 {
300            const FILENAME: &'static str = "FreeBSD-13.2-RELEASE-amd64.vhd";
301            const SIZE: u64 = 6477005312;
302        }
303
304        declare_artifacts! {
305            /// Ubuntu 2204 Server
306            UBUNTU_2204_SERVER_X64
307        }
308
309        impl IsTestVhd for UBUNTU_2204_SERVER_X64 {
310            const OS_FLAVOR: OsFlavor = OsFlavor::Linux;
311            const ARCH: MachineArch = MachineArch::X86_64;
312        }
313
314        impl IsHostedOnHvliteAzureBlobStore for UBUNTU_2204_SERVER_X64 {
315            const FILENAME: &'static str = "ubuntu-22.04-server-cloudimg-amd64.vhd";
316            const SIZE: u64 = 2361655808;
317        }
318
319        declare_artifacts! {
320            /// Ubuntu 24.04 Server Aarch64
321            UBUNTU_2404_SERVER_AARCH64
322        }
323
324        impl IsTestVhd for UBUNTU_2404_SERVER_AARCH64 {
325            const OS_FLAVOR: OsFlavor = OsFlavor::Linux;
326            const ARCH: MachineArch = MachineArch::Aarch64;
327        }
328
329        impl IsHostedOnHvliteAzureBlobStore for UBUNTU_2404_SERVER_AARCH64 {
330            const FILENAME: &'static str = "ubuntu-24.04-server-cloudimg-arm64.vhd";
331            const SIZE: u64 = 3758211584;
332        }
333
334        declare_artifacts! {
335            /// Windows 11 Enterprise ARM64 24H2
336            WINDOWS_11_ENTERPRISE_AARCH64
337        }
338
339        impl IsTestVhd for WINDOWS_11_ENTERPRISE_AARCH64 {
340            const OS_FLAVOR: OsFlavor = OsFlavor::Windows;
341            const ARCH: MachineArch = MachineArch::Aarch64;
342        }
343
344        impl IsHostedOnHvliteAzureBlobStore for WINDOWS_11_ENTERPRISE_AARCH64 {
345            const FILENAME: &'static str =
346                "windows11preview-arm64-win11-24h2-ent-26100.3775.250406-1.vhdx";
347            const SIZE: u64 = 24398266368;
348        }
349    }
350
351    /// Test ISO artifacts
352    pub mod test_iso {
353        use crate::tags::IsHostedOnHvliteAzureBlobStore;
354        use petri_artifacts_common::tags::GuestQuirks;
355        use petri_artifacts_common::tags::IsTestIso;
356        use petri_artifacts_common::tags::MachineArch;
357        use petri_artifacts_common::tags::OsFlavor;
358        use petri_artifacts_core::declare_artifacts;
359
360        declare_artifacts! {
361            /// FreeBSD 13.2
362            FREE_BSD_13_2_X64
363        }
364
365        impl IsTestIso for FREE_BSD_13_2_X64 {
366            const OS_FLAVOR: OsFlavor = OsFlavor::FreeBsd;
367            const ARCH: MachineArch = MachineArch::X86_64;
368
369            fn quirks() -> GuestQuirks {
370                GuestQuirks {
371                    // FreeBSD will ignore shutdown requests that arrive too
372                    // early in the boot process.
373                    //
374                    // Time is set to 5s longer than the VHD, to account for ISO
375                    // boot being slower.
376                    hyperv_shutdown_ic_sleep: Some(std::time::Duration::from_secs(20)),
377                }
378            }
379        }
380
381        impl IsHostedOnHvliteAzureBlobStore for FREE_BSD_13_2_X64 {
382            const FILENAME: &'static str = "FreeBSD-13.2-RELEASE-amd64-dvd1.iso";
383            const SIZE: u64 = 4245487616;
384        }
385    }
386
387    /// Test VMGS artifacts
388    pub mod test_vmgs {
389        use crate::tags::IsHostedOnHvliteAzureBlobStore;
390        use petri_artifacts_common::tags::IsTestVmgs;
391        use petri_artifacts_core::declare_artifacts;
392
393        declare_artifacts! {
394            /// VMGS file containing a UEFI boot entry
395            ///
396            /// The file was generated by booting an arbitrary Windows VHD
397            /// (different from the ones used for testing in CI) in OpenVMM
398            /// with a persistent VMGS file enabled. This is useful for testing
399            /// whether default_boot_always_attempt works to boot other VHDs.
400            VMGS_WITH_BOOT_ENTRY,
401        }
402
403        impl IsHostedOnHvliteAzureBlobStore for VMGS_WITH_BOOT_ENTRY {
404            const FILENAME: &'static str = "sample-vmgs.vhd";
405            const SIZE: u64 = 4194816;
406        }
407
408        impl IsTestVmgs for VMGS_WITH_BOOT_ENTRY {}
409    }
410
411    /// TMK-related artifacts
412    pub mod tmks {
413        use petri_artifacts_core::declare_artifacts;
414
415        macro_rules! tmk_native {
416            ($id_ty:ty, $os:literal, $arch:literal) => {
417                /// tmk_vmm "native" executable
418                // xtask-fmt allow-target-arch oneoff-petri-native-test-deps
419                #[cfg(all(target_os = $os, target_arch = $arch))]
420                pub const TMK_VMM_NATIVE: petri_artifacts_core::ArtifactHandle<$id_ty> =
421                    petri_artifacts_core::ArtifactHandle::new();
422            };
423        }
424
425        tmk_native!(TMK_VMM_WIN_X64, "windows", "x86_64");
426        tmk_native!(TMK_VMM_LINUX_X64, "linux", "x86_64");
427        tmk_native!(TMK_VMM_WIN_AARCH64, "windows", "aarch64");
428        tmk_native!(TMK_VMM_LINUX_AARCH64, "linux", "aarch64");
429        tmk_native!(TMK_VMM_MACOS_AARCH64, "macos", "aarch64");
430
431        declare_artifacts! {
432            /// TMK VMM for Windows x64
433            TMK_VMM_WIN_X64,
434            /// TMK VMM for Linux x64
435            TMK_VMM_LINUX_X64,
436            /// TMK VMM for MacOS x64
437            TMK_VMM_WIN_AARCH64,
438            /// TMK VMM for Linux aarch64
439            TMK_VMM_LINUX_AARCH64,
440            /// TMK VMM for MacOS aarch64
441            TMK_VMM_MACOS_AARCH64,
442            /// TMK VMM for Linux musl x64
443            TMK_VMM_LINUX_X64_MUSL,
444            /// TMK VMM for Linux musl aarch64
445            TMK_VMM_LINUX_AARCH64_MUSL,
446            /// TMK binary for x64
447            SIMPLE_TMK_X64,
448            /// TMK binary for aarch64
449            SIMPLE_TMK_AARCH64,
450        }
451    }
452}
453
454/// Artifact tag trait declarations
455pub mod tags {
456    use petri_artifacts_core::ArtifactId;
457
458    /// Artifact is associated with a file hosted in HvLite's microsoft-internal
459    /// Azure Blob Store.
460    pub trait IsHostedOnHvliteAzureBlobStore: ArtifactId {
461        /// Filename in the blob store
462        const FILENAME: &'static str;
463        /// Size of the file in bytes
464        const SIZE: u64;
465    }
466}