Path: blob/main/crates/wasi-nn/tests/check/mod.rs
1693 views
//! Check that the environment is set up correctly for running tests.1//!2//! This module checks:3//! - that various backends can be located on the system (see sub-modules)4//! - that certain ML model artifacts can be downloaded and cached.56use std::{7env,8path::{Path, PathBuf},9process::Command,10sync::Mutex,11};1213#[cfg(any(feature = "onnx", all(feature = "winml", target_os = "windows")))]14pub mod onnx;15#[cfg(feature = "openvino")]16pub mod openvino;17#[cfg(feature = "pytorch")]18pub mod pytorch;19#[cfg(all(feature = "winml", target_os = "windows"))]20pub mod winml;2122/// Protect `are_artifacts_available` from concurrent access; when running tests23/// in parallel, we want to avoid two threads attempting to create the same24/// directory or download the same file.25pub static DOWNLOAD_LOCK: Mutex<()> = Mutex::new(());2627/// Return the directory in which the test artifacts are stored.28pub fn artifacts_dir() -> PathBuf {29PathBuf::from(env!("OUT_DIR")).join("fixtures")30}3132/// Retrieve the bytes at the `from` URL and place them in the `to` file.33fn download(from: &str, to: &Path) -> anyhow::Result<()> {34let mut curl = Command::new("curl");35curl.arg("--location").arg(from).arg("--output").arg(to);36println!("> downloading: {:?}", &curl);37let result = curl.output().unwrap();38if !result.status.success() {39panic!(40"curl failed: {}\n{}",41result.status,42String::from_utf8_lossy(&result.stderr)43);44}45Ok(())46}474849