diff --git a/examples/memory.wat b/examples/memory.wat index 51f09d18b..b3a97eb9a 100644 --- a/examples/memory.wat +++ b/examples/memory.wat @@ -14,10 +14,12 @@ (drop) (memory.grow (i32.const 0)) - (drop) (memory.grow (i32.const 2)) + (drop) + (memory.grow (i32.const 65536)) + (drop) (memory.grow (i32.const 12)) ) diff --git a/src/build_spectests.rs b/src/build_spectests.rs index 3f9616d68..3b0279983 100644 --- a/src/build_spectests.rs +++ b/src/build_spectests.rs @@ -15,7 +15,7 @@ static ENV_VAR: &str = "WASM_GENERATE_SPECTESTS"; static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs). // Please do NOT modify it by hand, as it will be reseted on next build.\n"; -const TESTS: [&str; 57] = [ +const TESTS: [&str; 58] = [ "spectests/address.wast", "spectests/align.wast", "spectests/binary.wast", @@ -59,6 +59,7 @@ const TESTS: [&str; 57] = [ "spectests/left_to_right.wast", "spectests/loop_.wast", "spectests/memory.wast", + "spectests/memory_grow.wast", "spectests/memory_redundancy.wast", "spectests/nop.wast", "spectests/return_.wast", diff --git a/src/spectests/memory_grow.rs b/src/spectests/memory_grow.rs new file mode 100644 index 000000000..b30211a95 --- /dev/null +++ b/src/spectests/memory_grow.rs @@ -0,0 +1,1602 @@ +// Rust test file autogenerated with cargo build (src/build_spectests.rs). +// Please do NOT modify it by hand, as it will be reseted on next build. +// Test based on spectests/memory_grow.wast +#![allow( + warnings, + dead_code +)] +use std::panic; +use wabt::wat2wasm; + +use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, Instance, Export}; +use super::_common::{ + spectest_importobject, + NaNCheck, +}; + + +// Line 1 +fn create_module_1() -> ResultObject { + let module_str = "(module + (type (;0;) (func (result i32))) + (type (;1;) (func)) + (type (;2;) (func (param i32) (result i32))) + (func (;0;) (type 0) (result i32) + i32.const 0 + i32.load) + (func (;1;) (type 1) + i32.const 0 + i32.const 2 + i32.store) + (func (;2;) (type 0) (result i32) + i32.const 65536 + i32.load) + (func (;3;) (type 1) + i32.const 65536 + i32.const 3 + i32.store) + (func (;4;) (type 2) (param i32) (result i32) + get_local 0 + memory.grow) + (func (;5;) (type 0) (result i32) + memory.size) + (memory (;0;) 0) + (export \"load_at_zero\" (func 0)) + (export \"store_at_zero\" (func 1)) + (export \"load_at_page_size\" (func 2)) + (export \"store_at_page_size\" (func 3)) + (export \"grow\" (func 4)) + (export \"size\" (func 5))) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_1(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 14 +fn c1_l14_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c1_l14_action_invoke"); + let func_index = match result_object.module.info.exports.get("size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 15 +fn c2_l15_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c2_l15_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c2_l15_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c2_l15_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 16 +fn c3_l16_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c3_l16_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c3_l16_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c3_l16_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 17 +fn c4_l17_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c4_l17_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c4_l17_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c4_l17_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 18 +fn c5_l18_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c5_l18_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c5_l18_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c5_l18_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 19 +fn c6_l19_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c6_l19_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 20 +fn c7_l20_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c7_l20_action_invoke"); + let func_index = match result_object.module.info.exports.get("size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 21 +fn c8_l21_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c8_l21_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 22 +fn c9_l22_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c9_l22_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 23 +fn c10_l23_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c10_l23_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 2 as i32); +} + +// Line 24 +fn c11_l24_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c11_l24_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c11_l24_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c11_l24_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 25 +fn c12_l25_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c12_l25_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c12_l25_assert_trap() { + let result_object = create_module_1(); + let result = panic::catch_unwind(|| { + c12_l25_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 26 +fn c13_l26_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c13_l26_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(4 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 27 +fn c14_l27_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c14_l27_action_invoke"); + let func_index = match result_object.module.info.exports.get("size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 5 as i32); +} + +// Line 28 +fn c15_l28_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c15_l28_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 2 as i32); +} + +// Line 29 +fn c16_l29_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c16_l29_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 30 +fn c17_l30_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c17_l30_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 2 as i32); +} + +// Line 31 +fn c18_l31_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c18_l31_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 32 +fn c19_l32_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c19_l32_action_invoke"); + let func_index = match result_object.module.info.exports.get("store_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 33 +fn c20_l33_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c20_l33_action_invoke"); + let func_index = match result_object.module.info.exports.get("load_at_page_size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 3 as i32); +} + +// Line 36 + +#[test] +fn test_module_1() { + let result_object = create_module_1(); + // We group the calls together + start_module_1(&result_object); + c1_l14_action_invoke(&result_object); + c6_l19_action_invoke(&result_object); + c7_l20_action_invoke(&result_object); + c8_l21_action_invoke(&result_object); + c9_l22_action_invoke(&result_object); + c10_l23_action_invoke(&result_object); + c13_l26_action_invoke(&result_object); + c14_l27_action_invoke(&result_object); + c15_l28_action_invoke(&result_object); + c16_l29_action_invoke(&result_object); + c17_l30_action_invoke(&result_object); + c18_l31_action_invoke(&result_object); + c19_l32_action_invoke(&result_object); + c20_l33_action_invoke(&result_object); +} +fn create_module_2() -> ResultObject { + let module_str = "(module + (type (;0;) (func (param i32) (result i32))) + (func (;0;) (type 0) (param i32) (result i32) + get_local 0 + memory.grow) + (memory (;0;) 0) + (export \"grow\" (func 0))) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_2(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 41 +fn c22_l41_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c22_l41_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 42 +fn c23_l42_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c23_l42_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 43 +fn c24_l43_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c24_l43_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 44 +fn c25_l44_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c25_l44_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(2 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 45 +fn c26_l45_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c26_l45_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(800 as i32, &result_object.instance); + assert_eq!(result, 3 as i32); +} + +// Line 46 +fn c27_l46_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c27_l46_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(65536 as i32, &result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 47 +fn c28_l47_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c28_l47_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(64736 as i32, &result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 48 +fn c29_l48_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c29_l48_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 803 as i32); +} + +// Line 50 + +#[test] +fn test_module_2() { + let result_object = create_module_2(); + // We group the calls together + start_module_2(&result_object); + c22_l41_action_invoke(&result_object); + c23_l42_action_invoke(&result_object); + c24_l43_action_invoke(&result_object); + c25_l44_action_invoke(&result_object); + c26_l45_action_invoke(&result_object); + c27_l46_action_invoke(&result_object); + c28_l47_action_invoke(&result_object); + c29_l48_action_invoke(&result_object); +} +fn create_module_3() -> ResultObject { + let module_str = "(module + (type (;0;) (func (param i32) (result i32))) + (func (;0;) (type 0) (param i32) (result i32) + get_local 0 + memory.grow) + (memory (;0;) 0 10) + (export \"grow\" (func 0))) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_3(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 55 +fn c31_l55_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c31_l55_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 56 +fn c32_l56_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c32_l56_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 57 +fn c33_l57_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c33_l57_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 58 +fn c34_l58_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c34_l58_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(2 as i32, &result_object.instance); + assert_eq!(result, 2 as i32); +} + +// Line 59 +fn c35_l59_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c35_l59_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(6 as i32, &result_object.instance); + assert_eq!(result, 4 as i32); +} + +// Line 60 +fn c36_l60_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c36_l60_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, &result_object.instance); + assert_eq!(result, 10 as i32); +} + +// Line 61 +fn c37_l61_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c37_l61_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 62 +fn c38_l62_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c38_l62_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(65536 as i32, &result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 66 + +#[test] +fn test_module_3() { + let result_object = create_module_3(); + // We group the calls together + start_module_3(&result_object); + c31_l55_action_invoke(&result_object); + c32_l56_action_invoke(&result_object); + c33_l57_action_invoke(&result_object); + c34_l58_action_invoke(&result_object); + c35_l59_action_invoke(&result_object); + c36_l60_action_invoke(&result_object); + c37_l61_action_invoke(&result_object); + c38_l62_action_invoke(&result_object); +} +fn create_module_4() -> ResultObject { + let module_str = "(module + (type (;0;) (func (param i32) (result i32))) + (type (;1;) (func (param i32 i32) (result i32))) + (func (;0;) (type 0) (param i32) (result i32) + get_local 0 + memory.grow) + (func (;1;) (type 1) (param i32 i32) (result i32) + (local i32) + i32.const 1 + set_local 2 + block ;; label = @1 + loop ;; label = @2 + get_local 0 + i32.load8_u + set_local 2 + get_local 2 + i32.const 0 + i32.ne + br_if 1 (;@1;) + get_local 0 + get_local 1 + i32.ge_u + br_if 1 (;@1;) + get_local 0 + i32.const 1 + i32.add + set_local 0 + get_local 0 + get_local 1 + i32.le_u + br_if 0 (;@2;) + end + end + get_local 2) + (memory (;0;) 1) + (export \"grow\" (func 0)) + (export \"check-memory-zero\" (func 1))) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_4(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 87 +fn c40_l87_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c40_l87_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, 65535 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 88 +fn c41_l88_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c41_l88_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 89 +fn c42_l89_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c42_l89_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(65536 as i32, 131071 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 90 +fn c43_l90_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c43_l90_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 2 as i32); +} + +// Line 91 +fn c44_l91_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c44_l91_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(131072 as i32, 196607 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 92 +fn c45_l92_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c45_l92_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 3 as i32); +} + +// Line 93 +fn c46_l93_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c46_l93_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(196608 as i32, 262143 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 94 +fn c47_l94_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c47_l94_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 4 as i32); +} + +// Line 95 +fn c48_l95_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c48_l95_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(262144 as i32, 327679 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 96 +fn c49_l96_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c49_l96_action_invoke"); + let func_index = match result_object.module.info.exports.get("grow") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(1 as i32, &result_object.instance); + assert_eq!(result, 5 as i32); +} + +// Line 97 +fn c50_l97_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c50_l97_action_invoke"); + let func_index = match result_object.module.info.exports.get("check-memory-zero") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(327680 as i32, 393215 as i32, &result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 101 + +#[test] +fn test_module_4() { + let result_object = create_module_4(); + // We group the calls together + start_module_4(&result_object); + c40_l87_action_invoke(&result_object); + c41_l88_action_invoke(&result_object); + c42_l89_action_invoke(&result_object); + c43_l90_action_invoke(&result_object); + c44_l91_action_invoke(&result_object); + c45_l92_action_invoke(&result_object); + c46_l93_action_invoke(&result_object); + c47_l94_action_invoke(&result_object); + c48_l95_action_invoke(&result_object); + c49_l96_action_invoke(&result_object); + c50_l97_action_invoke(&result_object); +} +fn create_module_5() -> ResultObject { + let module_str = "(module + (type (;0;) (func (param i32 i32 i32) (result i32))) + (type (;1;) (func (result i32))) + (type (;2;) (func)) + (type (;3;) (func (param i32 i32) (result i32))) + (func (;0;) (type 1) (result i32) + block (result i32) ;; label = @1 + i32.const 0 + memory.grow + br 0 (;@1;) + end) + (func (;1;) (type 2) + block ;; label = @1 + i32.const 0 + memory.grow + br_if 0 (;@1;) + end) + (func (;2;) (type 1) (result i32) + block (result i32) ;; label = @1 + i32.const 0 + memory.grow + i32.const 1 + br_if 0 (;@1;) + drop + i32.const 7 + end) + (func (;3;) (type 1) (result i32) + block (result i32) ;; label = @1 + i32.const 6 + i32.const 0 + memory.grow + br_if 0 (;@1;) + drop + i32.const 7 + end) + (func (;4;) (type 2) + block ;; label = @1 + i32.const 0 + memory.grow + br_table 0 (;@1;) 0 (;@1;) 0 (;@1;) + end) + (func (;5;) (type 1) (result i32) + block (result i32) ;; label = @1 + i32.const 0 + memory.grow + i32.const 1 + br_table 0 (;@1;) 0 (;@1;) 0 (;@1;) + i32.const 7 + end) + (func (;6;) (type 1) (result i32) + block (result i32) ;; label = @1 + i32.const 6 + i32.const 0 + memory.grow + br_table 0 (;@1;) 0 (;@1;) + i32.const 7 + end) + (func (;7;) (type 1) (result i32) + i32.const 0 + memory.grow + return) + (func (;8;) (type 1) (result i32) + i32.const 0 + memory.grow + if (result i32) ;; label = @1 + i32.const 0 + else + i32.const 1 + end) + (func (;9;) (type 1) (result i32) + i32.const 1 + if (result i32) ;; label = @1 + i32.const 0 + memory.grow + else + i32.const 0 + end) + (func (;10;) (type 1) (result i32) + i32.const 0 + if (result i32) ;; label = @1 + i32.const 0 + else + i32.const 0 + memory.grow + end) + (func (;11;) (type 3) (param i32 i32) (result i32) + i32.const 0 + memory.grow + get_local 0 + get_local 1 + select) + (func (;12;) (type 3) (param i32 i32) (result i32) + get_local 0 + i32.const 0 + memory.grow + get_local 1 + select) + (func (;13;) (type 1) (result i32) + i32.const 0 + i32.const 1 + i32.const 0 + memory.grow + select) + (func (;14;) (type 0) (param i32 i32 i32) (result i32) + i32.const -1) + (func (;15;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.const 2 + i32.const 3 + call 14) + (func (;16;) (type 1) (result i32) + i32.const 1 + i32.const 0 + memory.grow + i32.const 3 + call 14) + (func (;17;) (type 1) (result i32) + i32.const 1 + i32.const 2 + i32.const 0 + memory.grow + call 14) + (func (;18;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.const 2 + i32.const 3 + i32.const 0 + call_indirect (type 0)) + (func (;19;) (type 1) (result i32) + i32.const 1 + i32.const 0 + memory.grow + i32.const 3 + i32.const 0 + call_indirect (type 0)) + (func (;20;) (type 1) (result i32) + i32.const 1 + i32.const 2 + i32.const 0 + memory.grow + i32.const 0 + call_indirect (type 0)) + (func (;21;) (type 1) (result i32) + i32.const 1 + i32.const 2 + i32.const 3 + i32.const 0 + memory.grow + call_indirect (type 0)) + (func (;22;) (type 2) + (local i32) + i32.const 0 + memory.grow + set_local 0) + (func (;23;) (type 1) (result i32) + (local i32) + i32.const 0 + memory.grow + tee_local 0) + (func (;24;) (type 2) + (local i32) + i32.const 0 + memory.grow + set_global 0) + (func (;25;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.load) + (func (;26;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.load8_s) + (func (;27;) (type 2) + i32.const 0 + memory.grow + i32.const 7 + i32.store) + (func (;28;) (type 2) + i32.const 2 + i32.const 0 + memory.grow + i32.store) + (func (;29;) (type 2) + i32.const 0 + memory.grow + i32.const 7 + i32.store8) + (func (;30;) (type 2) + i32.const 2 + i32.const 0 + memory.grow + i32.store16) + (func (;31;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.clz) + (func (;32;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.const 10 + i32.add) + (func (;33;) (type 1) (result i32) + i32.const 10 + i32.const 0 + memory.grow + i32.sub) + (func (;34;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.eqz) + (func (;35;) (type 1) (result i32) + i32.const 0 + memory.grow + i32.const 10 + i32.le_s) + (func (;36;) (type 1) (result i32) + i32.const 10 + i32.const 0 + memory.grow + i32.ne) + (func (;37;) (type 1) (result i32) + i32.const 0 + memory.grow + memory.grow) + (table (;0;) 1 1 anyfunc) + (memory (;0;) 1) + (global (;0;) (mut i32) (i32.const 0)) + (export \"as-br-value\" (func 0)) + (export \"as-br_if-cond\" (func 1)) + (export \"as-br_if-value\" (func 2)) + (export \"as-br_if-value-cond\" (func 3)) + (export \"as-br_table-index\" (func 4)) + (export \"as-br_table-value\" (func 5)) + (export \"as-br_table-value-index\" (func 6)) + (export \"as-return-value\" (func 7)) + (export \"as-if-cond\" (func 8)) + (export \"as-if-then\" (func 9)) + (export \"as-if-else\" (func 10)) + (export \"as-select-first\" (func 11)) + (export \"as-select-second\" (func 12)) + (export \"as-select-cond\" (func 13)) + (export \"as-call-first\" (func 15)) + (export \"as-call-mid\" (func 16)) + (export \"as-call-last\" (func 17)) + (export \"as-call_indirect-first\" (func 18)) + (export \"as-call_indirect-mid\" (func 19)) + (export \"as-call_indirect-last\" (func 20)) + (export \"as-call_indirect-index\" (func 21)) + (export \"as-set_local-value\" (func 22)) + (export \"as-tee_local-value\" (func 23)) + (export \"as-set_global-value\" (func 24)) + (export \"as-load-address\" (func 25)) + (export \"as-loadN-address\" (func 26)) + (export \"as-store-address\" (func 27)) + (export \"as-store-value\" (func 28)) + (export \"as-storeN-address\" (func 29)) + (export \"as-storeN-value\" (func 30)) + (export \"as-unary-operand\" (func 31)) + (export \"as-binary-left\" (func 32)) + (export \"as-binary-right\" (func 33)) + (export \"as-test-operand\" (func 34)) + (export \"as-compare-left\" (func 35)) + (export \"as-compare-right\" (func 36)) + (export \"as-memory.grow-size\" (func 37)) + (elem (;0;) (i32.const 0) 14)) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_5(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 259 +fn c52_l259_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c52_l259_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 261 +fn c53_l261_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c53_l261_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_if-cond") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 262 +fn c54_l262_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c54_l262_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_if-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 263 +fn c55_l263_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c55_l263_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_if-value-cond") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 6 as i32); +} + +// Line 265 +fn c56_l265_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c56_l265_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_table-index") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 266 +fn c57_l266_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c57_l266_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_table-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 267 +fn c58_l267_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c58_l267_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-br_table-value-index") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 6 as i32); +} + +// Line 269 +fn c59_l269_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c59_l269_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-return-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 271 +fn c60_l271_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c60_l271_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-if-cond") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 272 +fn c61_l272_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c61_l272_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-if-then") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 273 +fn c62_l273_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c62_l273_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-if-else") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 275 +fn c63_l275_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c63_l275_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-select-first") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, 1 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 276 +fn c64_l276_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c64_l276_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-select-second") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(i32, i32, &Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(0 as i32, 0 as i32, &result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 277 +fn c65_l277_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c65_l277_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-select-cond") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 279 +fn c66_l279_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c66_l279_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call-first") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 280 +fn c67_l280_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c67_l280_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call-mid") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 281 +fn c68_l281_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c68_l281_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call-last") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 283 +fn c69_l283_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c69_l283_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call_indirect-first") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 284 +fn c70_l284_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c70_l284_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call_indirect-mid") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 285 +fn c71_l285_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c71_l285_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call_indirect-last") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, -1 as i32); +} + +// Line 286 +fn c72_l286_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c72_l286_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-call_indirect-index") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c72_l286_assert_trap() { + let result_object = create_module_5(); + let result = panic::catch_unwind(|| { + c72_l286_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 288 +fn c73_l288_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c73_l288_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-set_local-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 289 +fn c74_l289_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c74_l289_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-tee_local-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 290 +fn c75_l290_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c75_l290_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-set_global-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 292 +fn c76_l292_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c76_l292_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-load-address") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 293 +fn c77_l293_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c77_l293_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-loadN-address") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 294 +fn c78_l294_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c78_l294_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-store-address") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 295 +fn c79_l295_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c79_l295_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-store-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 296 +fn c80_l296_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c80_l296_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-storeN-address") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 297 +fn c81_l297_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c81_l297_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-storeN-value") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, ()); +} + +// Line 299 +fn c82_l299_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c82_l299_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-unary-operand") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 31 as i32); +} + +// Line 301 +fn c83_l301_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c83_l301_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-binary-left") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 11 as i32); +} + +// Line 302 +fn c84_l302_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c84_l302_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-binary-right") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 9 as i32); +} + +// Line 304 +fn c85_l304_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c85_l304_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-test-operand") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 0 as i32); +} + +// Line 306 +fn c86_l306_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c86_l306_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-compare-left") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 307 +fn c87_l307_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c87_l307_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-compare-right") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +// Line 309 +fn c88_l309_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c88_l309_action_invoke"); + let func_index = match result_object.module.info.exports.get("as-memory.grow-size") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 1 as i32); +} + +#[test] +fn test_module_5() { + let result_object = create_module_5(); + // We group the calls together + start_module_5(&result_object); + c52_l259_action_invoke(&result_object); + c53_l261_action_invoke(&result_object); + c54_l262_action_invoke(&result_object); + c55_l263_action_invoke(&result_object); + c56_l265_action_invoke(&result_object); + c57_l266_action_invoke(&result_object); + c58_l267_action_invoke(&result_object); + c59_l269_action_invoke(&result_object); + c60_l271_action_invoke(&result_object); + c61_l272_action_invoke(&result_object); + c62_l273_action_invoke(&result_object); + c63_l275_action_invoke(&result_object); + c64_l276_action_invoke(&result_object); + c65_l277_action_invoke(&result_object); + c66_l279_action_invoke(&result_object); + c67_l280_action_invoke(&result_object); + c68_l281_action_invoke(&result_object); + c69_l283_action_invoke(&result_object); + c70_l284_action_invoke(&result_object); + c71_l285_action_invoke(&result_object); + c73_l288_action_invoke(&result_object); + c74_l289_action_invoke(&result_object); + c75_l290_action_invoke(&result_object); + c76_l292_action_invoke(&result_object); + c77_l293_action_invoke(&result_object); + c78_l294_action_invoke(&result_object); + c79_l295_action_invoke(&result_object); + c80_l296_action_invoke(&result_object); + c81_l297_action_invoke(&result_object); + c82_l299_action_invoke(&result_object); + c83_l301_action_invoke(&result_object); + c84_l302_action_invoke(&result_object); + c85_l304_action_invoke(&result_object); + c86_l306_action_invoke(&result_object); + c87_l307_action_invoke(&result_object); + c88_l309_action_invoke(&result_object); +} diff --git a/src/spectests/mod.rs b/src/spectests/mod.rs index 3882469e3..691fe75fb 100644 --- a/src/spectests/mod.rs +++ b/src/spectests/mod.rs @@ -58,6 +58,7 @@ mod labels; mod left_to_right; mod loop_; mod memory; +mod memory_grow; mod memory_redundancy; mod nop; mod return_; diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index d7e8c6e53..63178674a 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -508,13 +508,14 @@ extern "C" fn grow_memory(size: u32, memory_index: u32, instance: &mut Instance) let old_mem_size = instance .memory_mut(memory_index as usize) .grow(size) - .unwrap_or(i32::max_value()); // Should be -1 ? + .unwrap_or(-1); - // Get new memory bytes - let new_mem_bytes = (old_mem_size as usize + size as usize) * LinearMemory::WASM_PAGE_SIZE; - - // Update data_pointer - instance.data_pointers.memories.get_unchecked_mut(memory_index as usize).len = new_mem_bytes; + if old_mem_size != -1 { + // Get new memory bytes + let new_mem_bytes = (old_mem_size as usize + size as usize) * LinearMemory::WASM_PAGE_SIZE; + // Update data_pointer + instance.data_pointers.memories.get_unchecked_mut(memory_index as usize).len = new_mem_bytes; + } old_mem_size }