From 118a3ff2d93dff9620b5afdc4f24be86fbe6afa9 Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Wed, 27 Sep 2023 22:18:28 +0100 Subject: [PATCH] move test functionality to the main crate behind a feature flag Signed-off-by: Jorge Prendes --- Cargo.lock | 8 +++----- Cargo.toml | 5 +++-- Makefile | 10 +++++----- .../Cargo.toml | 5 ++--- .../build.rs | 0 .../src/lib.rs} | 0 .../src/modules/custom_entrypoint.wat | 0 .../src/modules/exit_code.wat | 0 .../src/modules/has_default_devices.rs | 0 .../src/modules/hello_world.wat | 0 .../src/modules/seccomp.rs | 0 .../src/modules/unreachable.wat | 0 crates/containerd-shim-wasm/Cargo.toml | 10 ++++++++-- crates/containerd-shim-wasm/src/lib.rs | 3 +++ .../lib.rs => containerd-shim-wasm/src/testing.rs} | 13 ++++--------- crates/containerd-shim-wasmedge/Cargo.toml | 2 +- crates/containerd-shim-wasmedge/src/tests.rs | 4 ++-- crates/containerd-shim-wasmer/Cargo.toml | 2 +- crates/containerd-shim-wasmer/src/tests.rs | 4 ++-- crates/containerd-shim-wasmtime/Cargo.toml | 2 +- crates/containerd-shim-wasmtime/src/tests.rs | 4 ++-- 21 files changed, 37 insertions(+), 35 deletions(-) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/Cargo.toml (74%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/build.rs (100%) rename crates/{containerd-shim-wasm-test/src/modules.rs => containerd-shim-wasm-test-modules/src/lib.rs} (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/custom_entrypoint.wat (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/exit_code.wat (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/has_default_devices.rs (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/hello_world.wat (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/seccomp.rs (100%) rename crates/{containerd-shim-wasm-test => containerd-shim-wasm-test-modules}/src/modules/unreachable.wat (100%) rename crates/{containerd-shim-wasm-test/src/lib.rs => containerd-shim-wasm/src/testing.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index 7550ad1f4..9ca4afde0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,8 +556,10 @@ dependencies = [ "caps", "chrono", "containerd-shim", + "containerd-shim-wasm-test-modules", "crossbeam", "dbus", + "env_logger", "git-version", "libc", "libcontainer", @@ -576,11 +578,10 @@ dependencies = [ ] [[package]] -name = "containerd-shim-wasm-test" +name = "containerd-shim-wasm-test-modules" version = "0.2.0" dependencies = [ "anyhow", - "containerd-shim-wasm", "env_logger", "lazy_static", "libc", @@ -598,7 +599,6 @@ dependencies = [ "anyhow", "containerd-shim", "containerd-shim-wasm", - "containerd-shim-wasm-test", "libc", "log", "oci-spec", @@ -615,7 +615,6 @@ dependencies = [ "anyhow", "containerd-shim", "containerd-shim-wasm", - "containerd-shim-wasm-test", "log", "oci-spec", "serial_test", @@ -633,7 +632,6 @@ dependencies = [ "anyhow", "containerd-shim", "containerd-shim-wasm", - "containerd-shim-wasm-test", "log", "oci-spec", "serial_test", diff --git a/Cargo.toml b/Cargo.toml index 0be2dd2f7..098c81690 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = [ "crates/containerd-shim-wasm", - "crates/containerd-shim-wasm-test", + "crates/containerd-shim-wasm-test-modules", "crates/wasi-demo-app", "crates/oci-tar-builder", "crates/containerd-shim-wasmedge", @@ -24,7 +24,7 @@ cap-std = "1.0" chrono = { version = "0.4", default-features = false, features = ["clock"] } containerd-shim = "0.5.0" containerd-shim-wasm = { path = "crates/containerd-shim-wasm" } -containerd-shim-wasm-test = { path = "crates/containerd-shim-wasm-test" } +containerd-shim-wasm-test-modules = { path = "crates/containerd-shim-wasm-test-modules" } crossbeam = { version = "0.8.2", default-features = false } env_logger = "0.10" libc = "0.2.147" @@ -36,6 +36,7 @@ serde = "1.0" serde_json = "1.0" sha256 = "1.4.0" tar = "0.4" +tempfile = "3.8" thiserror = "1.0" ttrpc = "0.8.0" wat = "*" # Use whatever version wasmtime will make us pull diff --git a/Makefile b/Makefile index 03d836e93..cf2bedea4 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ check: check-wasm $(RUNTIMES:%=check-%); check-common: check-wasm; check-wasm: - $(CARGO) +nightly fmt $(TARGET_FLAG) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test -- --check - $(CARGO) clippy $(TARGET_FLAG) $(FEATURES_wasm) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test -- $(WARNINGS) + $(CARGO) +nightly fmt $(TARGET_FLAG) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test-modules -- --check + $(CARGO) clippy $(TARGET_FLAG) $(FEATURES_wasm) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test-modules -- $(WARNINGS) check-%: $(CARGO) +nightly fmt $(TARGET_FLAG) -p containerd-shim-$* -- --check @@ -59,8 +59,8 @@ fix: fix-wasm $(RUNTIMES:%=fix-%); fix-common: fix-wasm; fix-wasm: - $(CARGO) +nightly fmt $(TARGET_FLAG) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test - $(CARGO) clippy $(TARGET_FLAG) $(FEATURES_wasm) --fix -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test -- $(WARNINGS) + $(CARGO) +nightly fmt $(TARGET_FLAG) -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test-modules + $(CARGO) clippy $(TARGET_FLAG) $(FEATURES_wasm) --fix -p oci-tar-builder -p wasi-demo-app -p containerd-shim-wasm -p containerd-shim-wasm-test-modules -- $(WARNINGS) fix-%: $(CARGO) +nightly fmt $(TARGET_FLAG) -p containerd-shim-$* @@ -72,7 +72,7 @@ test: test-wasm $(RUNTIMES:%=test-%); test-common: test-wasm; test-wasm: # oci-tar-builder and wasi-demo-app have no tests - RUST_LOG=trace $(CARGO) test $(TARGET_FLAG) --package containerd-shim-wasm $(FEATURES_wasm) --verbose -- --nocapture + RUST_LOG=trace $(CARGO) test $(TARGET_FLAG) --package containerd-shim-wasm $(FEATURES_wasm) --verbose -- --nocapture --test-threads=1 test-wasmedge: # run tests in one thread to prevent paralellism diff --git a/crates/containerd-shim-wasm-test/Cargo.toml b/crates/containerd-shim-wasm-test-modules/Cargo.toml similarity index 74% rename from crates/containerd-shim-wasm-test/Cargo.toml rename to crates/containerd-shim-wasm-test-modules/Cargo.toml index dec58651e..b8abbee03 100644 --- a/crates/containerd-shim-wasm-test/Cargo.toml +++ b/crates/containerd-shim-wasm-test-modules/Cargo.toml @@ -1,13 +1,12 @@ [package] -name = "containerd-shim-wasm-test" -description = "Library for testing containerd shims for wasm" +name = "containerd-shim-wasm-test-modules" +description = "Set of WebAssembly modules for testing containerd shims for wasm" version.workspace = true edition.workspace = true license.workspace = true [dependencies] anyhow = { workspace = true } -containerd-shim-wasm = { workspace = true } env_logger = "0.10" libc = { workspace = true } log = { workspace = true } diff --git a/crates/containerd-shim-wasm-test/build.rs b/crates/containerd-shim-wasm-test-modules/build.rs similarity index 100% rename from crates/containerd-shim-wasm-test/build.rs rename to crates/containerd-shim-wasm-test-modules/build.rs diff --git a/crates/containerd-shim-wasm-test/src/modules.rs b/crates/containerd-shim-wasm-test-modules/src/lib.rs similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules.rs rename to crates/containerd-shim-wasm-test-modules/src/lib.rs diff --git a/crates/containerd-shim-wasm-test/src/modules/custom_entrypoint.wat b/crates/containerd-shim-wasm-test-modules/src/modules/custom_entrypoint.wat similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/custom_entrypoint.wat rename to crates/containerd-shim-wasm-test-modules/src/modules/custom_entrypoint.wat diff --git a/crates/containerd-shim-wasm-test/src/modules/exit_code.wat b/crates/containerd-shim-wasm-test-modules/src/modules/exit_code.wat similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/exit_code.wat rename to crates/containerd-shim-wasm-test-modules/src/modules/exit_code.wat diff --git a/crates/containerd-shim-wasm-test/src/modules/has_default_devices.rs b/crates/containerd-shim-wasm-test-modules/src/modules/has_default_devices.rs similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/has_default_devices.rs rename to crates/containerd-shim-wasm-test-modules/src/modules/has_default_devices.rs diff --git a/crates/containerd-shim-wasm-test/src/modules/hello_world.wat b/crates/containerd-shim-wasm-test-modules/src/modules/hello_world.wat similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/hello_world.wat rename to crates/containerd-shim-wasm-test-modules/src/modules/hello_world.wat diff --git a/crates/containerd-shim-wasm-test/src/modules/seccomp.rs b/crates/containerd-shim-wasm-test-modules/src/modules/seccomp.rs similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/seccomp.rs rename to crates/containerd-shim-wasm-test-modules/src/modules/seccomp.rs diff --git a/crates/containerd-shim-wasm-test/src/modules/unreachable.wat b/crates/containerd-shim-wasm-test-modules/src/modules/unreachable.wat similarity index 100% rename from crates/containerd-shim-wasm-test/src/modules/unreachable.wat rename to crates/containerd-shim-wasm-test-modules/src/modules/unreachable.wat diff --git a/crates/containerd-shim-wasm/Cargo.toml b/crates/containerd-shim-wasm/Cargo.toml index 6cdea5181..f272e86a4 100644 --- a/crates/containerd-shim-wasm/Cargo.toml +++ b/crates/containerd-shim-wasm/Cargo.toml @@ -14,15 +14,18 @@ doctest = false [dependencies] anyhow = { workspace = true } chrono = { workspace = true } -git-version = "0.3.5" containerd-shim = { workspace = true } +containerd-shim-wasm-test-modules = { workspace = true, optional = true } crossbeam = { workspace = true } +env_logger = { workspace = true, optional = true } +git-version = "0.3.5" libc = { workspace = true } log = { workspace = true } oci-spec = { workspace = true } protobuf = "3.2" serde = { workspace = true } serde_json = { workspace = true } +tempfile = { workspace = true, optional = true } thiserror = { workspace = true } ttrpc = { workspace = true } wat = { workspace = true } @@ -40,8 +43,11 @@ windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Storage ttrpc-codegen = { version = "0.4.2", optional = true } [dev-dependencies] -tempfile = "3.8" +containerd-shim-wasm-test-modules = { workspace = true } +env_logger = { workspace = true } +tempfile = { workspace = true } [features] +testing = ["dep:containerd-shim-wasm-test-modules", "dep:env_logger", "dep:tempfile"] generate_bindings = ["ttrpc-codegen"] generate_doc = [] diff --git a/crates/containerd-shim-wasm/src/lib.rs b/crates/containerd-shim-wasm/src/lib.rs index 21238b842..a61a914f5 100644 --- a/crates/containerd-shim-wasm/src/lib.rs +++ b/crates/containerd-shim-wasm/src/lib.rs @@ -10,3 +10,6 @@ pub mod services; #[cfg_attr(unix, path = "sys/unix/mod.rs")] #[cfg_attr(windows, path = "sys/windows/mod.rs")] pub(crate) mod sys; + +#[cfg(any(test, feature = "testing"))] +pub mod testing; diff --git a/crates/containerd-shim-wasm-test/src/lib.rs b/crates/containerd-shim-wasm/src/testing.rs similarity index 96% rename from crates/containerd-shim-wasm-test/src/lib.rs rename to crates/containerd-shim-wasm/src/testing.rs index 169924e05..62a6e77e9 100644 --- a/crates/containerd-shim-wasm-test/src/lib.rs +++ b/crates/containerd-shim-wasm/src/testing.rs @@ -8,17 +8,12 @@ use std::sync::mpsc::channel; use std::time::Duration; use anyhow::{bail, Result}; -#[cfg(unix)] -use libc::SIGKILL; - -#[cfg(windows)] -const SIGKILL: i32 = 9; - -use containerd_shim_wasm::sandbox::instance::Wait; -use containerd_shim_wasm::sandbox::{Instance, InstanceConfig}; +pub use containerd_shim_wasm_test_modules as modules; use oci_spec::runtime::{ProcessBuilder, RootBuilder, SpecBuilder}; -pub mod modules; +use crate::sandbox::instance::Wait; +use crate::sandbox::{Instance, InstanceConfig}; +use crate::sys::signals::SIGKILL; pub struct WasiTestBuilder where diff --git a/crates/containerd-shim-wasmedge/Cargo.toml b/crates/containerd-shim-wasmedge/Cargo.toml index ebb224d64..53e32b76d 100644 --- a/crates/containerd-shim-wasmedge/Cargo.toml +++ b/crates/containerd-shim-wasmedge/Cargo.toml @@ -15,7 +15,7 @@ wasmedge-sdk = { version = "0.12.2" } wasmedge-sys = "*" [dev-dependencies] -containerd-shim-wasm-test = { workspace = true } +containerd-shim-wasm = { workspace = true, features = ["testing"] } libc = { workspace = true } serial_test = "*" diff --git a/crates/containerd-shim-wasmedge/src/tests.rs b/crates/containerd-shim-wasmedge/src/tests.rs index a290e95ae..61887e1ac 100644 --- a/crates/containerd-shim-wasmedge/src/tests.rs +++ b/crates/containerd-shim-wasmedge/src/tests.rs @@ -1,8 +1,8 @@ use std::time::Duration; //use containerd_shim_wasm::sandbox::Instance; -use containerd_shim_wasm_test::modules::*; -use containerd_shim_wasm_test::WasiTest; +use containerd_shim_wasm::testing::modules::*; +use containerd_shim_wasm::testing::WasiTest; use serial_test::serial; use crate::instance::WasmEdgeInstance as WasiInstance; diff --git a/crates/containerd-shim-wasmer/Cargo.toml b/crates/containerd-shim-wasmer/Cargo.toml index fbf11f02f..32a6230c7 100644 --- a/crates/containerd-shim-wasmer/Cargo.toml +++ b/crates/containerd-shim-wasmer/Cargo.toml @@ -17,7 +17,7 @@ wasmer-compiler = { version = "4.1.2", features = ["compiler"] } wasmer-wasix = { version = "0.12.0" } [dev-dependencies] -containerd-shim-wasm-test = { workspace = true } +containerd-shim-wasm = { workspace = true, features = ["testing"] } serial_test = "*" [[bin]] diff --git a/crates/containerd-shim-wasmer/src/tests.rs b/crates/containerd-shim-wasmer/src/tests.rs index c3ce8d2e4..15ee5b478 100644 --- a/crates/containerd-shim-wasmer/src/tests.rs +++ b/crates/containerd-shim-wasmer/src/tests.rs @@ -1,8 +1,8 @@ use std::time::Duration; //use containerd_shim_wasm::sandbox::Instance; -use containerd_shim_wasm_test::modules::*; -use containerd_shim_wasm_test::WasiTest; +use containerd_shim_wasm::testing::modules::*; +use containerd_shim_wasm::testing::WasiTest; use serial_test::serial; use crate::instance::WasmerInstance as WasiInstance; diff --git a/crates/containerd-shim-wasmtime/Cargo.toml b/crates/containerd-shim-wasmtime/Cargo.toml index b40f76755..06131e85f 100644 --- a/crates/containerd-shim-wasmtime/Cargo.toml +++ b/crates/containerd-shim-wasmtime/Cargo.toml @@ -29,7 +29,7 @@ wasmtime-wasi = { version = "11.0", features = ["exit"] } wasi-common = "11.0" [dev-dependencies] -containerd-shim-wasm-test = { workspace = true } +containerd-shim-wasm = { workspace = true, features = ["testing"] } serial_test = "*" [[bin]] diff --git a/crates/containerd-shim-wasmtime/src/tests.rs b/crates/containerd-shim-wasmtime/src/tests.rs index 27dbd70c8..e3ed046dd 100644 --- a/crates/containerd-shim-wasmtime/src/tests.rs +++ b/crates/containerd-shim-wasmtime/src/tests.rs @@ -1,8 +1,8 @@ use std::time::Duration; //use containerd_shim_wasm::sandbox::Instance; -use containerd_shim_wasm_test::modules::*; -use containerd_shim_wasm_test::WasiTest; +use containerd_shim_wasm::testing::modules::*; +use containerd_shim_wasm::testing::WasiTest; use serial_test::serial; use crate::instance::WasmtimeInstance as WasiInstance;