#[path = "../../tensor/tests/support/outcome.rs"]
#[allow(dead_code)]
mod outcome;
#[allow(unused_imports)]
pub(crate) use outcome::{allocated, current_test, report_skip, Expect};
#[path = "../../tensor/tests/support/dma_require.rs"]
#[allow(dead_code)]
mod dma_require;
pub(crate) fn is_dma_available() -> bool {
dma_require::decide(
edgefirst_tensor::is_dma_available(),
dma_require::required(),
¤t_test(),
"no usable DMA heap (no /dev/dma_heap node, or it is not openable by this user)",
)
}
#[cfg_attr(not(feature = "opengl"), allow(dead_code))]
pub(crate) fn is_gpu_buffer_available() -> bool {
#[cfg(target_os = "linux")]
return is_dma_available();
#[cfg(not(target_os = "linux"))]
edgefirst_tensor::is_gpu_buffer_available()
}
pub(crate) fn dma_allocated<T, E: std::fmt::Debug>(result: Result<T, E>, what: &str) -> Option<T> {
match result {
Ok(value) => Some(value),
Err(e) => allocated(Err(e), what, outcome::expect_dma(is_dma_available())),
}
}
#[cfg_attr(not(feature = "opengl"), allow(dead_code))]
pub(crate) fn gpu_buffer_allocated<T, E: std::fmt::Debug>(
result: Result<T, E>,
what: &str,
) -> Option<T> {
match result {
Ok(value) => Some(value),
Err(e) => {
let expect = if is_gpu_buffer_available() {
Expect::Succeeds
} else {
Expect::MayFail("no zero-copy GPU buffer backing on this host")
};
allocated(Err(e), what, expect)
}
}
}
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
pub(crate) fn g2d_required_or(available: bool) -> bool {
let required = std::env::var("HAL_TEST_REQUIRE_G2D").as_deref() == Ok("1");
g2d_decide(available, required, ¤t_test())
}
fn g2d_decide(available: bool, required: bool, what: &str) -> bool {
assert!(
available || !required,
"HAL_TEST_REQUIRE_G2D=1 but {what} would have skipped while reporting success: \
libg2d.so.2 did not load or G2D failed to initialize"
);
available
}
#[test]
fn g2d_policy_skips_unless_required() {
assert!(g2d_decide(true, true, "t"));
assert!(g2d_decide(true, false, "t"));
assert!(!g2d_decide(false, false, "t"));
let required_but_missing = std::panic::catch_unwind(|| g2d_decide(false, true, "t"));
assert!(required_but_missing.is_err());
}