replay: the player opens the new runtime's GPU only while the hang tripwire is absent

The old runtime's device opener refuses a GPU while ~/.cache/m2v-gpu/hang
exists (command-replay prints "error device: ..." and exits 2), but the
new runtime's path opened its device without looking, so rt plays in a
job that followed a hang ran anyway. docs/VALIDATION.md already states
the contract: every GPU open is refused while the file exists.

open_rt now checks the tripwire once, before it makes the instance, for
a GPU only (a CPU device never checks it), as
candidate::runtime_case::open_device does; the refusal takes the same
"error device" line and exit 2. The guard test
gpu::tests::device_opens_exist_only_behind_the_tripwire_check now
counts the new runtime's device opens too (the player's and the replay
tests' rt_device) and fails where a file opens one without the check
before it.

Verified: see the check job (clippy in both configs, the gpu and
replay unit tests, and a negative control: the player without the check
fails the guard test).
This commit is contained in:
Anees Iqbal committed 2026-11-18 15:57:02 -08:00
1 parent e56b590a5d
commit 5f2494bfc5
2 files changed
+22 -2

No files matched your search

@@ -297,8 +297,12 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
/// The new runtime's backend on the first physical device of `device_type` that opens (a GPU:
/// discrete, then integrated, then virtual), its compiled kernels kept in `cache`, and its name.
/// A GPU opens only while the hang tripwire is absent, as the old runtime's device does.
fn open_rt(device_type: DeviceType, cache: PathBuf) -> Result<(NewRuntime, String), String> {
use ash::vk::PhysicalDeviceType as Kind;
if device_type == DeviceType::Gpu {
metal2vulkan_validation::gpu::tripwire::refuse_if_tripped()?;
}
let instance = metal2vulkan_rt::Instance::new(&[]).map_err(|error| error.to_string())?;
let (_, vk_instance) = instance.raw();
let ranks: &[Kind] = match device_type {
+18 -2
View File
@@ -48,8 +48,10 @@ mod tests {
/// Every device open goes through one of the functions that check the hang tripwire first:
/// validation's Vulkan context, the Metal platform, the device validation makes through the
/// runtime (`candidate::runtime_case::open_device`, which the runtime lane and the executor's
/// runtime path share), and the present tests' own device, which the runtime adopts. A new raw
/// open anywhere else in the crate fails here, before it can run.
/// runtime path share), the present tests' own device, which the runtime adopts, and the new
/// runtime's device in the player and in the replay tests, each after the tripwire check in its
/// own file. A new raw open anywhere else in the crate fails here, before it can run, and so
/// does a new-runtime open ahead of its check.
#[test]
fn device_opens_exist_only_behind_the_tripwire_check() {
let root = metal2vulkan_devtools::validation_dir();
@@ -66,6 +68,8 @@ mod tests {
// The runtime's own device creation (`metal2vulkan_runtime`).
concat!("::system_", "default"),
concat!("Device::", "all"),
// The new runtime's device creation (`metal2vulkan_rt`).
concat!("metal2vulkan_rt::Device", "::new("),
];
let allowed: &[(&str, &str, usize)] = &[
("src/candidate/platform/device.rs", opens[2], 1),
@@ -78,7 +82,19 @@ mod tests {
("src/runtime_lane/presenting.rs", opens[2], 1),
("src/runtime_lane/presenting.rs", opens[3], 1),
("src/runtime_lane/presenting.rs", opens[4], 1),
// The new runtime's device: the player's and the replay tests'.
("src/bin/command-replay.rs", opens[7], 1),
("src/runtime_lane/rt_replay.rs", opens[7], 1),
];
let checked = concat!("refuse_if", "_tripped(");
for (file, open, _) in allowed.iter().filter(|(_, open, _)| *open == opens[7]) {
let text = std::fs::read_to_string(root.join(file)).unwrap();
let check = text.find(checked);
assert!(
check.is_some_and(|at| text.find(open).is_some_and(|open| at < open)),
"{file} opens the new runtime's device without the hang tripwire check before it"
);
}
let mut found = Vec::new();
for file in files {
let text = std::fs::read_to_string(&file).unwrap();