Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Wizer: rust regex test working as a component (#13167)

Pat Hickeyeca0416625bd
diff --git a/Cargo.lock b/Cargo.lock
index c4ba2b5600..41872111d2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3205,13 +3205,6 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
-[[package]]
-name = "regex-test"
-version = "0.1.0"
-dependencies = [
- "regex",
-]
-
[[package]]
name = "region"
version = "3.0.2"
@@ -3805,6 +3798,7 @@ dependencies = [
"log",
"once_cell",
"pin-project-lite",
+ "regex",
"sha2",
"url",
"wasi-nn",
@@ -5423,6 +5417,7 @@ dependencies = [
"env_logger 0.11.5",
"log",
"rayon",
+ "test-programs-artifacts",
"tokio",
"wasm-encoder 0.247.0",
"wasmparser 0.247.0",
diff --git a/Cargo.toml b/Cargo.toml
index 7ae32c8c6a..f97497bac3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -171,7 +171,6 @@ members = [
"crates/gdbstub-component",
"crates/gdbstub-component/artifact",
"crates/wizer/fuzz",
- "crates/wizer/tests/regex-test",
"crates/wizer/benches/regex-bench",
"crates/wizer/benches/uap-bench",
"examples/fib-debug/wasm",
diff --git a/crates/test-programs/Cargo.toml b/crates/test-programs/Cargo.toml
index b9ac602ff4..5201041e08 100644
--- a/crates/test-programs/Cargo.toml
+++ b/crates/test-programs/Cargo.toml
@@ -26,4 +26,5 @@ flate2 = "1.0.28"
log = { workspace = true }
env_logger = { workspace = true }
pin-project-lite = { workspace = true }
+regex = { workspace = true }
diff --git a/crates/test-programs/artifacts/build.rs b/crates/test-programs/artifacts/build.rs
index 37b632c941..1bb2f07616 100644
--- a/crates/test-programs/artifacts/build.rs
+++ b/crates/test-programs/artifacts/build.rs
@@ -105,6 +105,7 @@ impl Artifacts {
s if s.starts_with("keyvalue_") => "keyvalue",
s if s.starts_with("async_") => "async",
s if s.starts_with("fuzz_") => "fuzz",
+ s if s.starts_with("wizer_") => "wizer",
// If you're reading this because you hit this panic, either add
// it to a test suite above or add a new "suite". The purpose of
// the categorization above is to have a static assertion that
diff --git a/crates/test-programs/src/bin/wizer_regex.rs b/crates/test-programs/src/bin/wizer_regex.rs
new file mode 100644
index 0000000000..4783a4bb9f
--- /dev/null
+++ b/crates/test-programs/src/bin/wizer_regex.rs
@@ -0,0 +1,47 @@
+use regex::Regex;
+use std::sync::LazyLock;
+
+/// A regex that matches numbers that start with "1".
+static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^1\d*$").unwrap());
+
+// Component exports will have a name conflict with `wizer-initialize` and
+// `run`, so change the core module exports to have prefix `module-`.
+#[unsafe(export_name = "module-wizer-initialize")]
+pub fn init() {
+ LazyLock::force(&REGEX);
+}
+
+#[unsafe(export_name = "module-run")]
+pub fn run(n: i32) -> i32 {
+ let s = format!("{n}");
+ if REGEX.is_match(&s) { 42 } else { 0 }
+}
+
+/// Stub so that Cargo can build this test as a binary
+pub fn main() {
+ eprintln!("dont use as a command");
+ std::process::exit(-1)
+}
+
+wit_bindgen::generate!({
+ inline: "
+package local:local;
+world wizer-test {
+ export wizer-initialize: func();
+ export run: func(arg: s32) -> s32;
+}
+ ",
+ world: "wizer-test",
+});
+
+pub struct C;
+export!(C);
+
+impl Guest for C {
+ fn wizer_initialize() {
+ init()
+ }
+ fn run(arg: i32) -> i32 {
+ run(arg)
+ }
+}
diff --git a/crates/wizer/Cargo.toml b/crates/wizer/Cargo.toml
index 6858986804..c237a74352 100644
--- a/crates/wizer/Cargo.toml
+++ b/crates/wizer/Cargo.toml
@@ -41,6 +41,7 @@ wat = { workspace = true }
wasmtime = { workspace = true, features = ['default', 'anyhow'] }
wasmtime-wasi = { workspace = true, features = ["p1"] }
tokio = { workspace = true, features = ['macros'] }
+test-programs-artifacts = { workspace = true }
[features]
default = ["rayon"]
diff --git a/crates/wizer/tests/all/component.rs b/crates/wizer/tests/all/component.rs
index d4dc744a1a..98df09db4b 100644
--- a/crates/wizer/tests/all/component.rs
+++ b/crates/wizer/tests/all/component.rs
@@ -1,5 +1,6 @@
-use wasmtime::component::{Component, Instance, Linker, Val};
+use wasmtime::component::{Component, Instance, Linker, ResourceTable, Val};
use wasmtime::{Engine, Result, Store, ToWasmtimeResult as _, bail, error::Context as _};
+use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiCtxView, WasiView, p2};
use wasmtime_wizer::Wizer;
fn fail_wizening(msg: &str, wasm: &[u8]) -> Result<()> {
@@ -119,20 +120,41 @@ fn unsupported_constructs() -> Result<()> {
Ok(())
}
-fn store() -> Result<Store<()>> {
+struct Ctx {
+ wasi: WasiCtx,
+ table: ResourceTable,
+}
+impl WasiView for Ctx {
+ fn ctx(&mut self) -> WasiCtxView<'_> {
+ WasiCtxView {
+ ctx: &mut self.wasi,
+ table: &mut self.table,
+ }
+ }
+}
+
+fn store() -> Result<Store<Ctx>> {
let engine = Engine::default();
- Ok(Store::new(&engine, ()))
+ Ok(Store::new(
+ &engine,
+ Ctx {
+ wasi: WasiCtxBuilder::new().build(),
+ table: ResourceTable::new(),
+ },
+ ))
}
-async fn instantiate(store: &mut Store<()>, component: &Component) -> Result<Instance> {
+async fn instantiate(store: &mut Store<Ctx>, component: &Component) -> Result<Instance> {
let mut linker = Linker::new(store.engine());
- linker.define_unknown_imports_as_traps(component)?;
+ p2::add_to_linker_async(&mut linker)?;
+ linker.root().func_new("x", |_, _, _, _| -> Result<()> {
+ wasmtime::bail!("trapped in wizer import of `x`")
+ })?;
linker.instantiate_async(store, component).await
}
-async fn wizen(wat: &str) -> Result<Vec<u8>> {
+async fn wizen(wasm: &[u8]) -> Result<Vec<u8>> {
let _ = env_logger::try_init();
- let wasm = wat::parse_str(wat)?;
log::debug!(
"=== PreWizened Wasm ==========================================================\n\
@@ -157,14 +179,21 @@ async fn wizen(wat: &str) -> Result<Vec<u8>> {
Ok(wasm)
}
-async fn wizen_and_run_wasm(expected: u32, wat: &str) -> Result<()> {
- let wasm = wizen(wat).await?;
-
+async fn wizen_and_run_wat(expected: i32, wat: &str) -> Result<()> {
+ let wasm = wat::parse_str(wat)?;
+ let wasm = wizen(&wasm).await?;
+ run_wasm(0, expected, &wasm).await
+}
+async fn run_wasm(input: i32, expected: i32, wasm: &[u8]) -> Result<()> {
let mut store = store()?;
let module =
Component::new(store.engine(), wasm).context("Wasm test case failed to compile")?;
- let linker = Linker::new(store.engine());
+ let mut linker = Linker::new(store.engine());
+ p2::add_to_linker_async(&mut linker)?;
+ linker.root().func_new("x", |_, _, _, _| -> Result<()> {
+ wasmtime::bail!("trapped in runtime import of `x`")
+ })?;
let instance = linker.instantiate_async(&mut store, &module).await?;
let run = instance.get_func(&mut store, "run").ok_or_else(|| {
@@ -172,10 +201,11 @@ async fn wizen_and_run_wasm(expected: u32, wat: &str) -> Result<()> {
})?;
let mut actual = [Val::U8(0)];
- run.call_async(&mut store, &[], &mut actual).await?;
+ run.call_async(&mut store, &[Val::S32(input)], &mut actual)
+ .await?;
let actual = match actual[0] {
- Val::U32(x) => x,
- _ => wasmtime::bail!("expected an u32 result"),
+ Val::S32(x) => x,
+ _ => wasmtime::bail!("expected an s32 result"),
};
wasmtime::ensure!(
expected == actual,
@@ -187,18 +217,18 @@ async fn wizen_and_run_wasm(expected: u32, wat: &str) -> Result<()> {
#[tokio::test]
async fn simple() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
42,
r#"(component
(core module $m
(func (export "init"))
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 42
)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -209,16 +239,16 @@ async fn simple() -> Result<()> {
#[tokio::test]
async fn snapshot_global_i32() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
1,
r#"(component
(core module $m
(global $g (mut i32) i32.const 0)
(func (export "init") (global.set $g (i32.const 1)))
- (func (export "run") (result i32) global.get $g)
+ (func (export "run") (param i32) (result i32) global.get $g)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -229,19 +259,19 @@ async fn snapshot_global_i32() -> Result<()> {
#[tokio::test]
async fn snapshot_global_i64() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
1,
r#"(component
(core module $m
(global $g (mut i64) i64.const 0)
(func (export "init") (global.set $g (i64.const 1)))
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
global.get $g
i32.wrap_i64
)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -252,18 +282,18 @@ async fn snapshot_global_i64() -> Result<()> {
#[tokio::test]
async fn snapshot_global_f32() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
1,
r#"(component
(core module $m
(global $g (mut f32) f32.const 0)
(func (export "init") (global.set $g (f32.const 1)))
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
global.get $g
i32.trunc_f32_s)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -274,18 +304,18 @@ async fn snapshot_global_f32() -> Result<()> {
#[tokio::test]
async fn snapshot_global_f64() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
1,
r#"(component
(core module $m
(global $g (mut f64) f64.const 0)
(func (export "init") (global.set $g (f64.const 1)))
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
global.get $g
i32.trunc_f64_s)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -309,7 +339,7 @@ fn v128_globals() -> Result<()> {
#[tokio::test]
async fn snapshot_memory() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
201,
r#"(component
(core module $m
@@ -322,7 +352,7 @@ async fn snapshot_memory() -> Result<()> {
i32.const 101
i32.store
)
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 200
i32.load
i32.const 300
@@ -331,7 +361,7 @@ async fn snapshot_memory() -> Result<()> {
)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -342,7 +372,7 @@ async fn snapshot_memory() -> Result<()> {
#[tokio::test]
async fn nested_components() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
42,
r#"(component
(component $a)
@@ -366,10 +396,10 @@ async fn nested_components() -> Result<()> {
(core module $m
(func (export "init"))
- (func (export "run") (result i32) i32.const 42)
+ (func (export "run") (param i32) (result i32) i32.const 42)
)
(core instance $i (instantiate $m))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -380,7 +410,7 @@ async fn nested_components() -> Result<()> {
#[tokio::test]
async fn multiple_modules() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
100 + 101 + 200 + 201 + 7 + 112,
r#"(component
(core module $a
@@ -396,7 +426,7 @@ async fn multiple_modules() -> Result<()> {
i32.store
)
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 200
i32.load
i32.const 300
@@ -411,7 +441,7 @@ async fn multiple_modules() -> Result<()> {
(core module $b
(import "a" "g" (global $g (mut i32)))
(import "a" "init" (func $init))
- (import "a" "run" (func $run (result i32)))
+ (import "a" "run" (func $run (param i32) (result i32)))
(memory (export "mem") 1)
(func (export "init")
call $init
@@ -425,12 +455,13 @@ async fn multiple_modules() -> Result<()> {
i32.const 111
global.set $g
)
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 400
i32.load
i32.const 500
i32.load
i32.add
+ i32.const 0
call $run
i32.add
)
@@ -440,7 +471,7 @@ async fn multiple_modules() -> Result<()> {
(core module $c
(import "a" "g" (global $g (mut i32)))
(import "b" "init" (func $init))
- (import "b" "run" (func $run (result i32)))
+ (import "b" "run" (func $run (param i32) (result i32)))
(import "b" "mem" (memory 1))
(func (export "init")
@@ -461,9 +492,10 @@ async fn multiple_modules() -> Result<()> {
i32.const 112
global.set $g
)
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 65536
i32.load
+ i32.const 0
call $run
i32.add
)
@@ -473,7 +505,7 @@ async fn multiple_modules() -> Result<()> {
(with "b" (instance $b))
))
- (func (export "run") (result u32) (canon lift (core func $c "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $c "run")))
(func (export "wizer-initialize") (canon lift (core func $c "init")))
)"#,
)
@@ -484,7 +516,7 @@ async fn multiple_modules() -> Result<()> {
#[tokio::test]
async fn export_is_removed() -> Result<()> {
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -493,13 +525,13 @@ async fn export_is_removed() -> Result<()> {
(func $a (canon lift (core func $a "init")))
(export "wizer-initialize" (func $a))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert!(names.is_empty());
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -509,12 +541,12 @@ async fn export_is_removed() -> Result<()> {
(export "other" (func $a))
(export "wizer-initialize" (func $a))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other"]);
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -525,12 +557,12 @@ async fn export_is_removed() -> Result<()> {
(export "wizer-initialize" (func $a))
(export "other2" (func $a))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other1", "other2"]);
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -541,12 +573,12 @@ async fn export_is_removed() -> Result<()> {
(export "other2" (func $a))
(export "wizer-initialize" (func $a))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other1", "other2"]);
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -557,12 +589,12 @@ async fn export_is_removed() -> Result<()> {
(export "other1" (func $a))
(export "other2" (func $a))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other1", "other2"]);
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(core module $a
(func (export "init"))
@@ -573,12 +605,12 @@ async fn export_is_removed() -> Result<()> {
(export "wizer-initialize" (func $a))
(export "other2" (func $x))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other1", "other2"]);
- let wasm = wizen(
+ let wasm = wizen(&wat::parse_str(
r#"(component
(import "x" (func))
(core module $a
@@ -590,7 +622,7 @@ async fn export_is_removed() -> Result<()> {
(export "wizer-initialize" (func $a))
(export "other2" (func $x))
)"#,
- )
+ )?)
.await?;
let names = exports(&wasm);
assert_eq!(names, ["other1", "other2"]);
@@ -619,13 +651,13 @@ async fn export_is_removed() -> Result<()> {
// redundancy.
#[tokio::test]
async fn leave_wasip1_initialize() -> Result<()> {
- wizen_and_run_wasm(
+ wizen_and_run_wat(
42,
r#"(component
(core module $m
(func (export "init"))
- (func (export "run") (result i32)
+ (func (export "run") (param i32) (result i32)
i32.const 42
)
@@ -640,7 +672,7 @@ async fn leave_wasip1_initialize() -> Result<()> {
(core instance $shim (instantiate $shim (with "" (instance
(export "_initialize" (func $initialize))
))))
- (func (export "run") (result u32) (canon lift (core func $i "run")))
+ (func (export "run") (param "arg" s32) (result s32) (canon lift (core func $i "run")))
(func (export "wizer-initialize") (canon lift (core func $i "init")))
)"#,
)
@@ -648,3 +680,25 @@ async fn leave_wasip1_initialize() -> Result<()> {
Ok(())
}
+
+#[tokio::test]
+async fn rust_regex() -> Result<()> {
+ let _ = env_logger::try_init();
+ let component = test_programs_artifacts::wizer_regex_component_bytes!();
+
+ // FIXME(#13186) Rather than using the `wizen` helper function, we use
+ // Wizer directly here because, currently, this test is broken if
+ // `keep_init_func(true)` is not set.
+ let mut store = store()?;
+ let wizened_component = Wizer::new()
+ .keep_init_func(true)
+ .run_component(&mut store, component, instantiate)
+ .await
+ .context("Wizer::run_component")?;
+
+ run_wasm(1, 42, &wizened_component)
+ .await
+ .context("run_wasm")?;
+
+ Ok(())
+}
diff --git a/crates/wizer/tests/all/tests.rs b/crates/wizer/tests/all/tests.rs
index a0fe6d9715..b4942932b4 100644
--- a/crates/wizer/tests/all/tests.rs
+++ b/crates/wizer/tests/all/tests.rs
@@ -1,4 +1,3 @@
-use std::process::Command;
use wasm_encoder::ConstExpr;
use wasmtime::{
Config, Engine, Instance, Linker, Module, Result, Store, ToWasmtimeResult as _,
@@ -11,7 +10,7 @@ use wat::parse_str as wat_to_wasm;
async fn run_wat(args: &[wasmtime::Val], expected: i32, wat: &str) -> Result<()> {
let _ = env_logger::try_init();
let wasm = wat_to_wasm(wat)?;
- wizen_and_run_wasm(args, expected, &wasm, get_wizer()).await
+ wizen_and_run_wasm("run", args, expected, &wasm, get_wizer()).await
}
fn get_wizer() -> Wizer {
@@ -34,6 +33,7 @@ async fn instantiate(store: &mut Store<p1::WasiP1Ctx>, module: &Module) -> Resul
}
async fn wizen_and_run_wasm(
+ export_name: &str,
args: &[wasmtime::Val],
expected: i32,
wasm: &[u8],
@@ -74,8 +74,8 @@ async fn wizen_and_run_wasm(
let instance = linker.instantiate_async(&mut store, &module).await?;
- let run = instance.get_func(&mut store, "run").ok_or_else(|| {
- wasmtime::format_err!("the test Wasm module does not export a `run` function")
+ let run = instance.get_func(&mut store, export_name).ok_or_else(|| {
+ wasmtime::format_err!("the test Wasm module does not export a `{export_name}` function")
})?;
let mut actual = vec![wasmtime::Val::I32(0)];
@@ -271,7 +271,7 @@ async fn reject_table_get_set() -> Result<()> {
let _ = env_logger::try_init();
let wizer = Wizer::new();
let wasm = wat_to_wasm(wat)?;
- let result = wizen_and_run_wasm(&[], 42, &wasm, wizer).await;
+ let result = wizen_and_run_wasm("", &[], 42, &wasm, wizer).await;
assert!(result.is_err());
@@ -336,7 +336,7 @@ async fn reject_table_grow_with_reference_types_enabled() -> wasmtime::Result<()
let _ = env_logger::try_init();
let wizer = Wizer::new();
let wasm = wat_to_wasm(wat)?;
- let result = wizen_and_run_wasm(&[], 42, &wasm, wizer).await;
+ let result = wizen_and_run_wasm("", &[], 42, &wasm, wizer).await;
assert!(result.is_err());
@@ -351,7 +351,10 @@ async fn reject_table_grow_with_reference_types_enabled() -> wasmtime::Result<()
#[tokio::test]
async fn indirect_call_with_reference_types() -> wasmtime::Result<()> {
- let wat = r#"
+ run_wat(
+ &[],
+ 42,
+ r#"
(module
(type $sig (func (result i32)))
(table 0 funcref)
@@ -365,12 +368,9 @@ async fn indirect_call_with_reference_types() -> wasmtime::Result<()> {
i32.const 0
call_indirect $table1 (type $sig)
)
- )"#;
-
- let _ = env_logger::try_init();
- let wizer = Wizer::new();
- let wasm = wat_to_wasm(wat)?;
- wizen_and_run_wasm(&[], 42, &wasm, wizer).await
+ )"#,
+ )
+ .await
}
#[tokio::test]
@@ -469,20 +469,17 @@ async fn reject_data_drop() -> Result<()> {
#[tokio::test]
async fn rust_regex() -> Result<()> {
- let status = Command::new("cargo")
- .args(&["build", "--target=wasm32-wasip1", "-q"])
- .current_dir("./tests/regex-test")
- .env_remove("CARGO_ENCODED_RUSTFLAGS")
- .env_remove("RUSTFLAGS")
- .status()
- .expect("failed to build regex test case");
- assert!(status.success());
+ // The same test-program binary is run as both a module and a component,
+ // but the module exports need to be munged with the module- prefix in
+ // order to not conflict with the component exports.
+ let mut wizer = get_wizer();
+ wizer.init_func("module-wizer-initialize");
wizen_and_run_wasm(
+ "module-run",
&[wasmtime::Val::I32(13)],
42,
- &std::fs::read("../../target/wasm32-wasip1/debug/regex_test.wasm")
- .expect("failed to read regex test case"),
- get_wizer(),
+ test_programs_artifacts::wizer_regex_bytes!(),
+ wizer,
)
.await
}
@@ -649,7 +646,7 @@ async fn wasi_reactor_initializer_as_init_func() -> wasmtime::Result<()> {
wizer.init_func("_initialize");
let wasm = wat_to_wasm(wat)?;
// we expect `_initialize` to be called _exactly_ once
- wizen_and_run_wasm(&[], 1, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 1, &wasm, wizer).await
}
#[tokio::test]
@@ -674,7 +671,7 @@ async fn wasi_reactor_initializer_with_keep_init() -> wasmtime::Result<()> {
wizer.keep_init_func(true);
let wasm = wat_to_wasm(wat)?;
// we expect `_initialize` to be un-exported and not called at run
- wizen_and_run_wasm(&[], 2, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 2, &wasm, wizer).await
}
#[tokio::test]
@@ -788,7 +785,7 @@ async fn accept_bulk_memory_data_count() -> Result<()> {
data.active(0, &ConstExpr::i32_const(4), vec![5, 6, 7, 8]);
module.section(&data);
- wizen_and_run_wasm(&[], 42, &module.finish(), get_wizer())
+ wizen_and_run_wasm("run", &[], 42, &module.finish(), get_wizer())
.await
.unwrap();
Ok(())
@@ -889,7 +886,7 @@ async fn relaxed_simd_deterministic() -> Result<()> {
// We'll get 0x4b000003 if we have the deterministic `relaxed_madd`
// semantics. We might get 0x4b000002 if we don't.
- wizen_and_run_wasm(&[], 0x4b800003, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 0x4b800003, &wasm, wizer).await
}
#[tokio::test]
@@ -949,7 +946,7 @@ async fn mixture_of_globals() -> Result<()> {
"#,
)?;
let wizer = get_wizer();
- wizen_and_run_wasm(&[], 42 + 2 + 43 + 4, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 42 + 2 + 43 + 4, &wasm, wizer).await
}
#[tokio::test]
@@ -991,7 +988,7 @@ async fn memory_init_and_data_segments() -> Result<()> {
"#,
)?;
let wizer = get_wizer();
- wizen_and_run_wasm(&[], 0x02010403 + 0x06050201, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 0x02010403 + 0x06050201, &wasm, wizer).await
}
#[tokio::test]
@@ -1016,5 +1013,5 @@ async fn memory64() -> Result<()> {
"#,
)?;
let wizer = get_wizer();
- wizen_and_run_wasm(&[], 10, &wasm, wizer).await
+ wizen_and_run_wasm("run", &[], 10, &wasm, wizer).await
}
diff --git a/crates/wizer/tests/regex-test/Cargo.toml b/crates/wizer/tests/regex-test/Cargo.toml
deleted file mode 100644
index a795ce458a..0000000000
--- a/crates/wizer/tests/regex-test/Cargo.toml
+++ /dev/null
@@ -1,16 +0,0 @@
-[package]
-name = "regex-test"
-version = "0.1.0"
-publish = false
-authors.workspace = true
-edition.workspace = true
-rust-version.workspace = true
-
-[lib]
-crate-type = ["cdylib"]
-
-[lints]
-workspace = true
-
-[dependencies]
-regex = { workspace = true }
diff --git a/crates/wizer/tests/regex-test/README.md b/crates/wizer/tests/regex-test/README.md
deleted file mode 100644
index 103b4d203c..0000000000
--- a/crates/wizer/tests/regex-test/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-Source code used to create `/wizer/tests/regex_test.wasm`.
-
-Rebuild with:
-
-```
-$ cargo build --release --target wasm32-wasi -p regex-test
-$ cp target/wasm32-wasi/release/regex_test.wasm tests/regex_test.wasm
-```
diff --git a/crates/wizer/tests/regex-test/src/lib.rs b/crates/wizer/tests/regex-test/src/lib.rs
deleted file mode 100644
index 4329389825..0000000000
--- a/crates/wizer/tests/regex-test/src/lib.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-use regex::Regex;
-use std::sync::LazyLock;
-
-/// A regex that matches numbers that start with "1".
-static REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^1\d*$").unwrap());
-
-#[unsafe(export_name = "wizer-initialize")]
-pub fn init() {
- LazyLock::force(&REGEX);
-}
-
-#[unsafe(no_mangle)]
-pub fn run(n: i32) -> i32 {
- let s = format!("{n}");
- if REGEX.is_match(&s) { 42 } else { 0 }
-}