// 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/switch.wast #![allow( warnings, dead_code )] use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use super::_common::spectest_importobject; use wabt::wat2wasm; // Line 1 fn create_module_1() -> ResultObject { let module_str = "(module (type (;0;) (func (param i32) (result i32))) (type (;1;) (func (param i64) (result i64))) (type (;2;) (func (result i32))) (func (;0;) (type 0) (param i32) (result i32) (local i32) i32.const 100 set_local 1 block ;; label = @1 block ;; label = @2 block ;; label = @3 block ;; label = @4 block ;; label = @5 block ;; label = @6 block ;; label = @7 block ;; label = @8 block ;; label = @9 block ;; label = @10 get_local 0 br_table 0 (;@10;) 1 (;@9;) 2 (;@8;) 3 (;@7;) 4 (;@6;) 5 (;@5;) 6 (;@4;) 8 (;@2;) 7 (;@3;) end get_local 0 return end nop end end i32.const 0 get_local 0 i32.sub set_local 1 br 5 (;@1;) end br 4 (;@1;) end i32.const 101 set_local 1 br 3 (;@1;) end i32.const 101 set_local 1 end i32.const 102 set_local 1 end end get_local 1 return) (func (;1;) (type 1) (param i64) (result i64) (local i64) i64.const 100 set_local 1 block (result i64) ;; label = @1 block ;; label = @2 block ;; label = @3 block ;; label = @4 block ;; label = @5 block ;; label = @6 block ;; label = @7 block ;; label = @8 block ;; label = @9 block ;; label = @10 get_local 0 i32.wrap/i64 br_table 0 (;@10;) 1 (;@9;) 2 (;@8;) 3 (;@7;) 6 (;@4;) 5 (;@5;) 4 (;@6;) 8 (;@2;) 7 (;@3;) end get_local 0 return end nop end end i64.const 0 get_local 0 i64.sub br 5 (;@1;) end i64.const 101 set_local 1 end end end get_local 1 br 1 (;@1;) end i64.const -5 end return) (func (;2;) (type 0) (param i32) (result i32) block (result i32) ;; label = @1 i32.const 10 block (result i32) ;; label = @2 i32.const 100 block (result i32) ;; label = @3 i32.const 1000 block (result i32) ;; label = @4 i32.const 2 get_local 0 i32.mul i32.const 3 get_local 0 i32.and br_table 1 (;@3;) 2 (;@2;) 3 (;@1;) 0 (;@4;) end i32.add end i32.add end i32.add end return) (func (;3;) (type 2) (result i32) block ;; label = @1 i32.const 0 br_table 0 (;@1;) end i32.const 1) (export \"stmt\" (func 0)) (export \"expr\" (func 1)) (export \"arg\" (func 2)) (export \"corner\" (func 3))) "; 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") } // Line 120 fn l120_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l120_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(0 as i32, &vm_context); assert_eq!(result, 0 as i32); } // Line 121 fn l121_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l121_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(1 as i32, &vm_context); assert_eq!(result, -1 as i32); } // Line 122 fn l122_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l122_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(2 as i32, &vm_context); assert_eq!(result, -2 as i32); } // Line 123 fn l123_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l123_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(3 as i32, &vm_context); assert_eq!(result, -3 as i32); } // Line 124 fn l124_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l124_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(4 as i32, &vm_context); assert_eq!(result, 100 as i32); } // Line 125 fn l125_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l125_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(5 as i32, &vm_context); assert_eq!(result, 101 as i32); } // Line 126 fn l126_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l126_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(6 as i32, &vm_context); assert_eq!(result, 102 as i32); } // Line 127 fn l127_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l127_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(7 as i32, &vm_context); assert_eq!(result, 100 as i32); } // Line 128 fn l128_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l128_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("stmt") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(-10 as i32, &vm_context); assert_eq!(result, 102 as i32); } // Line 130 fn l130_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l130_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(0 as i64, &vm_context); assert_eq!(result, 0 as i64); } // Line 131 fn l131_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l131_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(1 as i64, &vm_context); assert_eq!(result, -1 as i64); } // Line 132 fn l132_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l132_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(2 as i64, &vm_context); assert_eq!(result, -2 as i64); } // Line 133 fn l133_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l133_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(3 as i64, &vm_context); assert_eq!(result, -3 as i64); } // Line 134 fn l134_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l134_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(6 as i64, &vm_context); assert_eq!(result, 101 as i64); } // Line 135 fn l135_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l135_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(7 as i64, &vm_context); assert_eq!(result, -5 as i64); } // Line 136 fn l136_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l136_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("expr") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(-10 as i64, &vm_context); assert_eq!(result, 100 as i64); } // Line 138 fn l138_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l138_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(0 as i32, &vm_context); assert_eq!(result, 110 as i32); } // Line 139 fn l139_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l139_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(1 as i32, &vm_context); assert_eq!(result, 12 as i32); } // Line 140 fn l140_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l140_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(2 as i32, &vm_context); assert_eq!(result, 4 as i32); } // Line 141 fn l141_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l141_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(3 as i32, &vm_context); assert_eq!(result, 1116 as i32); } // Line 142 fn l142_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l142_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(4 as i32, &vm_context); assert_eq!(result, 118 as i32); } // Line 143 fn l143_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l143_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(5 as i32, &vm_context); assert_eq!(result, 20 as i32); } // Line 144 fn l144_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l144_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(6 as i32, &vm_context); assert_eq!(result, 12 as i32); } // Line 145 fn l145_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l145_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(7 as i32, &vm_context); assert_eq!(result, 1124 as i32); } // Line 146 fn l146_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l146_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("arg") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(8 as i32, &vm_context); assert_eq!(result, 126 as i32); } // Line 148 fn l148_assert_return_invoke(result_object: &ResultObject, vm_context: &VmCtx) { println!("Executing function {}", "l148_assert_return_invoke"); let func_index = match result_object.module.info.exports.get("corner") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), }; let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index); let result = invoke_fn(&vm_context); assert_eq!(result, 1 as i32); } // Line 150 #[test] fn l150_assert_invalid() { let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 9, 1, 7, 0, 65, 0, 14, 0, 3, 11]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is invalid"); } #[test] fn test_module_1() { let result_object = create_module_1(); let vm_context = result_object.instance.generate_context(); // We group the calls together l120_assert_return_invoke(&result_object, &vm_context); l121_assert_return_invoke(&result_object, &vm_context); l122_assert_return_invoke(&result_object, &vm_context); l123_assert_return_invoke(&result_object, &vm_context); l124_assert_return_invoke(&result_object, &vm_context); l125_assert_return_invoke(&result_object, &vm_context); l126_assert_return_invoke(&result_object, &vm_context); l127_assert_return_invoke(&result_object, &vm_context); l128_assert_return_invoke(&result_object, &vm_context); l130_assert_return_invoke(&result_object, &vm_context); l131_assert_return_invoke(&result_object, &vm_context); l132_assert_return_invoke(&result_object, &vm_context); l133_assert_return_invoke(&result_object, &vm_context); l134_assert_return_invoke(&result_object, &vm_context); l135_assert_return_invoke(&result_object, &vm_context); l136_assert_return_invoke(&result_object, &vm_context); l138_assert_return_invoke(&result_object, &vm_context); l139_assert_return_invoke(&result_object, &vm_context); l140_assert_return_invoke(&result_object, &vm_context); l141_assert_return_invoke(&result_object, &vm_context); l142_assert_return_invoke(&result_object, &vm_context); l143_assert_return_invoke(&result_object, &vm_context); l144_assert_return_invoke(&result_object, &vm_context); l145_assert_return_invoke(&result_object, &vm_context); l146_assert_return_invoke(&result_object, &vm_context); l148_assert_return_invoke(&result_object, &vm_context); }