diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-09-11 22:48:12 +0200 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-09-11 22:48:12 +0200 |
| commit | c5f45ff56f7538944d92d5d318a01d10da04535c (patch) | |
| tree | 589c7c3af38c46441c798ce307c96acca637c314 /examples/wasm-rust.rs | |
| parent | 0ed6acf459ff941f3b20b3e7462e4ba1cf7fdbe5 (diff) | |
ci: improve no_std testing, add linux arm64
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'examples/wasm-rust.rs')
| -rw-r--r-- | examples/wasm-rust.rs | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index 169fed5..a9c7572 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -43,6 +43,7 @@ fn main() -> Result<()> { "printi32" => printi32()?, "fibonacci" => fibonacci()?, "tinywasm" => tinywasm()?, + "tinywasm_no_std" => tinywasm_no_std()?, "argon2id" => argon2id()?, "all" => { println!("Running all examples"); @@ -54,6 +55,8 @@ fn main() -> Result<()> { fibonacci()?; println!("\ntinywasm.wasm:"); tinywasm()?; + println!("\ntinywasm_no_std.wasm:"); + tinywasm_no_std()?; println!("argon2id.wasm:"); argon2id()?; } @@ -64,7 +67,22 @@ fn main() -> Result<()> { } fn tinywasm() -> Result<()> { - let module = Module::parse_file("./examples/rust/out/tinywasm.wasm")?; + let module = Module::parse_file("./examples/rust/out/tinywasm.opt.wasm")?; + let mut store = Store::default(); + + let mut imports = Imports::new(); + imports.define("env", "printi32", Extern::typed_func(|_: FuncContext<'_>, _x: i32| Ok(())))?; + let instance = module.instantiate(&mut store, Some(black_box(imports)))?; + + let hello = instance.exported_func::<(), ()>(&store, "hello")?; + hello.call(&mut store, black_box(()))?; + hello.call(&mut store, black_box(()))?; + hello.call(&mut store, black_box(()))?; + Ok(()) +} + +fn tinywasm_no_std() -> Result<()> { + let module = Module::parse_file("./examples/rust/out/tinywasm_no_std.opt.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -79,7 +97,7 @@ fn tinywasm() -> Result<()> { } fn hello() -> Result<()> { - let module = Module::parse_file("./examples/rust/out/hello.wasm")?; + let module = Module::parse_file("./examples/rust/out/hello.opt.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -108,7 +126,7 @@ fn hello() -> Result<()> { } fn printi32() -> Result<()> { - let module = Module::parse_file("./examples/rust/out/print.wasm")?; + let module = Module::parse_file("./examples/rust/out/print.opt.wasm")?; let mut store = Store::default(); let mut imports = Imports::new(); @@ -151,3 +169,38 @@ fn argon2id() -> Result<()> { Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_hello() { + hello().unwrap(); + } + + #[test] + fn test_printi32() { + printi32().unwrap(); + } + + #[test] + fn test_fibonacci() { + fibonacci().unwrap(); + } + + #[test] + fn test_tinywasm() { + tinywasm().unwrap(); + } + + #[test] + fn test_tinywasm_no_std() { + tinywasm_no_std().unwrap(); + } + + #[test] + fn test_argon2id() { + argon2id().unwrap(); + } +} |
