Skip to content

Commit

Permalink
wasi-nn: add CLI tests
Browse files Browse the repository at this point in the history
These tests are Rust versions of what `ci/run-wasi-nn-example.sh`
executed. Now that all of the test-checking (ML backend? artifacts?) can
be done via Rust, the Bash script is no longer needed; this change
removes it.

This change also switches over CI to run all of the new wasi-nn tests by
modifying the `main.yml` workflow and the `ci/run-tests.sh` script.
  • Loading branch information
abrown committed Aug 23, 2023
1 parent 508b85d commit 970149e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 86 deletions.
33 changes: 6 additions & 27 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ jobs:
- run: echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
if: matrix.target != ''

# Install OpenVINO for testing wasmtime-wasi-nn.
- uses: abrown/install-openvino-action@v6
with:
version: 2022.3.0
apt: true

# Fix an ICE for now in gcc when compiling zstd with debuginfo (??)
- run: echo CFLAGS=-g0 >> $GITHUB_ENV
if: matrix.target == 'x86_64-pc-windows-gnu'
Expand Down Expand Up @@ -479,32 +485,6 @@ jobs:
# Windows fails GitHub Actions will confusingly mark the failed Windows job
# as cancelled instead of failed.

# Build and test the wasi-nn module.
test_wasi_nn:
needs: determine
if: needs.determine.outputs.run-full
name: Test wasi-nn module
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: ./.github/actions/install-rust
- run: rustup target add wasm32-wasi
- uses: abrown/install-openvino-action@v6
with:
version: 2022.3.0
apt: true
- run: ./ci/run-wasi-nn-example.sh
env:
RUST_BACKTRACE: 1

# common logic to cancel the entire run if this job fails
- run: gh run cancel ${{ github.run_id }}
if: failure() && github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ github.token }}

build-preview1-component-adapter:
name: Build wasi-preview1-component-adapter
needs: determine
Expand Down Expand Up @@ -752,7 +732,6 @@ jobs:
- checks
- checks_winarm64
- fuzz_targets
- test_wasi_nn
- bench
- meta_deterministic_check
- verify-publish
Expand Down
4 changes: 3 additions & 1 deletion ci/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ cargo test \
--features wasi-threads \
--features wasi-http \
--features component-model \
--features wasmtime-wasi-nn/test-check \
--workspace \
--exclude 'wasmtime-wasi-*' \
--exclude 'wasmtime-wasi-http' \
--exclude 'wasmtime-wasi-crypto' \
--exclude wasi-tests \
--exclude wasi-http-tests \
--exclude command-tests \
Expand Down
58 changes: 0 additions & 58 deletions ci/run-wasi-nn-example.sh

This file was deleted.

38 changes: 38 additions & 0 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,44 @@ fn run_simple_with_wasi_threads() -> Result<()> {
Ok(())
}

#[cfg(feature = "wasi-nn")]
#[test]
fn image_classification_with_wasi_nn() -> Result<()> {
wasmtime_wasi_nn::test_check!();
let wasm =
wasmtime_wasi_nn::test_check::cargo_build("crates/wasi-nn/examples/image-classification");
let artifacts_dir = wasmtime_wasi_nn::test_check::artifacts_dir();
let artifacts_dir = artifacts_dir.display();
let stdout = run_wasmtime(&[
"run",
"--wasi-modules=experimental-wasi-nn",
&format!("--mapdir=fixture::{artifacts_dir}"),
&format!("{}", wasm.display()),
])?;
assert!(stdout.contains("InferenceResult(963"));
Ok(())
}

#[cfg(feature = "wasi-nn")]
#[test]
fn image_classification_with_wasi_nn_and_named_models() -> Result<()> {
wasmtime_wasi_nn::test_check!();
let wasm = wasmtime_wasi_nn::test_check::cargo_build(
"crates/wasi-nn/examples/image-classification-named",
);
let artifacts_dir = wasmtime_wasi_nn::test_check::artifacts_dir();
let artifacts_dir = artifacts_dir.display();
let stdout = run_wasmtime(&[
"run",
"--wasi-modules=experimental-wasi-nn",
&format!("--mapdir=fixture::{artifacts_dir}"),
&format!("--wasi-nn-graph=openvino::{artifacts_dir}"),
&format!("{}", wasm.display()),
])?;
assert!(stdout.contains("InferenceResult(963"));
Ok(())
}

#[test]
fn wasm_flags() -> Result<()> {
// Any argument after the wasm module should be interpreted as for the
Expand Down

0 comments on commit 970149e

Please sign in to comment.