Validation tests find their inputs and their compile worker under any archive selection

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.
This commit is contained in:
Anees Iqbal committed 2026-11-15 19:16:35 -08:00
1 parent 47e6b45475
commit 52a784770c
47 files changed
+315 -242

No files matched your search

+5 -3
View File
@@ -42,9 +42,11 @@ mod tests;
/// 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. Tests 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.
/// 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
+7 -5
View File
@@ -2,12 +2,14 @@
use std::path::{Path, PathBuf};
/// The test trees, relative to the workspace, that run from nextest archives carried to other
/// machines (`cargo nextest run --archive-file ... --workspace-remap <checkout>`): the runtime
/// lanes and the runtime's lib tests (`src/tests/` and the test modules beside its sources).
/// The trees, relative to the workspace, whose tests run from nextest archives carried to other
/// machines (`cargo nextest run --archive-file ... --workspace-remap <checkout>`): all of the
/// validation crate (its lib test binary holds the runtime lanes and the library code they call,
/// its integration tests and binaries ride a full archive), and the runtime's lib tests
/// (`src/tests/` and the test modules beside its sources).
const CARRIED: [&str; 3] = [
"crates/metal2vulkan-validation/src/runtime_lane",
"crates/metal2vulkan-validation/src/runtime_lane.rs",
"crates/metal2vulkan-validation/src",
"crates/metal2vulkan-validation/tests",
"crates/metal2vulkan-runtime/src",
];
@@ -319,7 +319,7 @@ fn what_the_projection_cannot_place_is_an_error_naming_it() {
/// projection declares exactly that entry.
#[test]
fn every_committed_multi_entry_module_projects_onto_each_entry() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public");
let root = metal2vulkan_devtools::fixtures_dir();
let mut entries = 0;
let mut modules = 0;
for directory in ["", "engine"] {
@@ -424,7 +424,7 @@ fn have_xcrun_metal() -> bool {
}
fn fixtures() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public")
metal2vulkan_devtools::fixtures_dir()
}
fn files(dir: &Path, suffix: &str) -> Vec<PathBuf> {
@@ -245,7 +245,7 @@ fn main() {
}
fn parse_args() -> Option<Options> {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let manifest_dir = metal2vulkan_devtools::validation_dir();
let env_limit = std::env::var("METAL2VULKAN_HARVEST_LIMIT").ok();
let env_offset = std::env::var("METAL2VULKAN_HARVEST_OFFSET").ok();
let env_set = std::env::var("METAL2VULKAN_HARVEST_START_SET").ok();
@@ -992,7 +992,7 @@ declare i32 @air.x(i32)
};
let scratch = crate::ScratchDir::new("bitcode-audit").unwrap();
let out = scratch.path().join("fixture.bc");
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public");
let root = metal2vulkan_devtools::fixtures_dir();
let mut fixtures: Vec<PathBuf> = [root.clone(), root.join("engine")]
.iter()
.flat_map(|d| std::fs::read_dir(d).unwrap())
@@ -423,7 +423,7 @@ fn the_product_fingerprint_covers_the_front_end_crate_by_path() {
/// it lists is declared only under `#[cfg(test)]`.
#[test]
fn this_builds_product_fingerprint_is_the_walk_over_the_product() {
let crates = Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
let crates = metal2vulkan_devtools::workspace_dir().join("crates");
assert_eq!(
product_fingerprint(&crates),
env!("METAL2VULKAN_PRODUCT_FINGERPRINT")
@@ -512,7 +512,7 @@ fn the_product_fingerprint_covers_the_workspace_manifest_it_inherits_from() {
/// fingerprint this crate takes is the walk the translator's build script takes.
#[test]
fn the_build_support_copy_is_the_translators() {
let crate_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let crate_dir = metal2vulkan_devtools::validation_dir();
let ours = std::fs::read(crate_dir.join("build_support.rs")).unwrap();
let translators = std::fs::read(crate_dir.join("../metal2vulkan/build_support.rs")).unwrap();
assert!(
@@ -1,17 +1,13 @@
//! The case artifact digest and the runtime guard.
use std::collections::BTreeMap;
use std::path::Path;
use super::*;
/// The hash of the runtime's sources this build pins (the runtime guard): 64 lowercase hex digits
/// and a newline, which the orchestrator's merge tooling rewrites after a merge that leaves it
/// stale.
const RUNTIME_SOURCES: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/runtime-sources.sha256"
));
const RUNTIME_SOURCES: &str = include_str!("../../../../runtime-sources.sha256");
fn digest(byte: u8) -> Hash256 {
[byte; 32]
@@ -105,7 +101,7 @@ fn an_executed_artifact_round_trips() {
#[test]
fn the_runtime_sources_are_the_committed_ones() {
use sha2::{Digest, Sha256};
let product = Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
let product = metal2vulkan_devtools::workspace_dir().join("crates");
let inputs = env!("METAL2VULKAN_RUNTIME_INPUTS")
.split(':')
.collect::<Vec<_>>();
@@ -1169,7 +1169,7 @@ fn owned_render_pipelines_plan_without_variants_or_diagnostics() {
/// element output is that texture's region.
#[test]
fn render_cases_bind_argument_buffer_buffers_and_texture_arrays() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let (case, row) = (0..64)
@@ -1570,7 +1570,7 @@ fn render_cases_bind_argument_buffer_buffers_and_texture_arrays() {
/// pipeline compiled for that shape is the variant that does not write `Layer`.
#[test]
fn a_slice_choosing_case_binds_the_oracles_one_layer_pass() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let (case, row) = (0..64)
@@ -1648,7 +1648,7 @@ fn b64(bytes: &[u8]) -> String {
/// refused typed.
#[test]
fn public_render_cases_plan_or_refuse_typed() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let mut planned = 0;
@@ -1737,7 +1737,7 @@ fn public_render_cases_plan_or_refuse_typed() {
#[test]
fn public_tessellation_cases_plan_their_patch_draws() {
use crate::executor_contract::tessellation as shared;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let mut planned = 0;
@@ -1891,7 +1891,7 @@ fn public_framebuffer_fetch_cases_plan_their_ordered_input_attachments() {
use metal2vulkan::bind::WriteSource;
use metal2vulkan::device::VkFeature;
use metal2vulkan::pipeline::StorageAttachmentView;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let mut planned = 0;
@@ -2183,7 +2183,7 @@ fn public_framebuffer_fetch_cases_plan_their_ordered_input_attachments() {
#[test]
fn public_framebuffer_fetch_cases_plan_input_attachments_without_an_ordered_form() {
use crate::air::reflect::ResourceKind;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
for stem in ["lunarg-desktop-baseline-2023", "vk12-floor"] {
@@ -2391,7 +2391,7 @@ fn the_cells_follow_the_reflected_master() {
fn public_fragment_imageblock_cases_plan_their_storage_image() {
use metal2vulkan::bind::WriteSource;
use metal2vulkan::device::VkFeature;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let sources = public_sources().unwrap();
let mut planned = 0;
let mut writers = 0;
@@ -2488,7 +2488,7 @@ fn public_fragment_imageblock_cases_plan_their_storage_image() {
/// the write runs after the depth test (the writer under early tests, or its draws testing first).
#[test]
fn imageblock_draws_the_product_does_not_model_are_refused_typed() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let case = CorpusStore::new(&root)
.read_all_cases()
.unwrap()
@@ -2568,8 +2568,7 @@ fn imageblock_draws_the_product_does_not_model_are_refused_typed() {
/// The graphics state of the public fixture `fragment_rate_map_position` drawn by its generated
/// fullscreen vertex function, compiled for lavapipe; `None` without `llvm-as`.
fn rate_map_position_graphics() -> Option<metal2vulkan::pipeline::GraphicsState> {
let ll =
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public/fragment_rate_map_position.ll");
let ll = metal2vulkan_devtools::fixtures_dir().join("fragment_rate_map_position.ll");
let bitcode = assembled(&ll)?;
let mut authored = crate::companion::tests::case(
Stage::Fragment,
@@ -2745,7 +2744,7 @@ fn the_imageblock_helpers_view_each_public_cases_master() {
use crate::candidate::runtime_case::imageblock::{
helpers_text, INITIALIZE_ENTRY, RESOLVE_ENTRY,
};
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let sources = public_sources().unwrap();
let mut compared = 0;
for case in CorpusStore::new(&root).read_all_cases().unwrap() {
@@ -26,7 +26,7 @@ pub(super) fn device(stem: &str) -> Device {
/// The committed cases whose AIR is a public fixture, with that fixture's source row.
fn public_cases() -> Vec<(AuthoredCase, crate::source::SourceRow)> {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let sources = public_sources().unwrap();
let mut out = Vec::new();
@@ -8,7 +8,6 @@ use crate::gpu::DeviceType;
use crate::store::CorpusStore;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::path::Path;
/// The route of each committed public case `names` names, prepared for the CPU device.
fn routes(names: &[&str]) -> BTreeMap<String, Route> {
@@ -20,7 +19,7 @@ fn routes(names: &[&str]) -> BTreeMap<String, Route> {
/// Each committed public case `names` names, prepared for the CPU device.
fn prepared(names: &[&str]) -> BTreeMap<String, PreparedCase> {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = DeviceType::Cpu;
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
names
@@ -185,7 +184,7 @@ fn committed_cases_route_by_their_own_inputs() {
fn a_runtime_case_compiles_its_own_pipeline_where_the_context_refuses_its_templates() {
use super::super::{case_compiles, CompileSubject};
use crate::worker::compile::WorkerDevice;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = DeviceType::Cpu;
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
let profile = WorkerDevice::new(
@@ -244,7 +243,7 @@ fn a_mesh_case_compiles_its_draw_device_free() {
use super::super::{case_compiles, CompileSubject, PlannedPipeline};
use crate::acceptance::{compile_pipeline, AcceptancePipeline, PipelineRequest};
use crate::worker::compile::WorkerDevice;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = DeviceType::Cpu;
let profiles = ["lavapipe", "moltenvk-m3"].map(|stem| {
let worker = WorkerDevice::new(
@@ -565,7 +564,7 @@ fn render_commands_and_render_states_run_as_the_executor_compiles_them() {
fn the_executor_draws_gpu_written_render_commands_where_the_runtime_does() {
use crate::candidate::tests::compile_worker;
use crate::candidate::tests::engine_compute::BACKEND;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = crate::gpu::TEST_DEVICE;
let store = CorpusStore::new(&root);
let cases = store.read_all_cases().unwrap();
@@ -618,7 +617,7 @@ fn the_executor_draws_gpu_written_render_commands_where_the_runtime_does() {
fn compute_command_ranges_run_on_both_paths_as_metal_ran_them() {
use crate::candidate::tests::compile_worker;
use crate::candidate::tests::engine_compute::BACKEND;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = crate::gpu::TEST_DEVICE;
let store = CorpusStore::new(&root);
let cases = store.read_all_cases().unwrap();
@@ -685,7 +684,7 @@ fn runs_as_the_executor_compiles_it(name: &str) {
use crate::candidate::engine::RefusedOn;
use crate::candidate::tests::compile_worker;
use crate::candidate::tests::engine_compute::BACKEND;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = crate::gpu::TEST_DEVICE;
let store = CorpusStore::new(&root);
let case = store
@@ -989,7 +988,7 @@ fn the_runtime_path_calls_the_functions_its_tables_hold() {
#[test]
fn mesh_cases_draw_through_the_runtime_as_metal_drew_them() {
use crate::candidate::tests::engine_compute::BACKEND;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let device = crate::gpu::TEST_DEVICE;
let mut emulated = BTreeSet::new();
for fixture in [
@@ -1752,7 +1752,7 @@ fn a_restricted_row_has_its_own_engine_slot() {
fn a_checked_fragment_imageblock_case_maps_its_plane_onto_the_cells() {
use super::graphics::RenderOutput;
use super::imageblock::Member;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let case = CorpusStore::new(&root)
.read_all_cases()
.unwrap()
@@ -1795,7 +1795,7 @@ fn a_checked_fragment_imageblock_case_maps_its_plane_onto_the_cells() {
/// owner is created holding it there beside the authored data the function reads.
#[test]
fn checked_pipeline_state_cases_prepare_with_their_tokens_in_their_owners() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
for name in [
"pipeline-states-beside-the-data-of-two-stages",
@@ -1873,7 +1873,7 @@ fn checked_pipeline_state_cases_prepare_with_their_tokens_in_their_owners() {
/// executor case.
#[test]
fn checked_render_replay_cases_prepare_their_render_template() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
for (name, render) in [
(
@@ -1960,7 +1960,7 @@ fn a_replayed_draw_stays_in_its_templates_topology_class() {
fn committed_compute_replay_cases_register_their_templates_variant() {
use crate::case::indirect_commands::HostAction;
use std::num::NonZeroU64;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
let mut lengths = [0u32; 31];
lengths[0] = 32;
@@ -2060,7 +2060,7 @@ fn committed_compute_replay_cases_register_their_templates_variant() {
/// refusal for a run the runtime hands back.
#[test]
fn a_template_only_the_runtime_replays_refuses_only_on_the_executors_context() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let name = "patch-draws-a-kernel-encodes-at-factor-scales-and-the-host-encodes";
let case = CorpusStore::new(&root)
.read_all_cases()
@@ -2142,7 +2142,7 @@ fn a_long_replay_records_the_regions_its_dispatch_bound_holds() {
#[test]
fn k14d_replay_cases_register_their_regions_variants() {
use std::num::NonZeroU64;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
let registered = |name: &str| {
let case = cases
@@ -2294,7 +2294,7 @@ fn compute_commands() -> crate::case::indirect_commands::CommandDescriptor {
#[test]
fn replay_templates_map_only_the_families_executed_commands_run() {
use crate::case::indirect_commands::CommandDescriptor;
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let case = CorpusStore::new(&root)
.read_all_cases()
.unwrap()
@@ -2363,7 +2363,7 @@ fn replay_templates_map_only_the_families_executed_commands_run() {
#[test]
fn replay_templates_skip_another_familys_literal_and_map_both_families_of_a_mixed_run() {
use crate::case::{SamplerAddressMode, SamplerFilter, SamplerMipFilter, SamplerResource};
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let cases = CorpusStore::new(&root).read_all_cases().unwrap();
let request = ExecutionRequest::EngineCandidate {
device: DeviceType::Cpu,
@@ -1740,7 +1740,7 @@ const OPENED_CHAINS: &str = "src/candidate/platform/enables/opened_chains.txt";
/// run -p metal2vulkan-validation --run-ignored ignored-only -E 'test(bless_opened_chains)'`.
#[test]
fn every_committed_profiles_context_enables_its_pinned_chain() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(OPENED_CHAINS);
let path = metal2vulkan_devtools::validation_dir().join(OPENED_CHAINS);
let pinned = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{path:?}: {e}"));
let pinned = pinned.lines().collect::<Vec<_>>();
let chains = opened_chains();
@@ -1766,7 +1766,7 @@ fn every_committed_profiles_context_enables_its_pinned_chain() {
#[test]
#[ignore]
fn bless_opened_chains() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(OPENED_CHAINS);
let path = metal2vulkan_devtools::validation_dir().join(OPENED_CHAINS);
let text = opened_chains()
.iter()
.map(|(name, lines)| format!("{}\n", pinned_line(name, lines)))
@@ -264,7 +264,7 @@ mod tests {
/// executors name the structure such a pipeline is made with, or begin dynamic rendering.
#[test]
fn no_pipeline_here_is_made_for_dynamic_rendering() {
let crates = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
let crates = metal2vulkan_devtools::workspace_dir().join("crates");
let mut files = Vec::new();
rust_sources(&crates.join("metal2vulkan-runtime/src"), &mut files);
rust_sources(&crates.join("metal2vulkan-validation/src"), &mut files);
@@ -37,41 +37,15 @@ mod engine_textures;
pub(crate) mod engine_render;
mod pipeline_contracts;
/// The compile worker the device tests compile through: `corpus-pipeline`, the validation binary
/// in this test binary's target profile directory, which serves the worker under the counting allocator, so each
/// test pipeline compiles under the 20-s and 500-MiB boundary in a killable child, never in the
/// process that holds the Vulkan device. It is executed once first: the OS may scan a freshly
/// linked binary on its first exec (seconds on macOS), which the worker's deadline would count.
/// Cargo builds the package's binaries for any test run that includes its integration tests; a
/// `--lib`-only run that never built them fails here, naming the binary.
/// The compile worker the device tests compile through: this test binary
/// (`CompileWorker::lib_tests`), which installs the counting allocator and serves the worker through
/// its fixture test, so each test pipeline compiles under the 20-s and 500-MiB boundary in a
/// killable child, never in the process that holds the Vulkan device. It is the binary under
/// test, built with the same flags, and every selection that runs these tests holds it: a
/// `--lib`-only build or archive has no package binary.
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
pub(crate) fn compile_worker() -> &'static crate::worker::compile::CompileWorker {
static WORKER: std::sync::OnceLock<crate::worker::compile::CompileWorker> =
std::sync::OnceLock::new();
WORKER.get_or_init(|| {
let binary = format!("corpus-pipeline{}", std::env::consts::EXE_SUFFIX);
let test = std::env::current_exe().expect("the test binary's path");
// The package's binaries are in `target/<profile>/`, above the test binary wherever
// Cargo's layout puts it: `<profile>/deps/<test>`, or, in its newer build-directory
// layout, `<profile>/build/<package>/<hash>/out/<test>`.
let program = test
.ancestors()
.skip(1)
.map(|directory| directory.join(&binary))
.find(|path| path.is_file())
.unwrap_or_else(|| {
panic!(
"the compile worker {binary} is not built above {}: run the package's tests \
without --lib, or build its binaries with the same RUSTFLAGS \
(cargo build -p metal2vulkan-validation --bins)",
test.display()
)
});
let _ = std::process::Command::new(&program)
.arg("--help")
.stdout(std::process::Stdio::null())
.stderr(std::process::Stdio::null())
.status();
crate::worker::compile::CompileWorker::program(program)
})
WORKER.get_or_init(|| crate::worker::compile::CompileWorker::lib_tests().unwrap())
}
@@ -375,8 +375,7 @@ fn a_device_buffer_array_binds_its_elements_at_consecutive_slots() {
#[cfg(any(target_os = "linux", target_os = "macos"))]
#[test]
fn an_argument_buffer_pointer_reaches_its_pointee() {
let fixture = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public/kernel_device_pointer_chain_phi.ll");
let fixture = metal2vulkan_devtools::fixtures_dir().join("kernel_device_pointer_chain_phi.ll");
let bitcode = llvm_assemble(&fixture).unwrap();
// `struct Node { device uint *next; uint value; }`: the pointer at 0, the value at 8.
let node = |value: u32| {
@@ -472,8 +471,7 @@ fn a_loaded_pointers_buffer_written_past_its_end_is_guarded() {
#[test]
fn an_oracle_instance_mask_is_refused_typed() {
use crate::candidate::engine::CaseStructure;
let fixture = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public/kernel_instance_as_intersect.ll");
let fixture = metal2vulkan_devtools::fixtures_dir().join("kernel_instance_as_intersect.ll");
let bitcode = llvm_assemble(&fixture).unwrap();
let mut trace = case("instance_as_intersect", vec![0; 36], one_thread());
trace
@@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
/// The corpus root. Only the two committed directories under it are ever read; see the module
/// docs for why the walk is not widened to the root.
fn corpus() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus")
metal2vulkan_devtools::validation_dir().join("corpus")
}
/// A design-record, work-package or plan citation, by the spelling each family uses. `D` followed
@@ -330,7 +330,7 @@ fn no_environment_variable_selects_the_loop_budget() {
}
}
}
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let mut files = Vec::new();
sources(&root.join("src"), &mut files);
sources(&root.join("tests"), &mut files);
@@ -18,11 +18,8 @@ pub(crate) fn of_text(
}
fn fixture(name: &str) -> String {
std::fs::read_to_string(format!(
"{}/fixtures/public/{name}",
env!("CARGO_MANIFEST_DIR")
))
.expect("public fixture")
std::fs::read_to_string(metal2vulkan_devtools::fixtures_dir().join(name))
.expect("public fixture")
}
/// A parameter with `role` and nothing else, present in the pipeline.
@@ -15,11 +15,9 @@ fn the_store_sweep_names_the_installed_cases_the_checker_now_rejects() {
use crate::store::CorpusStore;
use crate::ScratchDir;
let air_ll = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/fixtures/public/kernel_copy_word.ll"
))
.expect("public fixture");
let air_ll =
std::fs::read_to_string(metal2vulkan_devtools::fixtures_dir().join("kernel_copy_word.ll"))
.expect("public fixture");
let air_sha256 = crate::hash::sha256_bytes(air_ll.as_bytes());
let buffer = |binding, role| BufferResource {
binding,
@@ -138,10 +136,9 @@ fn an_output_declared_read_but_written_by_the_kernel_is_accepted() {
BufferResource, Comparison, Dispatch, ExecutionSafety, OutputSelection, ResourceRole, Stage,
};
let air_ll = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/fixtures/public/kernel_copy_word_declared_read.ll"
))
let air_ll = std::fs::read_to_string(
metal2vulkan_devtools::fixtures_dir().join("kernel_copy_word_declared_read.ll"),
)
.expect("public fixture");
let interface =
interface::tests::of_text(&air_ll, "copy_word_declared_read", &BTreeMap::new()).unwrap();
@@ -805,10 +802,7 @@ declare i32 @air.atomic.global.add.u.i32(ptr addrspace(1), i32, i32, i32, i1)
fn the_in_shader_out_of_bounds_targets_follow_their_air() {
use crate::case::out_of_bounds::{ContainmentForm, OutOfBoundsResource};
let fixture = |name: &str| {
let path = format!(
"{}/fixtures/public/engine/{name}.ll",
env!("CARGO_MANIFEST_DIR")
);
let path = metal2vulkan_devtools::engine_dir().join(format!("{name}.ll"));
let text = std::fs::read_to_string(path).unwrap();
interface::tests::of_text(&text, name, &BTreeMap::new()).unwrap()
};
@@ -858,10 +852,7 @@ fn the_in_shader_out_of_bounds_targets_follow_their_air() {
// A load through the pointer alone accesses it, and with neither a load nor a store the
// target is refused: the fixture's AIR without its store through the pointer, then without
// its load as well.
let path = format!(
"{}/fixtures/public/engine/ob2_loaded_pointer.ll",
env!("CARGO_MANIFEST_DIR")
);
let path = metal2vulkan_devtools::engine_dir().join("ob2_loaded_pointer.ll");
let text = std::fs::read_to_string(path).unwrap();
let store = " store i32 %14, ptr addrspace(1) %20, align 4, !tbaa !35\n";
let load = "%12 = load i32, ptr addrspace(1) %11, align 4, !tbaa !35";
@@ -945,11 +936,7 @@ fn out_of_bounds_errors(case: &serde_json::Value, interface: &interface::AirInte
/// The committed `engine/{name}.ll` fixture's text.
fn ob3_fixture(name: &str) -> String {
std::fs::read_to_string(format!(
"{}/fixtures/public/engine/{name}.ll",
env!("CARGO_MANIFEST_DIR")
))
.unwrap()
std::fs::read_to_string(metal2vulkan_devtools::engine_dir().join(format!("{name}.ll"))).unwrap()
}
/// An index buffer target's vertex function reads its `[[vertex_id]]` only clamped to a constant:
@@ -1013,10 +1000,9 @@ fn an_index_buffer_targets_vertex_function_reads_its_vertex_id_clamped() {
/// same case is refused by that rule alone.
#[test]
fn an_attribute_targets_format_has_the_lanes_its_shader_reads() {
let text = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/fixtures/public/vertex_narrow_attributes.ll"
))
let text = std::fs::read_to_string(
metal2vulkan_devtools::fixtures_dir().join("vertex_narrow_attributes.ll"),
)
.unwrap();
let interface =
interface::tests::of_text(&text, "vertex_narrow_attributes", &BTreeMap::new()).unwrap();
@@ -1136,11 +1122,8 @@ fn mesh_draws_case(
BufferResource, Comparison, ExecutionSafety, OutputSelection, RenderTargetResource,
ResourceRole,
};
let air_ll = std::fs::read_to_string(concat!(
env!("CARGO_MANIFEST_DIR"),
"/fixtures/public/engine/mesh_draws.ll"
))
.expect("public fixture");
let air_ll = std::fs::read_to_string(metal2vulkan_devtools::engine_dir().join("mesh_draws.ll"))
.expect("public fixture");
let air_sha256 = crate::hash::sha256_bytes(air_ll.as_bytes());
let target = |index| RenderTargetResource {
index,
@@ -21,7 +21,7 @@ use std::path::{Path, PathBuf};
/// The committed reviewed list `file` (`validation/cutover/<file>`).
pub fn list_path(file: &str) -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
metal2vulkan_devtools::validation_dir()
.join("cutover")
.join(file)
}
@@ -237,7 +237,7 @@ mod tests {
assert!(path.ends_with("cutover/c1-reviewed.json"));
assert_eq!(
path.parent().and_then(Path::parent),
Some(Path::new(env!("CARGO_MANIFEST_DIR")))
Some(metal2vulkan_devtools::validation_dir().as_path())
);
assert_eq!(crate::c1::reviewed::ReviewedList::committed_path(), path);
assert_eq!(
+1 -1
View File
@@ -1186,7 +1186,7 @@ fn l3_outcome(failure: &L3Failure) -> Outcome {
/// The committed device-profile directory (`validation/profiles`).
pub fn profiles_dir() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("profiles")
metal2vulkan_devtools::validation_dir().join("profiles")
}
/// The stems of every committed device profile, sorted.
@@ -235,11 +235,8 @@ mod tests {
/// The text of the owned public fixture `engine/<name>.ll`.
fn fixture(name: &str) -> String {
std::fs::read_to_string(format!(
"{}/fixtures/public/engine/{name}.ll",
env!("CARGO_MANIFEST_DIR")
))
.unwrap()
std::fs::read_to_string(metal2vulkan_devtools::engine_dir().join(format!("{name}.ll")))
.unwrap()
}
/// The projection of `module` onto its entry `entry` of `stage`, and its reflection.
@@ -37,7 +37,7 @@ mod tests {
use super::*;
fn fixture(name: &str) -> String {
let path = format!("{}/fixtures/public/{name}", env!("CARGO_MANIFEST_DIR"));
let path = metal2vulkan_devtools::fixtures_dir().join(name);
std::fs::read_to_string(path).expect("public fixture")
}
+5 -5
View File
@@ -52,7 +52,7 @@ mod tests {
/// open anywhere else in the crate fails here, before it can run.
#[test]
fn device_opens_exist_only_behind_the_tripwire_check() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let mut files = Vec::new();
rust_sources(&root.join("src"), &mut files);
rust_sources(&root.join("tests"), &mut files);
@@ -83,7 +83,7 @@ mod tests {
for file in files {
let text = std::fs::read_to_string(&file).unwrap();
let relative = file
.strip_prefix(root)
.strip_prefix(&root)
.unwrap()
.to_string_lossy()
.replace('\\', "/");
@@ -109,7 +109,7 @@ mod tests {
/// unbounded one anywhere in the crate fails here.
#[test]
fn metal_compilations_run_under_the_compile_deadline() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let mut files = Vec::new();
rust_sources(&root.join("src"), &mut files);
rust_sources(&root.join("tests"), &mut files);
@@ -149,7 +149,7 @@ mod tests {
/// supervises its process group.
#[test]
fn xcrun_runs_only_under_the_compile_deadline() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let mut files = Vec::new();
rust_sources(&root.join("src"), &mut files);
rust_sources(&root.join("tests"), &mut files);
@@ -176,7 +176,7 @@ mod tests {
/// wait anywhere else in the crate (sources, tests, binaries) fails here.
#[test]
fn device_waits_exist_only_in_the_bounded_wait_module() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let mut files = Vec::new();
rust_sources(&root.join("src"), &mut files);
rust_sources(&root.join("tests"), &mut files);
@@ -569,9 +569,7 @@ fn public_linked_modules() -> Result<&'static BTreeMap<String, String>, String>
}
fn public_linked_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public")
.join(PUBLIC_LINKED_DIR)
metal2vulkan_devtools::fixtures_dir().join(PUBLIC_LINKED_DIR)
}
/// The public linked module whose `.ll` text hashes to `module_sha256`, as a row labelled
@@ -1800,11 +1798,7 @@ mod tests {
assert!(is_typed && typed.is_file(), "{}", typed.display());
match metal2vulkan_devtools::llvm_assemble(
&crate::source::public_source_path(&module.label)
.map(|path| {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.join(path)
})
.map(|path| metal2vulkan_devtools::workspace_dir().join(path))
.unwrap(),
) {
Ok(bitcode) => assert_eq!(module.bitcode().unwrap(), bitcode),
@@ -26,9 +26,12 @@ pub(crate) struct MeshFixtureCase {
/// The public row of `entry` at `stage` in the owned fixture `engine/<module>.ll`.
fn row(module: &str, stage: Stage, entry: &str) -> SourceRow {
let label = format!("public/engine/{module}.ll");
let air_ll =
std::fs::read_to_string(format!("{}/fixtures/{label}", env!("CARGO_MANIFEST_DIR")))
.unwrap();
let air_ll = std::fs::read_to_string(
metal2vulkan_devtools::validation_dir()
.join("fixtures")
.join(&label),
)
.unwrap();
SourceRow {
air_sha256: crate::hash::sha256_bytes(air_ll.as_bytes()),
stage: stage.metadata_label().into(),
@@ -54,8 +54,7 @@ fn interface_of(
#[cfg(all(target_os = "macos", m2v_gpu))]
fn compile_metal_fixture(name: &str) -> Vec<u8> {
let scratch = crate::ScratchDir::new(name).unwrap();
let source = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public")
let source = metal2vulkan_devtools::fixtures_dir()
.join(name)
.with_extension("metal");
let air = scratch.path().join("fixture.air");
@@ -7,7 +7,7 @@ use crate::mesh_cases::{self, MeshFixtureCase};
/// `fixture`'s selected output on the Metal device, run as compiled over its checked case: the
/// committed public row, its reflection and interface, and the companion the checker derived.
fn executed(fixture: &MeshFixtureCase) -> Vec<u8> {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let checked = crate::check::check_case(&root, fixture.case.clone())
.unwrap_or_else(|errors| panic!("{errors:?}"));
let shader = &checked.primary;
@@ -3,7 +3,6 @@ use crate::case::{BufferResource, ResourceRole};
use crate::metal::ORACLE_ABI;
use crate::store::CorpusStore;
use std::collections::HashMap;
use std::path::Path;
/// A case whose output is bytes 4..8 of an in/out buffer authored as `0..16`.
fn case(no_effect: Option<&str>) -> AuthoredCase {
@@ -98,7 +97,7 @@ fn a_declaration_is_a_bounded_reason_over_a_selected_output() {
/// and every declaration is well formed.
#[test]
fn every_committed_metal_answer_agrees_with_its_cases_declaration() {
let store = CorpusStore::new(Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus"));
let store = CorpusStore::new(metal2vulkan_devtools::validation_dir().join("corpus"));
let cases = store.read_all_cases().unwrap();
let by_id = cases
.iter()
@@ -11,7 +11,7 @@
//! every public fixture whose entry reaches a loop.
use std::ffi::OsString;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use metal2vulkan::Budget;
use metal2vulkan_air::bitcode::{Decoded, EnumAttrTable, EnumAttrs};
@@ -1485,7 +1485,7 @@ fn instrumented_msl_round_trips_through_metal_as() {
}
fn fixtures() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public")
metal2vulkan_devtools::fixtures_dir()
}
/// Every stage entry a module lists.
+3 -3
View File
@@ -183,7 +183,7 @@ impl SourceRow {
pub fn corpus_root() -> PathBuf {
std::env::var_os(CORPUS_DIR_ENV)
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(DEFAULT_CORPUS_REL))
.unwrap_or_else(|| metal2vulkan_devtools::validation_dir().join(DEFAULT_CORPUS_REL))
}
pub fn shard_index_for_hash(hash: &str) -> Result<usize, String> {
@@ -2215,7 +2215,7 @@ mod tests {
fn every_committed_public_module_is_a_row_per_entry_the_product_decodes() {
use metal2vulkan_devtools::{llvm_assemble, AssembleError};
let meter = || metal2vulkan_air::budget::Meter::new(&metal2vulkan::Budget::default());
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/public");
let root = metal2vulkan_devtools::fixtures_dir();
let sources = public_source_set().unwrap();
let (mut modules, mut compared, mut undecoded) = (0, 0, Vec::new());
for directory in PUBLIC_SOURCE_DIRS.map(|relative| root.join(relative)) {
@@ -2278,7 +2278,7 @@ mod tests {
#[test]
fn every_engine_source_row_has_the_typed_half_the_metal_oracle_loads() {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/public");
let root = metal2vulkan_devtools::fixtures_dir();
let rows = public_sources().unwrap();
let engine = rows
.iter()
+9 -19
View File
@@ -1467,9 +1467,7 @@ entry:
#[test]
fn indirect_command_fixtures_close_beside_another_observable_effect_or_through_replay() {
fn fixture(name: &str) -> SourceRow {
let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public")
.join(name);
let path = metal2vulkan_devtools::fixtures_dir().join(name);
let air_ll = std::fs::read_to_string(&path).unwrap();
let (stage, entry) = crate::air::stage_entry_from_ll(&air_ll).unwrap();
SourceRow {
@@ -1807,7 +1805,7 @@ entry:
);
// The build's fingerprints are the product's and the classifier's own sources, hashed as
// below.
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
let crate_root = metal2vulkan_devtools::validation_dir();
let inputs = env!("METAL2VULKAN_CLASSIFIER_INPUTS")
.split(':')
@@ -1827,7 +1825,7 @@ entry:
env!("METAL2VULKAN_PRODUCT_FINGERPRINT")
);
assert_eq!(
classifier(crate_root),
classifier(&crate_root),
env!("METAL2VULKAN_CLASSIFIER_FINGERPRINT"),
"the test hashes the classifier's sources the way the build does"
);
@@ -1919,7 +1917,7 @@ entry:
),
]);
let dependencies =
super::classifier_inputs::dependencies(crate_root, &[], &inputs).unwrap();
super::classifier_inputs::dependencies(&crate_root, &[], &inputs).unwrap();
let unlisted = dependencies
.iter()
.filter(|(file, _)| {
@@ -2426,12 +2424,8 @@ entry:
/// The row of entry `entry` of the committed public module `name`: the module's text, standing
/// for that entry.
fn entry_of(name: &str, entry: &str) -> SourceRow {
let air_ll = std::fs::read_to_string(
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public")
.join(name),
)
.unwrap();
let air_ll =
std::fs::read_to_string(metal2vulkan_devtools::fixtures_dir().join(name)).unwrap();
let declared = crate::air::module_entries(&air_ll)
.unwrap()
.into_iter()
@@ -2480,12 +2474,8 @@ entry:
("engine/fragment_rog.ll", "rog_loop"),
("engine/fragment_discard_msl22.ll", "discard_loop"),
] {
let text = std::fs::read_to_string(
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("fixtures/public")
.join(module),
)
.unwrap();
let text = std::fs::read_to_string(metal2vulkan_devtools::fixtures_dir().join(module))
.unwrap();
let entries = crate::air::module_entries(&text).unwrap();
assert!(entries.len() > 1, "{module}");
for entry in entries {
@@ -2559,7 +2549,7 @@ entry:
/// projection keeps only the entry's.
#[test]
fn the_product_reflects_each_projection_as_its_entry_in_the_module() {
let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/public");
let root = metal2vulkan_devtools::fixtures_dir();
let without_static_samplers = |mut interface: crate::air::reflect::ShaderInterface| {
interface
.bindings
+40 -6
View File
@@ -121,8 +121,8 @@ impl Peaks {
/// Write `result` to stdout as this worker's one report, with its counting allocator's process
/// peak ([`alloc::peak_bytes`]) and its own resident high water
/// ([`process::own_peak_resident_bytes`]), for [`run_json`] to decode. Every worker child reports
/// through this, as its last act.
/// ([`process::own_peak_resident_bytes`]), for [`run_json`] to decode: one line of JSON, the last
/// of its stdout. Every worker child reports through this, as its last act.
pub fn report<R: Serialize>(result: &R) -> Result<(), String> {
report_with_peaks(result, Peaks::now())
}
@@ -268,9 +268,11 @@ impl<R> WorkerRun<R> {
static SUPERVISOR_HEAP: std::sync::Once = std::sync::Once::new();
/// Run `command` as a killable worker under [`DEADLINE`] and [`MEMORY_LIMIT_BYTES`]:
/// `write_input` fills the file that becomes the child's stdin, and the child's stdout is decoded
/// as its one [`report`] of an `R`. The deadline covers input preparation, the child, and result decoding; the
/// process group is killed on every exit path and the scratch directory is removed.
/// `write_input` fills the file that becomes the child's stdin, and the last line of the child's
/// stdout is decoded as its one [`report`] of an `R` (a test binary serving a worker, the lib
/// tests' compile worker, prints its harness's line before it). The deadline covers input
/// preparation, the child, and result decoding; the process group is killed on every exit path
/// and the scratch directory is removed.
pub fn run_json<R: DeserializeOwned>(
command: Command,
purpose: &str,
@@ -349,7 +351,7 @@ pub fn run_json_within<R: DeserializeOwned>(
allocator_peak_bytes,
resident_peak_bytes,
result,
} = serde_json::from_slice(&output).map_err(|error| {
} = serde_json::from_slice(last_line(&output)).map_err(|error| {
WorkerFailure::Output(
format!("decode translation worker result: {error}"),
measured(exited),
@@ -376,6 +378,14 @@ pub fn run_json_within<R: DeserializeOwned>(
})
}
/// The last line of `output` that holds anything but whitespace (a worker's [`report`]), or none.
fn last_line(output: &[u8]) -> &[u8] {
output
.split(|byte| *byte == b'\n')
.rfind(|line| !line.trim_ascii().is_empty())
.unwrap_or_default()
}
fn single_line(value: &str) -> String {
value.split_whitespace().collect::<Vec<_>>().join(" ")
}
@@ -417,6 +427,30 @@ mod tests {
assert_eq!(measured.peak_resident_bytes, run.peak_resident_bytes);
}
/// A worker's report is the last line of its stdout: what a test harness serving the worker
/// printed before it is not the report.
#[cfg(unix)]
#[test]
fn a_worker_s_report_is_the_last_line_of_its_stdout() {
let run: WorkerRun<u32> = run_json(
shell("printf '\\nrunning 1 test\\n{\"allocator_peak_bytes\": null, \"result\": 7}'"),
"worker-test",
|_| Ok(()),
)
.unwrap();
assert_eq!(run.result, 7);
let failure = run_json::<u32>(
shell("printf '{\"allocator_peak_bytes\": null, \"result\": 7}\\nrunning 1 test\\n'"),
"worker-test",
|_| Ok(()),
)
.unwrap_err();
assert!(
matches!(&failure, WorkerFailure::Output(message, _) if message.contains("decode")),
"{failure:?}"
);
}
/// A worker's report states its counting allocator's process peak and its resident high
/// water, which survive the round trip; a peak the sampler missed still sets the ceiling
/// measure.
@@ -78,10 +78,18 @@ pub const ARTIFACT_FILE: &str = "M2V_COMPILE_WORKER_ARTIFACT";
/// The executable that serves compile workers: a validation binary that calls
/// [`serve_if_requested`] first in `main` and installs
/// [`CountingAllocator`](super::alloc::CountingAllocator) as its global allocator.
/// [`CountingAllocator`](super::alloc::CountingAllocator) as its global allocator, or this crate's
/// lib test binary, which installs it too (`alloc::tests`) and serves through a fixture test
/// (`CompileWorker::lib_tests`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompileWorker {
program: PathBuf,
/// The arguments before the worker's own: none for a binary, which reads its worker argument
/// first; the lib test binary's selection of its fixture test.
selection: Vec<String>,
/// The variables the worker starts with: none for a binary; the fixture's role for the lib
/// test binary.
environment: Vec<(String, String)>,
}
impl CompileWorker {
@@ -97,16 +105,71 @@ impl CompileWorker {
pub fn program(program: impl Into<PathBuf>) -> CompileWorker {
CompileWorker {
program: program.into(),
selection: Vec::new(),
environment: Vec::new(),
}
}
/// This crate's lib test binary, the running one, serving each compile through its fixture
/// test ([`LIB_TESTS_FIXTURE`]) as a binary serves it: in a child of its own process group,
/// under the deadline, the process-group RSS limit and the allocator budget, its scratch
/// removed. Any selection that runs the lib's tests holds it, where a `--lib` build builds no
/// package binary.
#[cfg(test)]
pub(crate) fn lib_tests() -> Result<CompileWorker, String> {
CompileWorker::lib_tests_as(LIB_TESTS_SERVE)
}
/// [`CompileWorker::lib_tests`], its fixture serving `role` ([`LIB_TESTS_ROLE`]). The test
/// harness parses the binary's arguments, so the selection runs the fixture alone and ends
/// with `--`: the worker argument after it is a filter that names no test. The harness's
/// terse output prints one line before the test runs and none of the test's name, so the
/// worker's report stays the last line of its stdout (`worker::run_json`).
#[cfg(test)]
fn lib_tests_as(role: &str) -> Result<CompileWorker, String> {
let program = std::env::current_exe()
.map_err(|error| format!("resolve the lib test binary: {error}"))?;
Ok(CompileWorker {
program,
selection: ["--exact", LIB_TESTS_FIXTURE, "--nocapture", "--quiet", "--"]
.map(String::from)
.to_vec(),
environment: vec![(LIB_TESTS_ROLE.to_string(), role.to_string())],
})
}
/// A command that starts the worker's executable, before its worker argument: also the
/// engine device worker's (`super::device`), which every tool that runs cases serves.
pub(crate) fn command(&self) -> Command {
Command::new(&self.program)
let mut command = Command::new(&self.program);
command.args(&self.selection).envs(
self.environment
.iter()
.map(|(name, value)| (name.as_str(), value.as_str())),
);
command
}
}
/// The lib test binary's compile worker fixture ([`CompileWorker::lib_tests`]).
#[cfg(test)]
const LIB_TESTS_FIXTURE: &str = "worker::compile::tests::compile_worker_fixture";
/// The variable that makes [`LIB_TESTS_FIXTURE`] a compile worker child, naming what it serves:
/// [`LIB_TESTS_SERVE`], or one of its limit probes.
#[cfg(test)]
const LIB_TESTS_ROLE: &str = "M2V_TEST_COMPILE_WORKER";
/// [`LIB_TESTS_ROLE`]'s value for a compile.
#[cfg(test)]
const LIB_TESTS_SERVE: &str = "serve";
/// The stack [`LIB_TESTS_FIXTURE`] serves on: a binary serves on its main thread, whose stack is
/// 8 MiB (Linux's default stack limit; macOS's main thread), where the harness runs a test on a
/// 2-MiB thread.
#[cfg(test)]
const LIB_TESTS_STACK: usize = 8 << 20;
/// The device a worker compiles for: the description and policy the child rebuilds it from, and
/// the parent's `Device` built from exactly that pair, against which the artifact is decoded.
#[derive(Clone, Debug)]
@@ -273,7 +336,7 @@ fn compile<P: PipelineArtifact>(
compile_in(command, device, libraries, request)
}
/// [`compile`] in the worker `command` starts (the tests' limit probes start this test binary).
/// [`compile`] in the worker `command` starts.
fn compile_in<P: PipelineArtifact>(
mut command: Command,
device: &WorkerDevice,
@@ -1211,15 +1274,12 @@ mod tests {
}
}
/// The variable that makes [`compile_worker_fixture`] a compile worker child, naming the
/// [`Probe`] it serves.
const PROBE: &str = "M2V_TEST_COMPILE_WORKER_PROBE";
/// The compile path's limit probes: test-only requests a compile worker child serves in place
/// of a compile, each breaching one limit of the boundary. The child is this test binary
/// running [`compile_worker_fixture`], which counts its allocations (`alloc::tests` installs
/// the counting allocator), through the worker's own process (`worker::serve_process`); the
/// parent is [`compile_in`], as every tool's compile.
/// of a compile, each breaching one limit of the boundary. The child is the worker the lib's
/// device tests compile through (`CompileWorker::lib_tests`), this test binary running
/// [`compile_worker_fixture`], which counts its allocations (`alloc::tests` installs the
/// counting allocator), through the worker's own process (`worker::serve_process`); the
/// parent is [`compile`], as every tool's compile.
#[derive(Clone, Copy, Debug)]
enum Probe {
/// Never answer: the deadline stops the worker.
@@ -1280,46 +1340,99 @@ mod tests {
}
}
/// A compile worker child when [`PROBE`] names a probe (the parent tests below start it);
/// otherwise nothing.
/// The lib test binary's compile worker child ([`CompileWorker::lib_tests`]) when
/// [`LIB_TESTS_ROLE`] is set: a compile ([`LIB_TESTS_SERVE`]), or the [`Probe`] it names,
/// served as a binary serves one ([`serve_if_requested`]) on a stack of a binary's main
/// thread ([`LIB_TESTS_STACK`]); otherwise nothing. It serves the compile worker alone: the
/// worker argument its parent passed is its last.
#[test]
fn compile_worker_fixture() {
let Some(probe) = std::env::var(PROBE)
.ok()
.and_then(|name| Probe::ALL.into_iter().find(|probe| probe.name() == name))
else {
let Ok(role) = std::env::var(LIB_TESTS_ROLE) else {
return;
};
let counting = alloc::installed() && !matches!(probe, Probe::Uncounted);
std::process::exit(crate::worker::serve_process(
"engine compile worker",
counting,
|input, started| probe.serve(input, started),
));
assert_eq!(
std::env::args().last().as_deref(),
Some(WORKER_ARG),
"the lib test binary serves only the compile worker"
);
let probe = Probe::ALL.into_iter().find(|probe| probe.name() == role);
assert!(
probe.is_some() || role == LIB_TESTS_SERVE,
"{LIB_TESTS_ROLE} names no role: {role}"
);
let counting = alloc::installed() && !matches!(probe, Some(Probe::Uncounted));
let served = std::thread::Builder::new()
.stack_size(LIB_TESTS_STACK)
.spawn(move || {
crate::worker::serve_process("engine compile worker", counting, |input, started| {
match probe {
Some(probe) => probe.serve(input, started),
None => serve_to_artifact_file(input, started),
}
})
})
.unwrap()
.join()
.unwrap();
std::process::exit(served);
}
/// Compile through a worker child that serves `probe`, as a tool compiles a kernel.
/// Compile through a worker child that serves `probe`, as a tool compiles a kernel: the lib
/// tests' worker ([`CompileWorker::lib_tests`]) serving it in place of a compile.
fn compile_probe(probe: Probe) -> Result<WorkerCompile<ComputePipeline>, WorkerFailure> {
let mut command = Command::new(std::env::current_exe().unwrap());
command
.args([
"--exact",
"worker::compile::tests::compile_worker_fixture",
"--nocapture",
])
.env(PROBE, probe.name());
let request = PipelineRequest::Compute {
entry: "main".into(),
constants: FunctionConstantValues::defaults(),
};
compile_in(
command,
compile(
&CompileWorker::lib_tests_as(&probe.name()).unwrap(),
&worker_device("vk12-floor"),
&[crate::acceptance::retained(b"bitcode")],
&request,
)
}
/// The lib tests' worker ([`CompileWorker::lib_tests`]), the one their device tests compile
/// through, returns across the process boundary the pipeline the public API compiles in
/// process, with its counting allocator's peaks, as every binary that serves the worker does
/// (`tests/integration/compile_worker.rs`, through `corpus-pipeline`).
#[test]
fn the_lib_tests_worker_returns_the_pipeline_the_public_api_compiles() {
let Some(bitcode) = fixture("store_const.ll") else {
return;
};
let device = worker_device("moltenvk-m3");
let request = PipelineRequest::Compute {
entry: "store_const".into(),
constants: FunctionConstantValues::defaults(),
};
let AcceptancePipeline::Compute(expected) =
compile_pipeline(&[&bitcode], &request, device.device(), None)
.unwrap()
.pipeline
else {
panic!("a kernel compiles to a compute pipeline");
};
let compiled = compile_compute(
&CompileWorker::lib_tests().unwrap(),
&device,
&crate::acceptance::retained(&bitcode),
"store_const",
&FunctionConstantValues::defaults(),
)
.unwrap_or_else(|failure| panic!("{}", failure.message()));
let pipeline = compiled.result.unwrap();
assert_eq!(pipeline.pipeline, *expected);
assert!(pipeline.handles.is_empty());
assert!(compiled.allocator_peak.is_some_and(|peak| peak > 0));
assert!(compiled.measured.elapsed < DEADLINE);
if cfg!(any(target_os = "macos", target_os = "linux")) {
assert!(compiled.measured.peak_resident_bytes.is_some());
}
let process_peak = compiled.measured.allocator_peak_bytes;
assert!(process_peak.is_some_and(|peak| peak >= compiled.allocator_peak.unwrap()));
}
/// A compile worker that never answers is stopped at the 20-second deadline, measured, and
/// reported as a `timeout`.
#[cfg(unix)]
@@ -11,8 +11,6 @@
//! installs the worker's counting allocator and runs one test, so no other test thread allocates
//! while a compile is measured and the allocator peak is exactly the compile's.
use std::path::Path;
use metal2vulkan::Budget;
use metal2vulkan_air::budget::Meter;
use metal2vulkan_devtools::{engine_dir, llvm_assemble, AssembleError};
@@ -25,7 +23,7 @@ pub const SHARDS: usize = 6;
/// Shard `shard` of the check: the sorted owned fixtures whose index is `shard` modulo
/// [`SHARDS`]. Every shard's binary must exist, so no fixture goes unchecked.
pub fn ledger_covers_the_allocator_peak_of_every_owned_fixture_compile(shard: usize) {
let tests = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests");
let tests = metal2vulkan_devtools::validation_dir().join("tests");
for k in 0..=SHARDS {
let binary = tests.join(format!("ledger_coverage_{k}.rs"));
assert_eq!(
@@ -61,7 +61,7 @@ fn declared_modules(file: &Path, text: &str, is_root: bool) -> Vec<PathBuf> {
#[test]
fn a_binary_without_a_test_harness_holds_no_test() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let root = metal2vulkan_devtools::validation_dir();
let manifest = std::fs::read_to_string(root.join("Cargo.toml")).unwrap();
let (mut binaries, mut offenders) = (0, Vec::new());
for table in manifest.split("\n[[bin]]\n").skip(1) {
@@ -20,7 +20,6 @@
//! both directions.
use std::collections::BTreeSet;
use std::path::Path;
use metal2vulkan_validation::case::AuthoredCase;
use metal2vulkan_validation::check::check_case;
@@ -28,7 +27,7 @@ use metal2vulkan_validation::source::{check_public_source, public_source_set};
use metal2vulkan_validation::store::CorpusStore;
fn committed_cases() -> Vec<AuthoredCase> {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
CorpusStore::new(&root)
.read_all_cases()
.expect("committed cases")
@@ -76,7 +75,7 @@ fn every_public_case_names_its_fixture_and_the_fixture_is_its_air() {
#[test]
fn every_committed_public_case_passes_the_checker() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let public = public_source_set().expect("public fixtures");
let modules = public
.rows
@@ -10,14 +10,12 @@
//! MoltenVK shards. Byte-level canonical form is not part of this check: rows of executor v34 still
//! carry the legacy `containment.device_addresses` field that a rewrite drops.
use std::path::Path;
use metal2vulkan_validation::observation::Backend;
use metal2vulkan_validation::store::CorpusStore;
#[test]
fn committed_shards_keep_the_store_layout() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let errors = store.layout_errors().expect("read the committed shards");
assert!(
@@ -55,7 +53,7 @@ fn committed_shards_keep_the_store_layout() {
/// of it were recorded on another branch).
#[test]
fn every_committed_observation_and_refusal_names_a_committed_case() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let mut errors = Vec::new();
if let Err(error) = store.read_metal() {
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output};
fn repo() -> PathBuf {
fs::canonicalize(Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")).unwrap()
fs::canonicalize(metal2vulkan_devtools::workspace_dir()).unwrap()
}
#[cfg(unix)]
@@ -20,7 +20,6 @@
//! accepted near-equivalent does not hold on that venue.
use std::collections::{BTreeMap, BTreeSet};
use std::path::Path;
use base64::Engine as _;
use metal2vulkan::device::DeviceProfile;
@@ -86,7 +85,7 @@ fn lanes() -> Vec<BoundedLane> {
#[test]
fn fast_trig_differs_from_metal_only_within_apples_bound_or_where_it_states_none() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus");
let root = metal2vulkan_devtools::validation_dir().join("corpus");
let store = CorpusStore::new(&root);
let case = store
.find_case(FAST_PROBE)
@@ -29,7 +29,7 @@ use metal2vulkan_validation::ScratchDir;
const REQUIRE: &str = "METAL2VULKAN_TEST_REQUIRE_PINNED_LLVM";
fn fixtures_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures")
metal2vulkan_devtools::validation_dir().join("fixtures")
}
/// The LLVM major `public/engine/TOOLCHAIN` pins (`llvm: <major> (...)`).
@@ -16,7 +16,7 @@ const PRIVATE_VOLUME: &str = "m2v-linux-gate-test-arm64-private";
const PRIVATE_DEST: &str = "/work/m2v/crates/metal2vulkan-validation/corpus/local";
fn repo() -> PathBuf {
fs::canonicalize(Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")).unwrap()
fs::canonicalize(metal2vulkan_devtools::workspace_dir()).unwrap()
}
/// A synthetic layout: a main checkout holding a linked worktree (the checkout), a private
@@ -16,7 +16,7 @@ use std::path::{Path, PathBuf};
/// The repository root.
fn root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("../..")
metal2vulkan_devtools::workspace_dir()
}
/// The table's rows, by column name.
@@ -65,8 +65,8 @@ fn walk(root: &Path, dir: &Path, descend: bool, found: &mut Vec<PathBuf>) {
#[test]
fn no_conflict_markers_in_the_tree() {
let root = fs::canonicalize(Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."))
.expect("the repository's root");
let root =
fs::canonicalize(metal2vulkan_devtools::workspace_dir()).expect("the repository's root");
let markers = markers();
let mut files = Vec::new();
walk(&root, &root, false, &mut files);
@@ -44,7 +44,7 @@ fn tools_read_this_checkouts_tracked_shards_and_another_roots_private_sources()
private.air_sha256 = sha256_bytes(private.air_ll.as_bytes());
private.label = "private/source".into();
write_source_shards(&other, [private.clone()]).unwrap();
let committed = Path::new(env!("CARGO_MANIFEST_DIR")).join("corpus/cases");
let committed = metal2vulkan_devtools::validation_dir().join("corpus/cases");
let (shard, line) = fs::read_dir(&committed)
.unwrap()
.map(|entry| entry.unwrap().path())
@@ -52,7 +52,7 @@ fn license_files(dir: &Path) -> Vec<String> {
#[test]
fn every_published_crate_carries_the_repository_license() {
let crates = Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
let crates = metal2vulkan_devtools::workspace_dir().join("crates");
let root = crates.join("..");
assert_eq!(
license_files(&root),
@@ -89,7 +89,7 @@ fn every_published_crate_carries_the_repository_license() {
#[test]
fn the_license_notice_names_the_declared_license_and_its_texts() {
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
let root = metal2vulkan_devtools::workspace_dir();
let manifest = fs::read_to_string(root.join("Cargo.toml")).expect("the workspace's manifest");
let declared = manifest
.lines()