Files
metal2vulkan/crates/metal2vulkan-validation/tests/integration/audit_worker.rs
T
Anees Iqbal f4205b38f9 Integration tests start the crate's tools at nextest's run-time path
The nineteen validation integration tests that spawn one of the crate's own
tools (corpus-pipeline, corpus-vulkan, corpus-moltenvk, corpus-triage,
corpus-index) named it with env!("CARGO_BIN_EXE_<tool>"), the path Cargo
bakes in at build time. A nextest archive reused on another machine
extracts its binaries into its own directory, so on every device leg
those tests found no file (ENOENT) and failed. They passed only where the
build's own target directory still existed.

A bin_exe! macro in tests/integration/main.rs now reads nextest's
run-time NEXTEST_BIN_EXE_<tool> (set from cargo-nextest 0.9.15, remapped
to the extracted archive) and falls back to the baked path under cargo
test. All 27 call sites use it. The SERVING constants become functions,
because the path is no longer a compile-time constant.

Verified: cargo fmt. The build, clippy and a remapped-archive rerun of the
integration binary on a node without the build's target directory are
reported with the landing.

Landed (main) at once: its build and clippy (m3-max-30499) and the um870 780M rerun of the
integration binary from a remapped archive run after landing. Test-only: no RUNTIME bump.
2026-11-14 15:52:19 -08:00

93 lines
3.6 KiB
Rust

//! The bitcode-reader audit lane across a real process boundary: `corpus-triage` serves each
//! attempt as a killable worker, and a row audited through it reports what the lane reports in
//! process, with what the parent measured; a program that does not serve the worker stops the
//! attempt, which is the row's result.
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
use metal2vulkan_validation::bitcode_audit::{self, Outcome};
use std::path::{Path, PathBuf};
fn fixture(name: &str) -> Option<String> {
match llvm_assemble(&engine_dir().join(name)) {
Ok(bytes) => Some(base64::Engine::encode(
&base64::engine::general_purpose::STANDARD,
bytes,
)),
Err(AssembleError::Missing(why)) => {
eprintln!("SKIPPED: {why}");
None
}
Err(AssembleError::Rejected(why)) => panic!("llvm-as rejected {name}: {why}"),
}
}
/// `corpus-triage`, executed once first: the OS may scan a freshly linked binary on its first exec
/// (seconds on macOS), which the 20-s worker deadline would count.
fn triage() -> PathBuf {
let program = bin_exe!("corpus-triage");
let _ = std::process::Command::new(&program)
.arg("--help")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status();
program
}
#[test]
fn a_row_read_in_the_worker_reports_what_the_reader_reports_in_process() {
let (Some(blob), Ok(llvm_dis)) = (fixture("store_const.ll"), bitcode_audit::resolve_llvm_dis())
else {
return;
};
let program = &triage();
for blob in [blob.as_str(), "bm90IGJpdGNvZGU="] {
let expected = bitcode_audit::audit_row(Some(blob), &llvm_dis);
let audited = bitcode_audit::audit_row_in_worker(program, Some(blob), &llvm_dis);
assert_eq!(audited.outcome, expected.outcome);
assert_eq!(audited.census, expected.census);
assert_eq!(
(audited.ledger_peak, audited.work),
(expected.ledger_peak, expected.work)
);
let measured = audited.worker.expect("a worker ran");
assert!(measured.allocator_peak_bytes.is_some_and(|peak| peak > 0));
}
// "not bitcode" is refused by both sides.
assert!(matches!(
bitcode_audit::audit_row_in_worker(program, Some("bm90IGJpdGNvZGU="), &llvm_dis).outcome,
Outcome::Refused {
class: "malformed",
llvm_accepts: false,
..
}
));
// No blob, and a blob that is not base64, never reach a worker.
let missing = bitcode_audit::audit_row_in_worker(program, None, &llvm_dis);
assert_eq!(missing.outcome, Outcome::NoBlob);
assert!(missing.worker.is_none());
let corrupt = bitcode_audit::audit_row_in_worker(program, Some("not*base64"), &llvm_dis);
assert!(matches!(corrupt.outcome, Outcome::InvalidBlob(_)));
assert!(corrupt.worker.is_none());
}
/// A program that does not serve the audit worker stops each attempt; the stop is the row's
/// result, measured, never a match or an analysis.
#[cfg(unix)]
#[test]
fn an_attempt_the_boundary_stops_is_the_rows_result() {
let program = Path::new("true");
let read = bitcode_audit::audit_row_in_worker(
program,
Some("bm90IGJpdGNvZGU="),
Path::new("/nonexistent/llvm-dis"),
);
match &read.outcome {
Outcome::Stopped { key, detail } => {
assert_eq!(key, "worker_exit", "{detail}");
assert_eq!(read.outcome.shape(), "worker-stopped worker_exit");
}
other => panic!("{other:?}"),
}
assert!(read.worker.is_some() && read.census.is_none());
}