1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-FileCopyrightText: Copyright 2026 Au-Zone Technologies
// SPDX-License-Identifier: Apache-2.0
//! CUDA test policy for the D3D11 interop tests: a skip must not be able to
//! masquerade as coverage.
//!
//! `d3d11_tensor.rs`'s CUDA tests used to return early whenever
//! `edgefirst_tensor::is_cuda_available()` was false, printing
//! `SKIP: no CUDA runtime` and reporting `ok`. On an NVIDIA Windows box
//! whose runtime soname `cuda.rs`'s probe does not recognise (or that is
//! simply not on `PATH`/`CUDA_PATH\bin`), that is indistinguishable from
//! real coverage -- the same vacuity PR #168 closed on Linux for
//! `crates/image/src/gl/cuda_policy.rs`. `HAL_TEST_REQUIRE_CUDA=1` turns
//! that skip into a failure naming the test and the reason, and
//! `scripts/test-windows.ps1 -RequireCuda` sets it whenever an NVIDIA
//! adapter is present, so the lane cannot silently stop testing again.
//!
//! The WARP-adapter skip (`cudaD3D11GetDevice` has no ordinal for WARP) is
//! correct by design and does not go through this module. Its callers test
//! for it *before* calling in here, so an armed gate cannot turn that skip
//! into a failure -- see `d3d11_tensor.rs`'s `warp_has_no_cuda_device`.
//!
//! [`decide`] is the pure core, and it is `pub` so this module can be
//! `#[path]`-included by `crates/tensor/tests/cuda_require_policy.rs` as
//! well as by `d3d11_tensor.rs`. Integration tests are separate compilation
//! units, so that include is the sharing mechanism: the policy tests cover
//! the very function the Windows guard calls, on every lane -- the Linux
//! ones included, where `d3d11_tensor.rs` compiles to nothing -- rather
//! than a copy that could drift from it.
//! [`cuda_available_or_skip`] is the one env-reading, skip-reporting caller
//! `d3d11_tensor.rs` uses.
/// `true` when `HAL_TEST_REQUIRE_CUDA=1` is set -- the opt-in that turns a
/// quiet skip into a visible failure.
/// The pure decision: `true` when `satisfied`; otherwise a failure or a skip
/// depending on `require`. No environment access and no output -- the
/// caller reads `HAL_TEST_REQUIRE_CUDA` and passes the result in as
/// `require`, and reports the skip itself on a `false` return. That
/// purity is what lets `crates/tensor/tests/cuda_require_policy.rs` test
/// this exact function on hosts with no CUDA and no D3D11.
///
/// # Panics
///
/// When `require` is `true` and `satisfied` is `false` -- the opt-in that
/// turns "quietly skipped" into a visible failure. The panic message names
/// `HAL_TEST_REQUIRE_CUDA=1`, `what`, and `why`.
/// `true` when the caller should run; `false` when it should return early.
/// Reports `SKIPPED: {what} - {why}` on a `false` return.
///
/// The line is written straight to `std::io::stderr()`, not through
/// `eprintln!`. `eprintln!` routes via `std::io::_eprint`, which libtest
/// hooks for per-test output capture and replays only for a *failing*
/// test -- and a skip is a pass, so the reason was discarded exactly when
/// it mattered. The `SKIPPED:` prefix is the one `scripts/
/// on-target-test.sh` greps for to count skips per board, so the previous
/// `SKIP {what}:` spelling was invisible to it twice over. This is the
/// same rule (and the same wire format) as `edgefirst-image`'s
/// `test_support::report_skip`, written out here because an integration
/// test is its own compilation unit and cannot reach that crate-private
/// helper.
///
/// # Panics
///
/// When `HAL_TEST_REQUIRE_CUDA=1` and CUDA is unavailable -- see [`decide`].