mitoxide_wasm/
test_utils.rs1pub mod test_modules {
4 use std::sync::OnceLock;
5
6 fn generate_minimal_wasm() -> Vec<u8> {
8 wat::parse_str("(module)").unwrap()
9 }
10
11 fn generate_simple_function_wasm() -> Vec<u8> {
12 wat::parse_str(r#"
13 (module
14 (func $add (param i32 i32) (result i32)
15 local.get 0
16 local.get 1
17 i32.add)
18 (export "add" (func $add)))
19 "#).unwrap()
20 }
21
22 fn generate_wasi_hello_wasm() -> Vec<u8> {
23 wat::parse_str(r#"
24 (module
25 (import "wasi_snapshot_preview1" "fd_write"
26 (func $fd_write (param i32 i32 i32 i32) (result i32)))
27 (import "wasi_snapshot_preview1" "environ_get"
28 (func $environ_get (param i32 i32) (result i32)))
29 (func $_start
30 nop)
31 (export "_start" (func $_start))
32 (memory 1)
33 (export "memory" (memory 0)))
34 "#).unwrap()
35 }
36
37 static MINIMAL_WASM: OnceLock<Vec<u8>> = OnceLock::new();
39 static SIMPLE_FUNCTION_WASM: OnceLock<Vec<u8>> = OnceLock::new();
40 static WASI_HELLO_WASM: OnceLock<Vec<u8>> = OnceLock::new();
41
42 pub fn minimal_wasm() -> &'static [u8] {
44 MINIMAL_WASM.get_or_init(generate_minimal_wasm)
45 }
46
47 pub fn simple_function_wasm() -> &'static [u8] {
49 SIMPLE_FUNCTION_WASM.get_or_init(generate_simple_function_wasm)
50 }
51
52 pub fn wasi_hello_wasm() -> &'static [u8] {
54 WASI_HELLO_WASM.get_or_init(generate_wasi_hello_wasm)
55 }
56
57 pub const INVALID_MAGIC_WASM: &[u8] = &[
59 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, ];
62}