Validation reads the checkout where the test runner names it, everywhere
A lib-only archive of the validation crate, built on msi and run from another root with
--workspace-remap and the build tree's sources moved away (lavapipe, job m3-max-34590), failed
runtime_lane::tests::a_kernel_runs_the_functions_its_descriptor_links (NotFound at tests.rs:697:
crate::engine::profiles_dir() is env!("CARGO_MANIFEST_DIR")/profiles) and
candidate::engine::graphics::tests::public_render_cases_plan_or_refuse_typed ("0 public render
cases planned": a baked corpus root). Both pass when the build tree is present. The scan
39bff0de2a added covered only runtime_lane/, not the library code the lanes call, nor the rest of
the crate a carried archive holds.
Every env!("CARGO_MANIFEST_DIR") read left in the validation crate moves onto
metal2vulkan-devtools' resolvers, mechanically: the crate's own files onto validation_dir(), the
public fixtures onto fixtures_dir()/engine_dir(), the workspace and crates/ onto workspace_dir().
That is 73 sites in src/ (library ones included: engine::profiles_dir, source::corpus_root,
cutover::list_path, library_module's linked fixtures, mesh_cases, corpus-harvest's default
corpus) and 15 in tests/. The runtime pin's include_str! takes a path relative to its file. A
binary run outside cargo names no manifest directory, so workspace_dir() falls back to the checkout
the dev-tools crate was built in: the same directory as before.
The devtools scan (tests::the_carried_tests_read_the_checkout_where_the_runner_names_it) now
covers all of crates/metal2vulkan-validation/src and tests beside the runtime's src; at the base
it lists the 88 sites.
Test harness and validation tooling only; no product file.
The lib's device tests compile through their own test binary
A lib-only archive of the validation crate (cargo nextest archive -p metal2vulkan-validation --lib,
lavapipe, job m3-max-34590) failed 20 runtime-lane tests whether or not it ran beside its build tree:
the 16 kernels_with_textures_and_samplers_match_metal shards, the two argument-buffer censuses,
sparse_cases_match_metal and public_render_cases_match_metal. All panicked at candidate/tests.rs:63:
compile_worker() looked for the corpus-pipeline binary above the test binary, and Cargo builds a
package's binaries only for a selection that holds an integration test, so a --lib build or archive
never has one.
compile_worker() now names this test binary (CompileWorker::lib_tests), which already installs the
counting allocator (alloc::tests) and already served the compile path's limit probes. A
CompileWorker carries the arguments and variables before the worker argument: none for a binary;
for the lib test binary, `--exact worker::compile::tests::compile_worker_fixture --nocapture
--quiet --` and M2V_TEST_COMPILE_WORKER, so the worker argument run_json's caller appends is a
filter after `--`. The fixture serves a compile, or the probe the variable names, through
worker::serve_process as a binary does, on an 8 MiB thread (a binary serves on its main thread;
the harness runs a test on a 2 MiB one), and exits. It refuses any worker argument but the compile
worker's. run_json decodes the last non-blank line of the worker's stdout as its report, so the
harness's "running 1 test" line before it is not read.
The worker keeps every limit of the boundary: its parent is the same compile() path, so it has
its own process group, the 20-s deadline, the process-group RSS kill, the 500-MiB allocator budget
and scratch removal. The limit probes now go through CompileWorker::lib_tests and compile(),
the exact path the device tests use: deadline (timeout), resident memory (oom), budget
(worker_exit) and the uncounted refusal. New tests:
worker::compile::tests::the_lib_tests_worker_returns_the_pipeline_the_public_api_compiles (the same
comparison tests/integration/compile_worker.rs makes through the real corpus-pipeline,
corpus-vulkan and corpus-moltenvk, which stays) and
worker::tests::a_worker_s_report_is_the_last_line_of_its_stdout.
Test harness only; no product file.
mesh_cases borrows its label for the fixture path; run_json's doc rewrapped
The unbake rewrite moved the row's label into the path join (E0382 in the cpu_icd lib test build,
msi job m3-max-34650); it joins a borrow. Compile fix and doc wrap only.
Why: a lib-only nextest archive of the validation crate (as lanes build) failed 22 tests when run off
its build tree, 20 when run on it (m3-max-34590, lavapipe): the compile worker binary is built only
for selections that include an integration test, and 88 env!("CARGO_MANIFEST_DIR") reads lay
outside the tree the 39bff0de2a scan checks.
Verified (m3-max-34662, msi, at 97feb0e0dc): the lib-only cpu_icd archive, run on lavapipe remapped to
another root with the build tree's sources moved away: 426/426 (the commitwait set, every touched lib
test module and worker::), including the 22 that failed at the base; the four limit probes through
CompileWorker::lib_tests (timeout 20.06 s, RSS kill, allocator budget, uncounted refusal); the new
lib-tests worker equality test. Still running when landed: clippy x3 for validation and devtools, the
plain suites (the corpus-pipeline integration comparison), the widened scan's negative control, rustdoc.
203 lines
9.4 KiB
Rust
203 lines
9.4 KiB
Rust
//! External-tool helpers for metal2vulkan's own tests and its validation tools: the fixture
|
|
//! assemblers (`llvm-as`, `xcrun metal-as`, `spirv-as`), the committed fixture directories, a
|
|
//! synthetic metallib writer ([`metallib`]), a writer of the modules Metal's stitcher makes
|
|
//! ([`stitched`]), the cases of the linked-signature fixtures and Metal's answers to them
|
|
//! ([`linked_signatures`]), a tool's identity, the MoltenVK toolchain the MSL
|
|
//! checks reproduce, and the generated-program fuzzers ([`fuzz`]) the product's CPU-interpreter
|
|
//! tests and validation's device tests both run, the extended-range bicubic table both check
|
|
//! ([`xr_bicubic`]), and the store-buffering litmus kernel both compile
|
|
//! ([`litmus`]).
|
|
//!
|
|
//! Scratch directories every suite's temporaries go in ([`scratch`]): one root under the OS temp
|
|
//! directory, each run's directory removed when its owner drops and, when its owner is killed
|
|
//! instead, by the next run that reads the root.
|
|
//!
|
|
//! The product runs no external tool and takes this crate for its tests alone: it is the
|
|
//! product's path-only dev-dependency, which `cargo publish` drops, and a dependency of
|
|
//! `metal2vulkan-validation`. The tool runner ([`tools`]) reads the `METAL2VULKAN_<TOOL>`
|
|
//! overrides the product's `env_vars` registers (`tools::tool_path_override`, which spells them as
|
|
//! the product does; the product's tests hold the two together): each tool resolves through its
|
|
//! override, then the usual LLVM install directories, then `PATH`. [`spirv`] runs `spirv-val` and
|
|
//! `spirv-dis`, the L3 checks the product's tests and validation share.
|
|
|
|
use std::ffi::OsStr;
|
|
use std::io::Write;
|
|
use std::path::{Path, PathBuf};
|
|
use std::process::Stdio;
|
|
|
|
pub mod fuzz;
|
|
pub mod linked_signatures;
|
|
pub mod litmus;
|
|
pub mod metallib;
|
|
pub mod scratch;
|
|
pub mod spirv;
|
|
pub mod stitched;
|
|
pub mod tools;
|
|
pub mod xr_bicubic;
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
/// The workspace's root (read-only), as the test runner names it as a test runs: two levels above
|
|
/// the manifest directory it names (`cargo test` and `cargo nextest` name the test's crate,
|
|
/// `crates/<name>`; a run of a nextest archive on another machine names it in that machine's
|
|
/// checkout, `--workspace-remap`) where that root holds the validation crate's fixtures, else above
|
|
/// this crate as it was built (a binary run outside cargo, which names no manifest directory).
|
|
/// Tests, and the validation library's paths to committed files (its profiles, corpus and lists),
|
|
/// read the checkout through it and the helpers on it ([`validation_dir`], [`fixtures_dir`],
|
|
/// [`engine_dir`]), never through a path the build baked in (`env!("CARGO_MANIFEST_DIR")`), which
|
|
/// names the build machine's checkout.
|
|
pub fn workspace_dir() -> PathBuf {
|
|
let root = |manifest: &Path| {
|
|
manifest
|
|
.parent()
|
|
.and_then(Path::parent)
|
|
.map(Path::to_path_buf)
|
|
};
|
|
let running = std::env::var_os("CARGO_MANIFEST_DIR")
|
|
.and_then(|manifest| root(Path::new(&manifest)))
|
|
.filter(|root| root.join(VALIDATION).join(FIXTURES).is_dir());
|
|
running.unwrap_or_else(|| {
|
|
root(Path::new(env!("CARGO_MANIFEST_DIR")))
|
|
.expect("the dev-tools crate lies in the workspace's crates/")
|
|
})
|
|
}
|
|
|
|
/// The validation crate, relative to the workspace.
|
|
const VALIDATION: &str = "crates/metal2vulkan-validation";
|
|
|
|
/// The public fixtures, relative to the validation crate.
|
|
const FIXTURES: &str = "fixtures/public";
|
|
|
|
/// The validation crate's directory under [`workspace_dir`] (read-only): its committed cases and
|
|
/// observations (`corpus/`), device profiles (`profiles/`) and sources.
|
|
pub fn validation_dir() -> PathBuf {
|
|
workspace_dir().join(VALIDATION)
|
|
}
|
|
|
|
/// The validation crate's `fixtures/public` under [`validation_dir`] (read-only).
|
|
pub fn fixtures_dir() -> PathBuf {
|
|
validation_dir().join(FIXTURES)
|
|
}
|
|
|
|
/// [`fixtures_dir`]'s `engine` (read-only; the engine's own fixtures).
|
|
pub fn engine_dir() -> PathBuf {
|
|
fixtures_dir().join("engine")
|
|
}
|
|
|
|
/// Why an external tool could not assemble a fixture or compile a module.
|
|
#[derive(Debug)]
|
|
pub enum AssembleError {
|
|
/// The tool is not installed (a test skips visibly).
|
|
Missing(String),
|
|
/// The tool ran and rejected the input (a test fails).
|
|
Rejected(String),
|
|
}
|
|
|
|
/// The bitcode `cmd` (after `pre`) assembles from the text on `input`: a function of the text and
|
|
/// the tool alone, wherever the text lies.
|
|
///
|
|
/// An LLVM assembler names a module after the file it reads, and a text without a
|
|
/// `source_filename` line takes that name as its `source_filename`, a record the bitcode carries.
|
|
/// Read from its path, one text assembled to different bytes in each directory: a census row
|
|
/// assembled in scratch directories named for process ids and counters carried them, so its work
|
|
/// units and ledger peak (the bitstream reader meters a record by its operands) and the detail of
|
|
/// a rejection changed from run to run. So the text goes in on standard input, where the module is
|
|
/// `<stdin>`, and the bitcode comes back on standard output.
|
|
fn assemble(cmd: &str, pre: &[&OsStr], input: Stdio) -> Result<Vec<u8>, AssembleError> {
|
|
let mut args: Vec<&OsStr> = pre.to_vec();
|
|
args.extend(["-", "-o", "-"].map(OsStr::new));
|
|
match tools::run_with_stdin(cmd, &args, input) {
|
|
Ok((bitcode, _)) => Ok(bitcode),
|
|
Err(tools::ToolError::Launch { executable, .. }) => Err(AssembleError::Missing(format!(
|
|
"{cmd} not found ({})",
|
|
executable.display()
|
|
))),
|
|
Err(e) => Err(AssembleError::Rejected(e.to_string())),
|
|
}
|
|
}
|
|
|
|
/// [`assemble`] of the text in the file `input`.
|
|
fn assemble_file(cmd: &str, pre: &[&OsStr], input: &Path) -> Result<Vec<u8>, AssembleError> {
|
|
let text = std::fs::File::open(input)
|
|
.map_err(|e| AssembleError::Rejected(format!("read {}: {e}", input.display())))?;
|
|
assemble(cmd, pre, text.into())
|
|
}
|
|
|
|
/// Opaque-pointer bitcode of an `.ll` fixture (`llvm-as`).
|
|
pub fn llvm_assemble(ll: &Path) -> Result<Vec<u8>, AssembleError> {
|
|
assemble_file("llvm-as", &[], ll)
|
|
}
|
|
|
|
/// Opaque-pointer bitcode of the LLVM text `text` (`llvm-as`), which a test generates rather than
|
|
/// reads from a fixture: the same bitcode [`llvm_assemble`] makes of that text in a file.
|
|
pub fn llvm_assemble_text(text: &str) -> Result<Vec<u8>, AssembleError> {
|
|
let (input, mut feed) =
|
|
std::io::pipe().map_err(|e| AssembleError::Rejected(format!("pipe: {e}")))?;
|
|
std::thread::scope(|scope| {
|
|
// Written beside the tool's run, so neither its input nor its output pipe fills while the
|
|
// other waits. The writer's end closes when the text is written, which ends the input.
|
|
let writer = scope.spawn(move || feed.write_all(text.as_bytes()));
|
|
let bitcode = assemble("llvm-as", &[], input.into());
|
|
match (bitcode, writer.join().expect("the input writer")) {
|
|
(Ok(_), Err(e)) => Err(AssembleError::Rejected(format!(
|
|
"llvm-as stopped reading its input: {e}"
|
|
))),
|
|
(bitcode, _) => bitcode,
|
|
}
|
|
})
|
|
}
|
|
|
|
/// The SPIR-V words of a `.spvasm` fixture (`spirv-as`, SPIR-V 1.5), every numeric id kept as the
|
|
/// text writes it (`--preserve-numeric-ids`), so a module `spirv-dis --raw-id` wrote assembles back
|
|
/// to its own words but the header's generator.
|
|
pub fn spirv_assemble(spvasm: &Path) -> Result<Vec<u32>, AssembleError> {
|
|
let args = ["--preserve-numeric-ids", "--target-env", "spv1.5"].map(OsStr::new);
|
|
let bytes = assemble_file("spirv-as", &args, spvasm)?;
|
|
if bytes.len() % 4 != 0 {
|
|
return Err(AssembleError::Rejected(format!(
|
|
"spirv-as wrote {} bytes for {}, not whole words",
|
|
bytes.len(),
|
|
spvasm.display()
|
|
)));
|
|
}
|
|
Ok(bytes
|
|
.as_chunks::<4>()
|
|
.0
|
|
.iter()
|
|
.map(|word| u32::from_le_bytes(*word))
|
|
.collect())
|
|
}
|
|
|
|
/// Typed-pointer AIR bitcode of an `.air.ll` companion (`xcrun metal-as`, macOS only).
|
|
pub fn metal_assemble(air_ll: &Path) -> Result<Vec<u8>, AssembleError> {
|
|
if !cfg!(target_os = "macos") {
|
|
return Err(AssembleError::Missing("metal-as needs macOS".to_owned()));
|
|
}
|
|
assemble_file("xcrun", &["metal-as".as_ref()], air_ll)
|
|
}
|
|
|
|
/// The `--version` output of external tool `cmd`, resolved as [`llvm_assemble`] and the L3 check
|
|
/// resolve it (`METAL2VULKAN_<TOOL>`, the Homebrew LLVM prefixes, then `PATH`): what a validation
|
|
/// cache keys that tool's behavior by. `Missing` when it cannot be launched, `Rejected` when it
|
|
/// runs and fails.
|
|
pub fn tool_version(cmd: &str) -> Result<String, AssembleError> {
|
|
match tools::run(cmd, &["--version"]) {
|
|
Ok((stdout, _)) => Ok(String::from_utf8_lossy(&stdout).into_owned()),
|
|
Err(tools::ToolError::Launch { executable, .. }) => Err(AssembleError::Missing(format!(
|
|
"{cmd} not found ({})",
|
|
executable.display()
|
|
))),
|
|
Err(e) => Err(AssembleError::Rejected(e.to_string())),
|
|
}
|
|
}
|
|
|
|
/// The pipeline creation the product tests' `pipeline::testing::moltenvk_msl_args` reproduces:
|
|
/// MoltenVK 1.4.1 (the Homebrew bottle, built with Xcode 26.2) on an Apple M3 Max under macOS 26,
|
|
/// the device of the committed `moltenvk-m3` profile.
|
|
pub const MOLTENVK_MSL_TARGET: &str = "MoltenVK 1.4.1 on Apple M3 Max, macOS 26: MSL 4.0";
|
|
|
|
/// The SPIRV-Cross commit MoltenVK 1.4.1 links (its `ExternalRevisions/SPIRV-Cross_repo_revision`).
|
|
/// A `spirv-cross` built from another commit converts as that commit does.
|
|
pub const MOLTENVK_SPIRV_CROSS_REVISION: &str = "adec7acbf41a988713cdb85f93f26c8ca5ea863e";
|