diff --git a/crates/metal2vulkan-conformance/src/case.rs b/crates/metal2vulkan-conformance/src/case.rs index 8a8067589..a107d08d8 100644 --- a/crates/metal2vulkan-conformance/src/case.rs +++ b/crates/metal2vulkan-conformance/src/case.rs @@ -788,6 +788,16 @@ pub trait Side { /// Where the side runs. fn venue(&self) -> Venue; + /// The macOS release and build the side runs on, as `sw_vers -productVersion` and + /// `-buildVersion` answer them on this host (empty where it does not answer): what record mode + /// holds against the oracle the suite names before it takes an answer + /// ([`crate::record::record`]). Every side runs on its host's; a test's stub states the one it + /// stands for. + #[cfg(target_os = "macos")] + fn macos_release(&self) -> (String, String) { + crate::record::sw_vers() + } + /// A library of the shader's AIR, from whichever of its forms the side reads /// ([`ShaderSource`]). fn library(&mut self, source: &ShaderSource<'_>) -> Answer; diff --git a/crates/metal2vulkan-conformance/src/record.rs b/crates/metal2vulkan-conformance/src/record.rs index 2d2a83ffa..b0d43f75b 100644 --- a/crates/metal2vulkan-conformance/src/record.rs +++ b/crates/metal2vulkan-conformance/src/record.rs @@ -93,7 +93,7 @@ pub fn record( reason: reason.to_owned(), }); } - check_host()?; + check_host(&*side)?; let inputs = case.inputs().map_err(|why| RecordError::Case { case: case.name().to_owned(), why, @@ -213,21 +213,12 @@ fn add(outcomes: &mut Vec, transcript: Transcript) { } } -/// Refuse to record on a host that is not the oracle the suite names. +/// Refuse to record on a host that is not the oracle the suite names: `side`'s macOS release and +/// build ([`Side::macos_release`]). #[cfg(target_os = "macos")] -fn check_host() -> Result<(), RecordError> { - let read = |flag: &str| { - std::process::Command::new("/usr/bin/sw_vers") - .arg(flag) - .output() - .ok() - .filter(|output| output.status.success()) - .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned()) - .unwrap_or_default() - }; +fn check_host(side: &dyn Side) -> Result<(), RecordError> { use crate::recording::{ORACLE_CHIP, ORACLE_OS_BUILD, ORACLE_OS_VERSION}; - let version = read("-productVersion"); - let build = read("-buildVersion"); + let (version, build) = side.macos_release(); if version == ORACLE_OS_VERSION && build == ORACLE_OS_BUILD { return Ok(()); } @@ -237,8 +228,24 @@ fn check_host() -> Result<(), RecordError> { }) } +/// This host's macOS release and build, as `sw_vers -productVersion` and `-buildVersion` answer +/// them; each empty where it does not answer. +#[cfg(target_os = "macos")] +pub(crate) fn sw_vers() -> (String, String) { + let read = |flag: &str| { + std::process::Command::new("/usr/bin/sw_vers") + .arg(flag) + .output() + .ok() + .filter(|output| output.status.success()) + .map(|output| String::from_utf8_lossy(&output.stdout).trim().to_owned()) + .unwrap_or_default() + }; + (read("-productVersion"), read("-buildVersion")) +} + /// There is no Metal to record from off macOS. #[cfg(not(target_os = "macos"))] -fn check_host() -> Result<(), RecordError> { +fn check_host(_side: &dyn Side) -> Result<(), RecordError> { Err(RecordError::NoMetal) } diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index c400a3fcd..c71670be4 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -41,6 +41,10 @@ struct StubSide { /// The device name the side's venue answers, so a test can hold a venue-scoped ledger row /// against one venue and not another. device: &'static str, + /// The macOS release and build the side stands for (`Side::macos_release`): the oracle's, + /// so record mode's logic runs on any Mac, where a test does not move it (`on_release`). + #[cfg(target_os = "macos")] + release: (&'static str, &'static str), made: u32, } @@ -52,10 +56,22 @@ impl StubSide { notices: Vec::new(), refuse: Vec::new(), device: "stub", + #[cfg(target_os = "macos")] + release: ( + crate::recording::ORACLE_OS_VERSION, + crate::recording::ORACLE_OS_BUILD, + ), made: 0, } } + /// The same side on another macOS release and build. + #[cfg(target_os = "macos")] + fn on_release(mut self, version: &'static str, build: &'static str) -> Self { + self.release = (version, build); + self + } + /// The same side on a venue of another name. fn on(mut self, device: &'static str) -> Self { self.device = device; @@ -91,6 +107,11 @@ impl Side for StubSide { venue_named(self.device) } + #[cfg(target_os = "macos")] + fn macos_release(&self) -> (String, String) { + (self.release.0.to_owned(), self.release.1.to_owned()) + } + fn library(&mut self, _source: &ShaderSource<'_>) -> Answer { match self.refusal("library") { Some(failure) => Err(failure), @@ -2367,6 +2388,36 @@ fn record_mode_counts_the_outcomes_it_saw_with_their_runs() { } } +/// Record mode refuses to take an answer on a Mac that is not the oracle the suite names, naming +/// both, and the host it holds is the side's (`Side::macos_release`): Metal's side reads this +/// host's, and the stub states the oracle's but here, so the record-mode tests above check record +/// mode's logic on any Mac, the CI runner's macOS among them. +#[cfg(target_os = "macos")] +#[test] +fn record_mode_refuses_a_host_that_is_not_the_oracle() { + use crate::recording::{ORACLE_CHIP, ORACLE_OS_BUILD, ORACLE_OS_VERSION}; + let case = WordsCase::new("words", 2); + let mut moved = StubSide::new(words(&[1, 2])).on_release("26.7.2", "25G332"); + let error = record(&case, &mut moved, 1, Validated::Ran).unwrap_err(); + assert_eq!( + error, + RecordError::HostMoved { + found: "macOS 26.7.2 (25G332)".to_owned(), + named: format!("{ORACLE_CHIP} on macOS {ORACLE_OS_VERSION} ({ORACLE_OS_BUILD})"), + } + ); + assert!( + format!("{error}").contains("re-record every case"), + "{error}" + ); + // The oracle's release on another build is moved too: a recording is keyed by both. + let mut rebuilt = StubSide::new(words(&[1, 2])).on_release(ORACLE_OS_VERSION, "26A999"); + assert!(matches!( + record(&case, &mut rebuilt, 1, Validated::Ran), + Err(RecordError::HostMoved { .. }) + )); +} + #[test] fn a_set_diff_prints_what_is_missing_and_what_is_extra() { let metal = Transcript::new(vec![Node::leaf( diff --git a/crates/metal2vulkan-conformance/src/watch.rs b/crates/metal2vulkan-conformance/src/watch.rs index 3fea15fbc..951620c5c 100644 --- a/crates/metal2vulkan-conformance/src/watch.rs +++ b/crates/metal2vulkan-conformance/src/watch.rs @@ -111,6 +111,11 @@ impl Side for Watching { self.inner.venue() } + #[cfg(target_os = "macos")] + fn macos_release(&self) -> (String, String) { + self.inner.macos_release() + } + fn library(&mut self, source: &ShaderSource<'_>) -> Answer { let _span = self.watch("library"); self.inner.library(source) diff --git a/docs/CONFORMANCE-COVERAGE.md b/docs/CONFORMANCE-COVERAGE.md index c8ba25e5b..705b3f93f 100644 --- a/docs/CONFORMANCE-COVERAGE.md +++ b/docs/CONFORMANCE-COVERAGE.md @@ -522,7 +522,7 @@ An implemented container no case's Metal leg touches. These are the families of | loosenings used | `Unchecked`, `AnyOf`, `Nonzero`, `Absolute` | | justifications named | `Degradation`, `AcceptedDifference`, `WithoutCompression` | | modules forbidding a re-record | 8 | -| `Side` methods (the suite's whole device vocabulary) | 134 | +| `Side` methods (the suite's whole device vocabulary) | 135 | | `Side` methods the Metal leg reaches an SDK item through | 128 | | SDK items a case's Metal leg reaches, median | 52 | | the same, least and most | 0 and 214 |