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