petri_artifacts_common/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! `petri` test artifact declarations used by all petri-based tests, no matter
5//! what VMM backend is being used.
6
7#![forbid(unsafe_code)]
8
9/// Artifact declarations
10pub mod artifacts {
11 use petri_artifacts_core::declare_artifacts;
12
13 declare_artifacts! {
14 /// Pipette windows x86_64 executable
15 PIPETTE_WINDOWS_X64,
16 /// Pipette linux x86_64 executable
17 PIPETTE_LINUX_X64,
18 /// Pipette windows aarch64 executable
19 PIPETTE_WINDOWS_AARCH64,
20 /// Pipette linux aarch64 executable
21 PIPETTE_LINUX_AARCH64,
22 /// Directory to put petri test logs in
23 TEST_LOG_DIRECTORY,
24 }
25}
26
27/// Artifact tag trait declarations
28pub mod tags {
29 use petri_artifacts_core::ArtifactId;
30
31 /// A coarse-grained label used to differentiate between different OS
32 /// environments.
33 #[derive(Debug, Clone, Copy)]
34 #[expect(missing_docs)] // Self-describing names.
35 pub enum OsFlavor {
36 Windows,
37 Linux,
38 FreeBsd,
39 Uefi,
40 }
41
42 /// The machine architecture supported by the artifact or VM.
43 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
44 #[expect(missing_docs)] // Self describing names
45 pub enum MachineArch {
46 X86_64,
47 Aarch64,
48 }
49
50 impl MachineArch {
51 /// Returns the host's architecture.
52 pub fn host() -> Self {
53 // xtask-fmt allow-target-arch oneoff-petri-host-arch
54 if cfg!(target_arch = "x86_64") {
55 Self::X86_64
56 }
57 // xtask-fmt allow-target-arch oneoff-petri-host-arch
58 else if cfg!(target_arch = "aarch64") {
59 Self::Aarch64
60 } else {
61 panic!("unsupported host architecture")
62 }
63 }
64 }
65
66 /// Quirks needed to boot a guest.
67 #[derive(Default, Copy, Clone, Debug)]
68 pub struct GuestQuirks {
69 /// How long to wait after the shutdown IC reports ready before sending
70 /// the shutdown command.
71 pub hyperv_shutdown_ic_sleep: Option<std::time::Duration>,
72 }
73
74 /// Artifact is a OpenHCL IGVM file
75 pub trait IsOpenhclIgvm: IsLoadable + ArtifactId {}
76
77 /// Artifact is a bootable test VHD file
78 pub trait IsTestVhd: ArtifactId {
79 /// What [`OsFlavor`] this image boots into.
80 const OS_FLAVOR: OsFlavor;
81
82 /// What [`MachineArch`] this image supports.
83 const ARCH: MachineArch;
84
85 /// Declare any "quirks" needed to boot the image.
86 fn quirks() -> GuestQuirks {
87 GuestQuirks::default()
88 }
89 }
90
91 /// Artifact is a bootable test ISO file
92 pub trait IsTestIso: ArtifactId {
93 /// What [`OsFlavor`] this image boots into.
94 const OS_FLAVOR: OsFlavor;
95
96 /// What [`MachineArch`] this image supports.
97 const ARCH: MachineArch;
98
99 /// Declare any "quirks" needed to boot the image.
100 fn quirks() -> GuestQuirks {
101 GuestQuirks::default()
102 }
103 }
104
105 /// Artifact is a binary that can be loaded into a VM
106 pub trait IsLoadable: ArtifactId {
107 /// What [`MachineArch`] this artifact supports.
108 const ARCH: MachineArch;
109 }
110
111 /// Artifact is a test VMGS file
112 pub trait IsTestVmgs: ArtifactId {}
113}