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
|
//! Check that the environment is set up correctly for running tests.
//!
//! This module checks:
//! - that various backends can be located on the system (see sub-modules)
//! - that certain ML model artifacts can be downloaded and cached.
#[allow(unused_imports)]
use anyhow::{anyhow, Context, Result};
use std::{
env,
path::{Path, PathBuf},
process::Command,
sync::Mutex,
};
#[cfg(any(feature = "onnx", feature = "winml"))]
pub mod onnx;
#[cfg(feature = "openvino")]
pub mod openvino;
#[cfg(all(feature = "winml", target_os = "windows"))]
pub mod winml;
/// Protect `are_artifacts_available` from concurrent access; when running tests
/// in parallel, we want to avoid two threads attempting to create the same
/// directory or download the same file.
pub static DOWNLOAD_LOCK: Mutex<()> = Mutex::new(());
/// Return the directory in which the test artifacts are stored.
pub fn artifacts_dir() -> PathBuf {
PathBuf::from(env!("OUT_DIR")).join("fixtures")
}
/// Retrieve the bytes at the `from` URL and place them in the `to` file.
fn download(from: &str, to: &Path) -> anyhow::Result<()> {
let mut curl = Command::new("curl");
curl.arg("--location").arg(from).arg("--output").arg(to);
println!("> downloading: {:?}", &curl);
let result = curl.output().unwrap();
if !result.status.success() {
panic!(
"curl failed: {}\n{}",
result.status,
String::from_utf8_lossy(&result.stderr)
);
}
Ok(())
}
|