Improved testing times by 5-10x

This is done via grouping of module/instance creation calls. This way the assert return calls are grouped to be tested in the same thread (therefore only one module creation is required rather than n=one for each test)
This commit is contained in:
Syrus Akbary
2018-10-23 15:43:35 +02:00
parent 8671025d97
commit 6653eeca4f
13 changed files with 7322 additions and 3635 deletions

1515
spectests/br_table.wast Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
//! This file will run at build time to autogenerate Rust tests based on //! This file will run at build time to autogenerate Rust tests based on
//! WebAssembly spec tests. It will convert the files indicated in TESTS //! WebAssembly spec tests. It will convert the files indicated in TESTS
//! from "/spectests/{MODULE}.wast" to "/src/spectests/{MODULE}.rs". //! from "/spectests/{MODULE}.wast" to "/src/spectests/{MODULE}.rs".
use std::collections::HashMap;
use std::fs; use std::fs;
use std::io::{self, Read}; use std::io::{self, Read};
use std::path::PathBuf; use std::path::PathBuf;
@ -11,8 +12,9 @@ use wabt::wasm2wat;
static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs). 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"; // Please do NOT modify it by hand, as it will be reseted on next build.\n";
const TESTS: [&str; 8] = [ const TESTS: [&str; 9] = [
"spectests/br_if.wast", "spectests/br_if.wast",
"spectests/br_table.wast",
"spectests/call.wast", "spectests/call.wast",
"spectests/call_indirect.wast", "spectests/call_indirect.wast",
"spectests/func_ptrs.wast", "spectests/func_ptrs.wast",
@ -22,14 +24,6 @@ const TESTS: [&str; 8] = [
"spectests/types.wast", "spectests/types.wast",
]; ];
struct WastTestGenerator {
last_module: i32,
last_line: u64,
filename: String,
script_parser: ScriptParser,
buffer: String,
}
fn wabt2rust_type(v: &Value) -> String { fn wabt2rust_type(v: &Value) -> String {
match v { match v {
Value::I32(v) => format!("i32"), Value::I32(v) => format!("i32"),
@ -48,6 +42,15 @@ fn wabt2rust_value(v: &Value) -> String {
} }
} }
struct WastTestGenerator {
last_module: i32,
last_line: u64,
filename: String,
script_parser: ScriptParser,
module_calls: HashMap<i32, Vec<String>>,
buffer: String,
}
impl WastTestGenerator { impl WastTestGenerator {
fn new(path: &PathBuf) -> Self { fn new(path: &PathBuf) -> Self {
let filename = path.file_name().unwrap().to_str().unwrap(); let filename = path.file_name().unwrap().to_str().unwrap();
@ -61,6 +64,7 @@ impl WastTestGenerator {
filename: filename.to_string(), filename: filename.to_string(),
script_parser: script, script_parser: script,
buffer: buffer, buffer: buffer,
module_calls: HashMap::new(),
} }
} }
@ -68,7 +72,6 @@ impl WastTestGenerator {
self.buffer.push_str(BANNER); self.buffer.push_str(BANNER);
self.buffer.push_str(&format!( self.buffer.push_str(&format!(
"// Test based on spectests/{} "// Test based on spectests/{}
use crate::webassembly::{{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}}; use crate::webassembly::{{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}};
use super::_common::spectest_importobject; use super::_common::spectest_importobject;
use wabt::wat2wasm;\n\n", use wabt::wat2wasm;\n\n",
@ -80,12 +83,43 @@ use wabt::wat2wasm;\n\n",
.push_str(&format!("\n// Line {}\n", self.last_line)); .push_str(&format!("\n// Line {}\n", self.last_line));
self.visit_command(&kind); self.visit_command(&kind);
} }
for n in 1..self.last_module + 1 {
self.flush_module_calls(n);
}
}
fn flush_module_calls(&mut self, module: i32) {
let calls: Vec<String> = self
.module_calls
.entry(module)
.or_insert(Vec::new())
.iter()
.map(|call_str| format!("{}(&result_object);", call_str))
.collect();
if calls.len() > 0 {
self.buffer.push_str(
format!(
"\n#[test]
fn test_module_{}() {{
let result_object = create_module_{}();
// We group the calls together
{}
}}\n",
module,
module,
calls.join("\n ")
)
.as_str(),
);
}
self.module_calls.remove(&module);
} }
fn visit_module(&mut self, module: &ModuleBinary, name: &Option<String>) { fn visit_module(&mut self, module: &ModuleBinary, name: &Option<String>) {
let wasm_binary: Vec<u8> = module.clone().into_vec(); let wasm_binary: Vec<u8> = module.clone().into_vec();
let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm"); let wast_string = wasm2wat(wasm_binary).expect("Can't convert back to wasm");
self.flush_module_calls(self.last_module);
self.last_module = self.last_module + 1; self.last_module = self.last_module + 1;
// self.module_calls.insert(self.last_module, vec![]);
self.buffer.push_str( self.buffer.push_str(
format!( format!(
"fn create_module_{}() -> ResultObject {{ "fn create_module_{}() -> ResultObject {{
@ -165,22 +199,20 @@ fn l{}_assert_malformed() {{
args_types.push("&VmCtx".to_string()); args_types.push("&VmCtx".to_string());
let mut args_values: Vec<String> = args.iter().map(wabt2rust_value).collect(); let mut args_values: Vec<String> = args.iter().map(wabt2rust_value).collect();
args_values.push("&vm_context".to_string()); args_values.push("&vm_context".to_string());
let func_name = format!("l{}_assert_return_invoke", self.last_line);
self.buffer.push_str( self.buffer.push_str(
format!( format!(
"#[test] "fn {}(result_object: &ResultObject) {{
fn l{}_assert_return_invoke() {{ let func_index = match result_object.module.info.exports.get({:?}) {{
let ResultObject {{ mut instance, module }} = create_module_{}();
let func_index = match module.info.exports.get({:?}) {{
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!(\"Function not found\"), _ => panic!(\"Function not found\"),
}}; }};
let invoke_fn: fn({}){} = get_instance_function!(instance, func_index); let invoke_fn: fn({}){} = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn({}); let result = invoke_fn({});
assert_eq!(result, {}); assert_eq!(result, {});
}}\n", }}\n",
self.last_line, func_name,
self.last_module,
field, field,
args_types.join(", "), args_types.join(", "),
func_return, func_return,
@ -189,6 +221,12 @@ fn l{}_assert_return_invoke() {{
) )
.as_str(), .as_str(),
); );
self.module_calls
.entry(self.last_module)
.or_insert(Vec::new())
.push(func_name);
// let mut module_calls = self.module_calls.get(&self.last_module).unwrap();
// module_calls.push(func_name);
} }
_ => {} _ => {}
}; };

File diff suppressed because it is too large Load Diff

2757
src/spectests/br_table.rs Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,8 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs). // 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. // Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/call.wast // Test based on spectests/call.wast
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject;
use wabt::wat2wasm; use wabt::wat2wasm;
@ -177,467 +177,401 @@ fn create_module_1() -> ResultObject {
(export \"mutual-runaway\" (func 30))) (export \"mutual-runaway\" (func 30)))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 111 // Line 111
#[test] fn l111_assert_return_invoke(result_object: &ResultObject) {
fn l111_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-i32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-i32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 306 as i32); assert_eq!(result, 306 as i32);
} }
// Line 112 // Line 112
#[test] fn l112_assert_return_invoke(result_object: &ResultObject) {
fn l112_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-i64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-i64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 356 as i64); assert_eq!(result, 356 as i64);
} }
// Line 113 // Line 113
#[test] fn l113_assert_return_invoke(result_object: &ResultObject) {
fn l113_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-f32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-f32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 3890.0 as f32); assert_eq!(result, 3890.0 as f32);
} }
// Line 114 // Line 114
#[test] fn l114_assert_return_invoke(result_object: &ResultObject) {
fn l114_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-f64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-f64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 3940.0 as f64); assert_eq!(result, 3940.0 as f64);
} }
// Line 116 // Line 116
#[test] fn l116_assert_return_invoke(result_object: &ResultObject) {
fn l116_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-first-i32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-first-i32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 32 as i32); assert_eq!(result, 32 as i32);
} }
// Line 117 // Line 117
#[test] fn l117_assert_return_invoke(result_object: &ResultObject) {
fn l117_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-first-i64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-first-i64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 64 as i64); assert_eq!(result, 64 as i64);
} }
// Line 118 // Line 118
#[test] fn l118_assert_return_invoke(result_object: &ResultObject) {
fn l118_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-first-f32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-first-f32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 1.32 as f32); assert_eq!(result, 1.32 as f32);
} }
// Line 119 // Line 119
#[test] fn l119_assert_return_invoke(result_object: &ResultObject) {
fn l119_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-first-f64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-first-f64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 1.64 as f64); assert_eq!(result, 1.64 as f64);
} }
// Line 121 // Line 121
#[test] fn l121_assert_return_invoke(result_object: &ResultObject) {
fn l121_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-second-i32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-second-i32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 32 as i32); assert_eq!(result, 32 as i32);
} }
// Line 122 // Line 122
#[test] fn l122_assert_return_invoke(result_object: &ResultObject) {
fn l122_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-second-i64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-second-i64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 64 as i64); assert_eq!(result, 64 as i64);
} }
// Line 123 // Line 123
#[test] fn l123_assert_return_invoke(result_object: &ResultObject) {
fn l123_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-second-f32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-second-f32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 32.0 as f32); assert_eq!(result, 32.0 as f32);
} }
// Line 124 // Line 124
#[test] fn l124_assert_return_invoke(result_object: &ResultObject) {
fn l124_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-second-f64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-second-f64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> f64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 64.1 as f64); assert_eq!(result, 64.1 as f64);
} }
// Line 126 // Line 126
#[test] fn l126_assert_return_invoke(result_object: &ResultObject) {
fn l126_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i64, &vm_context); let result = invoke_fn(0 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 127 // Line 127
#[test] fn l127_assert_return_invoke(result_object: &ResultObject) {
fn l127_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, &vm_context); let result = invoke_fn(1 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 128 // Line 128
#[test] fn l128_assert_return_invoke(result_object: &ResultObject) {
fn l128_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i64, &vm_context); let result = invoke_fn(5 as i64, &vm_context);
assert_eq!(result, 120 as i64); assert_eq!(result, 120 as i64);
} }
// Line 129 // Line 129
#[test] fn l129_assert_return_invoke(result_object: &ResultObject) {
fn l129_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(25 as i64, &vm_context); let result = invoke_fn(25 as i64, &vm_context);
assert_eq!(result, 7034535277573963776 as i64); assert_eq!(result, 7034535277573963776 as i64);
} }
// Line 130 // Line 130
#[test] fn l130_assert_return_invoke(result_object: &ResultObject) {
fn l130_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac-acc") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac-acc") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i64, 1 as i64, &vm_context); let result = invoke_fn(0 as i64, 1 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 131 // Line 131
#[test] fn l131_assert_return_invoke(result_object: &ResultObject) {
fn l131_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac-acc") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac-acc") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, 1 as i64, &vm_context); let result = invoke_fn(1 as i64, 1 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 132 // Line 132
#[test] fn l132_assert_return_invoke(result_object: &ResultObject) {
fn l132_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac-acc") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac-acc") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i64, 1 as i64, &vm_context); let result = invoke_fn(5 as i64, 1 as i64, &vm_context);
assert_eq!(result, 120 as i64); assert_eq!(result, 120 as i64);
} }
// Line 134 // Line 134
#[test] fn l134_assert_return_invoke(result_object: &ResultObject) {
fn l134_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fac-acc") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fac-acc") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(25 as i64, 1 as i64, &vm_context); let result = invoke_fn(25 as i64, 1 as i64, &vm_context);
assert_eq!(result, 7034535277573963776 as i64); assert_eq!(result, 7034535277573963776 as i64);
} }
// Line 138 // Line 138
#[test] fn l138_assert_return_invoke(result_object: &ResultObject) {
fn l138_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fib") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fib") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i64, &vm_context); let result = invoke_fn(0 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 139 // Line 139
#[test] fn l139_assert_return_invoke(result_object: &ResultObject) {
fn l139_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fib") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fib") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, &vm_context); let result = invoke_fn(1 as i64, &vm_context);
assert_eq!(result, 1 as i64); assert_eq!(result, 1 as i64);
} }
// Line 140 // Line 140
#[test] fn l140_assert_return_invoke(result_object: &ResultObject) {
fn l140_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fib") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fib") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i64, &vm_context); let result = invoke_fn(2 as i64, &vm_context);
assert_eq!(result, 2 as i64); assert_eq!(result, 2 as i64);
} }
// Line 141 // Line 141
#[test] fn l141_assert_return_invoke(result_object: &ResultObject) {
fn l141_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fib") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fib") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i64, &vm_context); let result = invoke_fn(5 as i64, &vm_context);
assert_eq!(result, 8 as i64); assert_eq!(result, 8 as i64);
} }
// Line 142 // Line 142
#[test] fn l142_assert_return_invoke(result_object: &ResultObject) {
fn l142_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("fib") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("fib") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(20 as i64, &vm_context); let result = invoke_fn(20 as i64, &vm_context);
assert_eq!(result, 10946 as i64); assert_eq!(result, 10946 as i64);
} }
// Line 144 // Line 144
#[test] fn l144_assert_return_invoke(result_object: &ResultObject) {
fn l144_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("even") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("even") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i64, &vm_context); let result = invoke_fn(0 as i64, &vm_context);
assert_eq!(result, 44 as i32); assert_eq!(result, 44 as i32);
} }
// Line 145 // Line 145
#[test] fn l145_assert_return_invoke(result_object: &ResultObject) {
fn l145_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("even") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("even") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, &vm_context); let result = invoke_fn(1 as i64, &vm_context);
assert_eq!(result, 99 as i32); assert_eq!(result, 99 as i32);
} }
// Line 146 // Line 146
#[test] fn l146_assert_return_invoke(result_object: &ResultObject) {
fn l146_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("even") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("even") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(100 as i64, &vm_context); let result = invoke_fn(100 as i64, &vm_context);
assert_eq!(result, 44 as i32); assert_eq!(result, 44 as i32);
} }
// Line 147 // Line 147
#[test] fn l147_assert_return_invoke(result_object: &ResultObject) {
fn l147_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("even") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("even") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(77 as i64, &vm_context); let result = invoke_fn(77 as i64, &vm_context);
assert_eq!(result, 99 as i32); assert_eq!(result, 99 as i32);
} }
// Line 148 // Line 148
#[test] fn l148_assert_return_invoke(result_object: &ResultObject) {
fn l148_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("odd") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("odd") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i64, &vm_context); let result = invoke_fn(0 as i64, &vm_context);
assert_eq!(result, 99 as i32); assert_eq!(result, 99 as i32);
} }
// Line 149 // Line 149
#[test] fn l149_assert_return_invoke(result_object: &ResultObject) {
fn l149_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("odd") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("odd") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, &vm_context); let result = invoke_fn(1 as i64, &vm_context);
assert_eq!(result, 44 as i32); assert_eq!(result, 44 as i32);
} }
// Line 150 // Line 150
#[test] fn l150_assert_return_invoke(result_object: &ResultObject) {
fn l150_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("odd") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("odd") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(200 as i64, &vm_context); let result = invoke_fn(200 as i64, &vm_context);
assert_eq!(result, 99 as i32); assert_eq!(result, 99 as i32);
} }
// Line 151 // Line 151
#[test] fn l151_assert_return_invoke(result_object: &ResultObject) {
fn l151_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("odd") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("odd") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(77 as i64, &vm_context); let result = invoke_fn(77 as i64, &vm_context);
assert_eq!(result, 44 as i32); assert_eq!(result, 44 as i32);
} }
@ -647,7 +581,6 @@ fn l151_assert_return_invoke() {
// Line 154 // Line 154
// Line 160 // Line 160
#[test] #[test]
fn l160_assert_invalid() { fn l160_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 10, 2, 5, 0, 16, 1, 69, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 10, 2, 5, 0, 16, 1, 69, 11, 2, 0, 11];
@ -656,7 +589,6 @@ fn l160_assert_invalid() {
} }
// Line 167 // Line 167
#[test] #[test]
fn l167_assert_invalid() { fn l167_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 0, 0, 96, 0, 1, 126, 3, 3, 2, 0, 1, 10, 12, 2, 5, 0, 16, 1, 69, 11, 4, 0, 66, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 0, 0, 96, 0, 1, 126, 3, 3, 2, 0, 1, 10, 12, 2, 5, 0, 16, 1, 69, 11, 4, 0, 66, 1, 11];
@ -665,7 +597,6 @@ fn l167_assert_invalid() {
} }
// Line 175 // Line 175
#[test] #[test]
fn l175_assert_invalid() { fn l175_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 0, 0, 96, 1, 127, 0, 3, 3, 2, 0, 1, 10, 9, 2, 4, 0, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 0, 0, 96, 1, 127, 0, 3, 3, 2, 0, 1, 10, 9, 2, 4, 0, 16, 1, 11, 2, 0, 11];
@ -674,7 +605,6 @@ fn l175_assert_invalid() {
} }
// Line 182 // Line 182
#[test] #[test]
fn l182_assert_invalid() { fn l182_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 124, 127, 0, 3, 3, 2, 0, 1, 10, 9, 2, 4, 0, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 124, 127, 0, 3, 3, 2, 0, 1, 10, 9, 2, 4, 0, 16, 1, 11, 2, 0, 11];
@ -683,7 +613,6 @@ fn l182_assert_invalid() {
} }
// Line 189 // Line 189
#[test] #[test]
fn l189_assert_invalid() { fn l189_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 11, 2, 6, 0, 65, 1, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 11, 2, 6, 0, 65, 1, 16, 1, 11, 2, 0, 11];
@ -692,7 +621,6 @@ fn l189_assert_invalid() {
} }
// Line 196 // Line 196
#[test] #[test]
fn l196_assert_invalid() { fn l196_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 20, 2, 15, 0, 68, 0, 0, 0, 0, 0, 0, 0, 64, 65, 1, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 3, 2, 0, 0, 10, 20, 2, 15, 0, 68, 0, 0, 0, 0, 0, 0, 0, 64, 65, 1, 16, 1, 11, 2, 0, 11];
@ -701,7 +629,6 @@ fn l196_assert_invalid() {
} }
// Line 204 // Line 204
#[test] #[test]
fn l204_assert_invalid() { fn l204_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 127, 0, 3, 3, 2, 0, 1, 10, 12, 2, 7, 0, 1, 65, 1, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 127, 0, 3, 3, 2, 0, 1, 10, 12, 2, 7, 0, 1, 65, 1, 16, 1, 11, 2, 0, 11];
@ -710,7 +637,6 @@ fn l204_assert_invalid() {
} }
// Line 211 // Line 211
#[test] #[test]
fn l211_assert_invalid() { fn l211_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 127, 0, 3, 3, 2, 0, 1, 10, 12, 2, 7, 0, 65, 1, 1, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 127, 0, 3, 3, 2, 0, 1, 10, 12, 2, 7, 0, 65, 1, 1, 16, 1, 11, 2, 0, 11];
@ -719,7 +645,6 @@ fn l211_assert_invalid() {
} }
// Line 218 // Line 218
#[test] #[test]
fn l218_assert_invalid() { fn l218_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 124, 0, 3, 3, 2, 0, 1, 10, 20, 2, 15, 0, 68, 0, 0, 0, 0, 0, 0, 240, 63, 65, 1, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 127, 124, 0, 3, 3, 2, 0, 1, 10, 20, 2, 15, 0, 68, 0, 0, 0, 0, 0, 0, 240, 63, 65, 1, 16, 1, 11, 2, 0, 11];
@ -728,7 +653,6 @@ fn l218_assert_invalid() {
} }
// Line 225 // Line 225
#[test] #[test]
fn l225_assert_invalid() { fn l225_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 124, 127, 0, 3, 3, 2, 0, 1, 10, 20, 2, 15, 0, 65, 1, 68, 0, 0, 0, 0, 0, 0, 240, 63, 16, 1, 11, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 9, 2, 96, 0, 0, 96, 2, 124, 127, 0, 3, 3, 2, 0, 1, 10, 20, 2, 15, 0, 65, 1, 68, 0, 0, 0, 0, 0, 0, 240, 63, 16, 1, 11, 2, 0, 11];
@ -737,7 +661,6 @@ fn l225_assert_invalid() {
} }
// Line 236 // Line 236
#[test] #[test]
fn l236_assert_invalid() { fn l236_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 6, 1, 4, 0, 16, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 6, 1, 4, 0, 16, 1, 11];
@ -746,10 +669,48 @@ fn l236_assert_invalid() {
} }
// Line 240 // Line 240
#[test] #[test]
fn l240_assert_invalid() { fn l240_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 16, 148, 152, 219, 226, 3, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 16, 148, 152, 219, 226, 3, 11];
let compilation = compile(wasm_binary.to_vec()); let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid"); assert!(compilation.is_err(), "WASM should not compile as is invalid");
} }
#[test]
fn test_module_1() {
let result_object = create_module_1();
// We group the calls together
l111_assert_return_invoke(&result_object);
l112_assert_return_invoke(&result_object);
l113_assert_return_invoke(&result_object);
l114_assert_return_invoke(&result_object);
l116_assert_return_invoke(&result_object);
l117_assert_return_invoke(&result_object);
l118_assert_return_invoke(&result_object);
l119_assert_return_invoke(&result_object);
l121_assert_return_invoke(&result_object);
l122_assert_return_invoke(&result_object);
l123_assert_return_invoke(&result_object);
l124_assert_return_invoke(&result_object);
l126_assert_return_invoke(&result_object);
l127_assert_return_invoke(&result_object);
l128_assert_return_invoke(&result_object);
l129_assert_return_invoke(&result_object);
l130_assert_return_invoke(&result_object);
l131_assert_return_invoke(&result_object);
l132_assert_return_invoke(&result_object);
l134_assert_return_invoke(&result_object);
l138_assert_return_invoke(&result_object);
l139_assert_return_invoke(&result_object);
l140_assert_return_invoke(&result_object);
l141_assert_return_invoke(&result_object);
l142_assert_return_invoke(&result_object);
l144_assert_return_invoke(&result_object);
l145_assert_return_invoke(&result_object);
l146_assert_return_invoke(&result_object);
l147_assert_return_invoke(&result_object);
l148_assert_return_invoke(&result_object);
l149_assert_return_invoke(&result_object);
l150_assert_return_invoke(&result_object);
l151_assert_return_invoke(&result_object);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,6 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs). // 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. // Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/func_ptrs.wast // Test based on spectests/func_ptrs.wast
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject; use super::_common::spectest_importobject;
use wabt::wat2wasm; use wabt::wat2wasm;
@ -43,43 +42,37 @@ fn create_module_1() -> ResultObject {
} }
// Line 27 // Line 27
#[test] fn l27_assert_return_invoke(result_object: &ResultObject) {
fn l27_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("one") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("one") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 13 as i32); assert_eq!(result, 13 as i32);
} }
// Line 28 // Line 28
#[test] fn l28_assert_return_invoke(result_object: &ResultObject) {
fn l28_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("two") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("two") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(13 as i32, &vm_context); let result = invoke_fn(13 as i32, &vm_context);
assert_eq!(result, 14 as i32); assert_eq!(result, 14 as i32);
} }
// Line 29 // Line 29
#[test] fn l29_assert_return_invoke(result_object: &ResultObject) {
fn l29_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("three") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("three") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(13 as i32, &vm_context); let result = invoke_fn(13 as i32, &vm_context);
assert_eq!(result, 11 as i32); assert_eq!(result, 11 as i32);
} }
@ -87,7 +80,6 @@ fn l29_assert_return_invoke() {
// Line 30 // Line 30
// Line 32 // Line 32
#[test] #[test]
fn l32_assert_invalid() { fn l32_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 9, 6, 1, 0, 65, 0, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 9, 6, 1, 0, 65, 0, 11, 0];
@ -96,7 +88,6 @@ fn l32_assert_invalid() {
} }
// Line 33 // Line 33
#[test] #[test]
fn l33_assert_invalid() { fn l33_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11];
@ -105,7 +96,6 @@ fn l33_assert_invalid() {
} }
// Line 36 // Line 36
#[test] #[test]
fn l36_assert_invalid() { fn l36_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0];
@ -114,7 +104,6 @@ fn l36_assert_invalid() {
} }
// Line 40 // Line 40
#[test] #[test]
fn l40_assert_invalid() { fn l40_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0];
@ -123,7 +112,6 @@ fn l40_assert_invalid() {
} }
// Line 44 // Line 44
#[test] #[test]
fn l44_assert_invalid() { fn l44_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0];
@ -132,7 +120,6 @@ fn l44_assert_invalid() {
} }
// Line 48 // Line 48
#[test] #[test]
fn l48_assert_invalid() { fn l48_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 3, 2, 1, 42, 10, 4, 1, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 3, 2, 1, 42, 10, 4, 1, 2, 0, 11];
@ -141,7 +128,6 @@ fn l48_assert_invalid() {
} }
// Line 49 // Line 49
#[test] #[test]
fn l49_assert_invalid() { fn l49_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 22, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 9, 112, 114, 105, 110, 116, 95, 105, 51, 50, 0, 43]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 22, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 9, 112, 114, 105, 110, 116, 95, 105, 51, 50, 0, 43];
@ -150,6 +136,15 @@ fn l49_assert_invalid() {
} }
// Line 51 // Line 51
#[test]
fn test_module_1() {
let result_object = create_module_1();
// We group the calls together
l27_assert_return_invoke(&result_object);
l28_assert_return_invoke(&result_object);
l29_assert_return_invoke(&result_object);
}
fn create_module_2() -> ResultObject { fn create_module_2() -> ResultObject {
let module_str = "(module let module_str = "(module
(type (;0;) (func (result i32))) (type (;0;) (func (result i32)))
@ -181,99 +176,85 @@ fn create_module_2() -> ResultObject {
} }
// Line 71 // Line 71
#[test] fn l71_assert_return_invoke(result_object: &ResultObject) {
fn l71_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i32, &vm_context); let result = invoke_fn(0 as i32, &vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 72 // Line 72
#[test] fn l72_assert_return_invoke(result_object: &ResultObject) {
fn l72_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i32, &vm_context); let result = invoke_fn(1 as i32, &vm_context);
assert_eq!(result, 2 as i32); assert_eq!(result, 2 as i32);
} }
// Line 73 // Line 73
#[test] fn l73_assert_return_invoke(result_object: &ResultObject) {
fn l73_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i32, &vm_context); let result = invoke_fn(2 as i32, &vm_context);
assert_eq!(result, 3 as i32); assert_eq!(result, 3 as i32);
} }
// Line 74 // Line 74
#[test] fn l74_assert_return_invoke(result_object: &ResultObject) {
fn l74_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(3 as i32, &vm_context); let result = invoke_fn(3 as i32, &vm_context);
assert_eq!(result, 4 as i32); assert_eq!(result, 4 as i32);
} }
// Line 75 // Line 75
#[test] fn l75_assert_return_invoke(result_object: &ResultObject) {
fn l75_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(4 as i32, &vm_context); let result = invoke_fn(4 as i32, &vm_context);
assert_eq!(result, 5 as i32); assert_eq!(result, 5 as i32);
} }
// Line 76 // Line 76
#[test] fn l76_assert_return_invoke(result_object: &ResultObject) {
fn l76_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i32, &vm_context); let result = invoke_fn(5 as i32, &vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 77 // Line 77
#[test] fn l77_assert_return_invoke(result_object: &ResultObject) {
fn l77_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(6 as i32, &vm_context); let result = invoke_fn(6 as i32, &vm_context);
assert_eq!(result, 3 as i32); assert_eq!(result, 3 as i32);
} }
@ -285,99 +266,85 @@ fn l77_assert_return_invoke() {
// Line 80 // Line 80
// Line 82 // Line 82
#[test] fn l82_assert_return_invoke(result_object: &ResultObject) {
fn l82_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i32, &vm_context); let result = invoke_fn(0 as i32, &vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 83 // Line 83
#[test] fn l83_assert_return_invoke(result_object: &ResultObject) {
fn l83_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i32, &vm_context); let result = invoke_fn(1 as i32, &vm_context);
assert_eq!(result, 2 as i32); assert_eq!(result, 2 as i32);
} }
// Line 84 // Line 84
#[test] fn l84_assert_return_invoke(result_object: &ResultObject) {
fn l84_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i32, &vm_context); let result = invoke_fn(2 as i32, &vm_context);
assert_eq!(result, 3 as i32); assert_eq!(result, 3 as i32);
} }
// Line 85 // Line 85
#[test] fn l85_assert_return_invoke(result_object: &ResultObject) {
fn l85_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(3 as i32, &vm_context); let result = invoke_fn(3 as i32, &vm_context);
assert_eq!(result, 4 as i32); assert_eq!(result, 4 as i32);
} }
// Line 86 // Line 86
#[test] fn l86_assert_return_invoke(result_object: &ResultObject) {
fn l86_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(4 as i32, &vm_context); let result = invoke_fn(4 as i32, &vm_context);
assert_eq!(result, 5 as i32); assert_eq!(result, 5 as i32);
} }
// Line 87 // Line 87
#[test] fn l87_assert_return_invoke(result_object: &ResultObject) {
fn l87_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5 as i32, &vm_context); let result = invoke_fn(5 as i32, &vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 88 // Line 88
#[test] fn l88_assert_return_invoke(result_object: &ResultObject) {
fn l88_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callu") {
let ResultObject { mut instance, module } = create_module_2();
let func_index = match module.info.exports.get("callu") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(6 as i32, &vm_context); let result = invoke_fn(6 as i32, &vm_context);
assert_eq!(result, 3 as i32); assert_eq!(result, 3 as i32);
} }
@ -389,6 +356,26 @@ fn l88_assert_return_invoke() {
// Line 91 // Line 91
// Line 93 // Line 93
#[test]
fn test_module_2() {
let result_object = create_module_2();
// We group the calls together
l71_assert_return_invoke(&result_object);
l72_assert_return_invoke(&result_object);
l73_assert_return_invoke(&result_object);
l74_assert_return_invoke(&result_object);
l75_assert_return_invoke(&result_object);
l76_assert_return_invoke(&result_object);
l77_assert_return_invoke(&result_object);
l82_assert_return_invoke(&result_object);
l83_assert_return_invoke(&result_object);
l84_assert_return_invoke(&result_object);
l85_assert_return_invoke(&result_object);
l86_assert_return_invoke(&result_object);
l87_assert_return_invoke(&result_object);
l88_assert_return_invoke(&result_object);
}
fn create_module_3() -> ResultObject { fn create_module_3() -> ResultObject {
let module_str = "(module let module_str = "(module
(type (;0;) (func (result i32))) (type (;0;) (func (result i32)))
@ -409,29 +396,33 @@ fn create_module_3() -> ResultObject {
} }
// Line 105 // Line 105
#[test] fn l105_assert_return_invoke(result_object: &ResultObject) {
fn l105_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_3();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(0 as i32, &vm_context); let result = invoke_fn(0 as i32, &vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 106 // Line 106
#[test] fn l106_assert_return_invoke(result_object: &ResultObject) {
fn l106_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("callt") {
let ResultObject { mut instance, module } = create_module_3();
let func_index = match module.info.exports.get("callt") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i32, &vm_context); let result = invoke_fn(1 as i32, &vm_context);
assert_eq!(result, 2 as i32); assert_eq!(result, 2 as i32);
} }
#[test]
fn test_module_3() {
let result_object = create_module_3();
// We group the calls together
l105_assert_return_invoke(&result_object);
l106_assert_return_invoke(&result_object);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs). // 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. // Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/memory.wast // Test based on spectests/memory.wast
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject;
use wabt::wat2wasm; use wabt::wat2wasm;
@ -12,7 +12,7 @@ fn create_module_1() -> ResultObject {
(memory (;0;) 0 0)) (memory (;0;) 0 0))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 3 // Line 3
@ -21,7 +21,7 @@ fn create_module_2() -> ResultObject {
(memory (;0;) 0 1)) (memory (;0;) 0 1))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 4 // Line 4
@ -30,7 +30,7 @@ fn create_module_3() -> ResultObject {
(memory (;0;) 1 256)) (memory (;0;) 1 256))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 5 // Line 5
@ -39,11 +39,10 @@ fn create_module_4() -> ResultObject {
(memory (;0;) 0 65536)) (memory (;0;) 0 65536))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 7 // Line 7
#[test] #[test]
fn l7_assert_invalid() { fn l7_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 5, 2, 0, 0, 0, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 5, 2, 0, 0, 0, 0];
@ -52,7 +51,6 @@ fn l7_assert_invalid() {
} }
// Line 8 // Line 8
#[test] #[test]
fn l8_assert_invalid() { fn l8_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 20, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 6, 109, 101, 109, 111, 114, 121, 2, 0, 0, 5, 3, 1, 0, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 20, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 6, 109, 101, 109, 111, 114, 121, 2, 0, 0, 5, 3, 1, 0, 0];
@ -71,24 +69,29 @@ fn create_module_5() -> ResultObject {
(data (i32.const 0) \"\")) (data (i32.const 0) \"\"))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 11 // Line 11
#[test] fn l11_assert_return_invoke(result_object: &ResultObject) {
fn l11_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("memsize") {
let ResultObject { mut instance, module } = create_module_5();
let func_index = match module.info.exports.get("memsize") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 0 as i32); assert_eq!(result, 0 as i32);
} }
// Line 12 // Line 12
#[test]
fn test_module_5() {
let result_object = create_module_5();
// We group the calls together
l11_assert_return_invoke(&result_object);
}
fn create_module_6() -> ResultObject { fn create_module_6() -> ResultObject {
let module_str = "(module let module_str = "(module
(type (;0;) (func (result i32))) (type (;0;) (func (result i32)))
@ -99,24 +102,29 @@ fn create_module_6() -> ResultObject {
(data (i32.const 0) \"\")) (data (i32.const 0) \"\"))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 13 // Line 13
#[test] fn l13_assert_return_invoke(result_object: &ResultObject) {
fn l13_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("memsize") {
let ResultObject { mut instance, module } = create_module_6();
let func_index = match module.info.exports.get("memsize") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 0 as i32); assert_eq!(result, 0 as i32);
} }
// Line 14 // Line 14
#[test]
fn test_module_6() {
let result_object = create_module_6();
// We group the calls together
l13_assert_return_invoke(&result_object);
}
fn create_module_7() -> ResultObject { fn create_module_7() -> ResultObject {
let module_str = "(module let module_str = "(module
(type (;0;) (func (result i32))) (type (;0;) (func (result i32)))
@ -127,25 +135,22 @@ fn create_module_7() -> ResultObject {
(data (i32.const 0) \"x\")) (data (i32.const 0) \"x\"))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 15 // Line 15
#[test] fn l15_assert_return_invoke(result_object: &ResultObject) {
fn l15_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("memsize") {
let ResultObject { mut instance, module } = create_module_7();
let func_index = match module.info.exports.get("memsize") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) -> i32 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, 1 as i32); assert_eq!(result, 1 as i32);
} }
// Line 17 // Line 17
#[test] #[test]
fn l17_assert_invalid() { fn l17_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 6, 1, 0, 65, 0, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 6, 1, 0, 65, 0, 11, 0];
@ -154,7 +159,6 @@ fn l17_assert_invalid() {
} }
// Line 18 // Line 18
#[test] #[test]
fn l18_assert_invalid() { fn l18_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 6, 1, 0, 65, 0, 11, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 6, 1, 0, 65, 0, 11, 0];
@ -163,7 +167,6 @@ fn l18_assert_invalid() {
} }
// Line 19 // Line 19
#[test] #[test]
fn l19_assert_invalid() { fn l19_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 7, 1, 0, 65, 0, 11, 1, 120]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 11, 7, 1, 0, 65, 0, 11, 1, 120];
@ -172,7 +175,6 @@ fn l19_assert_invalid() {
} }
// Line 22 // Line 22
#[test] #[test]
fn l22_assert_invalid() { fn l22_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 42, 2, 0, 26, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 42, 2, 0, 26, 11];
@ -181,7 +183,6 @@ fn l22_assert_invalid() {
} }
// Line 26 // Line 26
#[test] #[test]
fn l26_assert_invalid() { fn l26_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 0, 67, 0, 0, 0, 0, 65, 0, 56, 2, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 0, 67, 0, 0, 0, 0, 65, 0, 56, 2, 0, 11];
@ -190,7 +191,6 @@ fn l26_assert_invalid() {
} }
// Line 30 // Line 30
#[test] #[test]
fn l30_assert_invalid() { fn l30_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 44, 0, 0, 26, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 0, 65, 0, 44, 0, 0, 26, 11];
@ -199,7 +199,6 @@ fn l30_assert_invalid() {
} }
// Line 34 // Line 34
#[test] #[test]
fn l34_assert_invalid() { fn l34_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 11, 1, 9, 0, 65, 0, 65, 0, 58, 0, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 11, 1, 9, 0, 65, 0, 65, 0, 58, 0, 0, 11];
@ -208,7 +207,6 @@ fn l34_assert_invalid() {
} }
// Line 38 // Line 38
#[test] #[test]
fn l38_assert_invalid() { fn l38_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 63, 0, 26, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 63, 0, 26, 11];
@ -217,7 +215,6 @@ fn l38_assert_invalid() {
} }
// Line 42 // Line 42
#[test] #[test]
fn l42_assert_invalid() { fn l42_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, 64, 0, 26, 11]; 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, 64, 0, 26, 11];
@ -226,7 +223,6 @@ fn l42_assert_invalid() {
} }
// Line 48 // Line 48
#[test] #[test]
fn l48_assert_invalid() { fn l48_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 4, 1, 1, 1, 0]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 4, 1, 1, 1, 0];
@ -235,7 +231,6 @@ fn l48_assert_invalid() {
} }
// Line 52 // Line 52
#[test] #[test]
fn l52_assert_invalid() { fn l52_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 5, 1, 0, 129, 128, 4]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 5, 1, 0, 129, 128, 4];
@ -244,7 +239,6 @@ fn l52_assert_invalid() {
} }
// Line 56 // Line 56
#[test] #[test]
fn l56_assert_invalid() { fn l56_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 7, 1, 0, 128, 128, 128, 128, 8]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 7, 1, 0, 128, 128, 128, 128, 8];
@ -253,7 +247,6 @@ fn l56_assert_invalid() {
} }
// Line 60 // Line 60
#[test] #[test]
fn l60_assert_invalid() { fn l60_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 7, 1, 0, 255, 255, 255, 255, 15]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 7, 1, 0, 255, 255, 255, 255, 15];
@ -262,7 +255,6 @@ fn l60_assert_invalid() {
} }
// Line 64 // Line 64
#[test] #[test]
fn l64_assert_invalid() { fn l64_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 6, 1, 1, 0, 129, 128, 4]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 6, 1, 1, 0, 129, 128, 4];
@ -271,7 +263,6 @@ fn l64_assert_invalid() {
} }
// Line 68 // Line 68
#[test] #[test]
fn l68_assert_invalid() { fn l68_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 8, 1, 1, 0, 128, 128, 128, 128, 8]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 8, 1, 1, 0, 128, 128, 128, 128, 8];
@ -280,10 +271,16 @@ fn l68_assert_invalid() {
} }
// Line 72 // Line 72
#[test] #[test]
fn l72_assert_invalid() { fn l72_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 8, 1, 1, 0, 255, 255, 255, 255, 15]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 5, 8, 1, 1, 0, 255, 255, 255, 255, 15];
let compilation = compile(wasm_binary.to_vec()); let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid"); assert!(compilation.is_err(), "WASM should not compile as is invalid");
} }
#[test]
fn test_module_7() {
let result_object = create_module_7();
// We group the calls together
l15_assert_return_invoke(&result_object);
}

View File

@ -4,6 +4,7 @@
// The _common module is not autogenerated, as it provides common functions for the spectests // The _common module is not autogenerated, as it provides common functions for the spectests
mod _common; mod _common;
mod br_if; mod br_if;
mod br_table;
mod call; mod call;
mod call_indirect; mod call_indirect;
mod func_ptrs; mod func_ptrs;

View File

@ -1,8 +1,8 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs). // 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. // Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/set_local.wast // Test based on spectests/set_local.wast
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject;
use wabt::wat2wasm; use wabt::wat2wasm;
@ -115,151 +115,130 @@ fn create_module_1() -> ResultObject {
(export \"write\" (func 9))) (export \"write\" (func 9)))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 68 // Line 68
#[test] fn l68_assert_return_invoke(result_object: &ResultObject) {
fn l68_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-local-i32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-local-i32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 69 // Line 69
#[test] fn l69_assert_return_invoke(result_object: &ResultObject) {
fn l69_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-local-i64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-local-i64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 70 // Line 70
#[test] fn l70_assert_return_invoke(result_object: &ResultObject) {
fn l70_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-local-f32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-local-f32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 71 // Line 71
#[test] fn l71_assert_return_invoke(result_object: &ResultObject) {
fn l71_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-local-f64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-local-f64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(&VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(&VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(&vm_context); let result = invoke_fn(&vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 73 // Line 73
#[test] fn l73_assert_return_invoke(result_object: &ResultObject) {
fn l73_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-param-i32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-param-i32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i32, &VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(i32, &VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(2 as i32, &vm_context); let result = invoke_fn(2 as i32, &vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 74 // Line 74
#[test] fn l74_assert_return_invoke(result_object: &ResultObject) {
fn l74_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-param-i64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-param-i64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, &VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, &VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(3 as i64, &vm_context); let result = invoke_fn(3 as i64, &vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 75 // Line 75
#[test] fn l75_assert_return_invoke(result_object: &ResultObject) {
fn l75_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-param-f32") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-param-f32") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(f32, &VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(f32, &VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(4.4 as f32, &vm_context); let result = invoke_fn(4.4 as f32, &vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 76 // Line 76
#[test] fn l76_assert_return_invoke(result_object: &ResultObject) {
fn l76_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-param-f64") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-param-f64") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(f64, &VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(f64, &VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(5.5 as f64, &vm_context); let result = invoke_fn(5.5 as f64, &vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 79 // Line 79
#[test] fn l79_assert_return_invoke(result_object: &ResultObject) {
fn l79_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("type-mixed") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("type-mixed") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, 2.2 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context); let result = invoke_fn(1 as i64, 2.2 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context);
assert_eq!(result, ()); assert_eq!(result, ());
} }
// Line 85 // Line 85
#[test] fn l85_assert_return_invoke(result_object: &ResultObject) {
fn l85_assert_return_invoke() { let func_index = match result_object.module.info.exports.get("write") {
let ResultObject { mut instance, module } = create_module_1();
let func_index = match module.info.exports.get("write") {
Some(&Export::Function(index)) => index, Some(&Export::Function(index)) => index,
_ => panic!("Function not found"), _ => panic!("Function not found"),
}; };
let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) -> i64 = get_instance_function!(instance, func_index); let invoke_fn: fn(i64, f32, f64, i32, i32, &VmCtx) -> i64 = get_instance_function!(result_object.instance, func_index);
let vm_context = instance.generate_context(); let vm_context = result_object.instance.generate_context();
let result = invoke_fn(1 as i64, 2.0 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context); let result = invoke_fn(1 as i64, 2.0 as f32, 3.3 as f64, 4 as i32, 5 as i32, &vm_context);
assert_eq!(result, 56 as i64); assert_eq!(result, 56 as i64);
} }
// Line 95 // Line 95
#[test] #[test]
fn l95_assert_invalid() { fn l95_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 126, 3, 2, 1, 0, 10, 10, 1, 8, 1, 1, 127, 65, 0, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 126, 3, 2, 1, 0, 10, 10, 1, 8, 1, 1, 127, 65, 0, 33, 0, 11];
@ -268,7 +247,6 @@ fn l95_assert_invalid() {
} }
// Line 101 // Line 101
#[test] #[test]
fn l101_assert_invalid() { fn l101_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 1, 1, 125, 67, 0, 0, 0, 0, 33, 0, 69, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 1, 1, 125, 67, 0, 0, 0, 0, 33, 0, 69, 11];
@ -277,7 +255,6 @@ fn l101_assert_invalid() {
} }
// Line 107 // Line 107
#[test] #[test]
fn l107_assert_invalid() { fn l107_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 124, 1, 126, 66, 0, 33, 1, 154, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 124, 1, 126, 66, 0, 33, 1, 154, 11];
@ -286,7 +263,6 @@ fn l107_assert_invalid() {
} }
// Line 114 // Line 114
#[test] #[test]
fn l114_assert_invalid() { fn l114_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, 1, 1, 127, 1, 33, 0, 11]; 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, 1, 1, 127, 1, 33, 0, 11];
@ -295,7 +271,6 @@ fn l114_assert_invalid() {
} }
// Line 118 // Line 118
#[test] #[test]
fn l118_assert_invalid() { fn l118_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 33, 0, 11];
@ -304,7 +279,6 @@ fn l118_assert_invalid() {
} }
// Line 122 // Line 122
#[test] #[test]
fn l122_assert_invalid() { fn l122_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 17, 1, 15, 1, 1, 125, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 17, 1, 15, 1, 1, 125, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 11];
@ -313,7 +287,6 @@ fn l122_assert_invalid() {
} }
// Line 126 // Line 126
#[test] #[test]
fn l126_assert_invalid() { fn l126_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 19, 1, 17, 2, 1, 124, 1, 126, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 19, 1, 17, 2, 1, 124, 1, 126, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 1, 11];
@ -322,7 +295,6 @@ fn l126_assert_invalid() {
} }
// Line 134 // Line 134
#[test] #[test]
fn l134_assert_invalid() { fn l134_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 126, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 126, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 0, 11];
@ -331,7 +303,6 @@ fn l134_assert_invalid() {
} }
// Line 138 // Line 138
#[test] #[test]
fn l138_assert_invalid() { fn l138_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 0, 69, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 0, 69, 11];
@ -340,7 +311,6 @@ fn l138_assert_invalid() {
} }
// Line 142 // Line 142
#[test] #[test]
fn l142_assert_invalid() { fn l142_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 1, 154, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 32, 1, 154, 11];
@ -349,7 +319,6 @@ fn l142_assert_invalid() {
} }
// Line 147 // Line 147
#[test] #[test]
fn l147_assert_invalid() { fn l147_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 1, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 7, 1, 5, 0, 1, 33, 0, 11];
@ -358,7 +327,6 @@ fn l147_assert_invalid() {
} }
// Line 151 // Line 151
#[test] #[test]
fn l151_assert_invalid() { fn l151_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 11, 1, 9, 0, 67, 0, 0, 0, 0, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 11, 1, 9, 0, 67, 0, 0, 0, 0, 33, 0, 11];
@ -367,7 +335,6 @@ fn l151_assert_invalid() {
} }
// Line 155 // Line 155
#[test] #[test]
fn l155_assert_invalid() { fn l155_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 11];
@ -376,7 +343,6 @@ fn l155_assert_invalid() {
} }
// Line 159 // Line 159
#[test] #[test]
fn l159_assert_invalid() { fn l159_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 124, 126, 0, 3, 2, 1, 0, 10, 15, 1, 13, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 33, 1, 11];
@ -385,7 +351,6 @@ fn l159_assert_invalid() {
} }
// Line 167 // Line 167
#[test] #[test]
fn l167_assert_invalid() { fn l167_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11];
@ -394,7 +359,6 @@ fn l167_assert_invalid() {
} }
// Line 171 // Line 171
#[test] #[test]
fn l171_assert_invalid() { fn l171_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 164, 234, 6, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 164, 234, 6, 11];
@ -403,7 +367,6 @@ fn l171_assert_invalid() {
} }
// Line 176 // Line 176
#[test] #[test]
fn l176_assert_invalid() { fn l176_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 127, 126, 0, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 2, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 127, 126, 0, 3, 2, 1, 0, 10, 6, 1, 4, 0, 32, 2, 11];
@ -412,7 +375,6 @@ fn l176_assert_invalid() {
} }
// Line 180 // Line 180
#[test] #[test]
fn l180_assert_invalid() { fn l180_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 2, 1, 127, 1, 126, 32, 247, 242, 206, 212, 2, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 14, 1, 12, 2, 1, 127, 1, 126, 32, 247, 242, 206, 212, 2, 11];
@ -421,7 +383,6 @@ fn l180_assert_invalid() {
} }
// Line 185 // Line 185
#[test] #[test]
fn l185_assert_invalid() { fn l185_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 127, 0, 3, 2, 1, 0, 10, 10, 1, 8, 2, 1, 127, 1, 126, 32, 3, 11];
@ -430,7 +391,6 @@ fn l185_assert_invalid() {
} }
// Line 189 // Line 189
#[test] #[test]
fn l189_assert_invalid() { fn l189_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 168, 153, 102, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 13, 1, 11, 2, 1, 127, 1, 126, 32, 247, 168, 153, 102, 11];
@ -439,7 +399,6 @@ fn l189_assert_invalid() {
} }
// Line 194 // Line 194
#[test] #[test]
fn l194_assert_invalid() { fn l194_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 33, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 125, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 127, 67, 0, 0, 0, 0, 33, 1, 11];
@ -448,7 +407,6 @@ fn l194_assert_invalid() {
} }
// Line 198 // Line 198
#[test] #[test]
fn l198_assert_invalid() { fn l198_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 126, 127, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 125, 67, 0, 0, 0, 0, 33, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 2, 126, 127, 0, 3, 2, 1, 0, 10, 13, 1, 11, 1, 1, 125, 67, 0, 0, 0, 0, 33, 1, 11];
@ -457,10 +415,25 @@ fn l198_assert_invalid() {
} }
// Line 202 // Line 202
#[test] #[test]
fn l202_assert_invalid() { fn l202_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 12, 1, 10, 2, 1, 124, 1, 126, 66, 0, 33, 1, 11]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 1, 126, 0, 3, 2, 1, 0, 10, 12, 1, 10, 2, 1, 124, 1, 126, 66, 0, 33, 1, 11];
let compilation = compile(wasm_binary.to_vec()); let compilation = compile(wasm_binary.to_vec());
assert!(compilation.is_err(), "WASM should not compile as is invalid"); assert!(compilation.is_err(), "WASM should not compile as is invalid");
} }
#[test]
fn test_module_1() {
let result_object = create_module_1();
// We group the calls together
l68_assert_return_invoke(&result_object);
l69_assert_return_invoke(&result_object);
l70_assert_return_invoke(&result_object);
l71_assert_return_invoke(&result_object);
l73_assert_return_invoke(&result_object);
l74_assert_return_invoke(&result_object);
l75_assert_return_invoke(&result_object);
l76_assert_return_invoke(&result_object);
l79_assert_return_invoke(&result_object);
l85_assert_return_invoke(&result_object);
}

View File

@ -1,8 +1,8 @@
// Rust test file autogenerated with cargo build (src/build_spectests.rs). // 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. // Please do NOT modify it by hand, as it will be reseted on next build.
// Test based on spectests/types.wast // Test based on spectests/types.wast
use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export}; use crate::webassembly::{instantiate, compile, ImportObject, ResultObject, VmCtx, Export};
use super::_common::spectest_importobject;
use wabt::wat2wasm; use wabt::wat2wasm;
@ -25,11 +25,10 @@ fn create_module_1() -> ResultObject {
(type (;13;) (func (param f32 f64 i32)))) (type (;13;) (func (param f32 f64 i32))))
"; ";
let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed");
instantiate(wasm_binary, ImportObject::new()).expect("WASM can't be instantiated") instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated")
} }
// Line 44 // Line 44
#[test] #[test]
fn l44_assert_malformed() { fn l44_assert_malformed() {
let wasm_binary = [40, 116, 121, 112, 101, 32, 40, 102, 117, 110, 99, 32, 40, 114, 101, 115, 117, 108, 116, 32, 105, 51, 50, 41, 32, 40, 112, 97, 114, 97, 109, 32, 105, 51, 50, 41, 41, 41]; let wasm_binary = [40, 116, 121, 112, 101, 32, 40, 102, 117, 110, 99, 32, 40, 114, 101, 115, 117, 108, 116, 32, 105, 51, 50, 41, 32, 40, 112, 97, 114, 97, 109, 32, 105, 51, 50, 41, 41, 41];
@ -38,7 +37,6 @@ fn l44_assert_malformed() {
} }
// Line 48 // Line 48
#[test] #[test]
fn l48_assert_malformed() { fn l48_assert_malformed() {
let wasm_binary = [40, 116, 121, 112, 101, 32, 40, 102, 117, 110, 99, 32, 40, 114, 101, 115, 117, 108, 116, 32, 36, 120, 32, 105, 51, 50, 41, 41, 41]; let wasm_binary = [40, 116, 121, 112, 101, 32, 40, 102, 117, 110, 99, 32, 40, 114, 101, 115, 117, 108, 116, 32, 36, 120, 32, 105, 51, 50, 41, 41, 41];
@ -47,7 +45,6 @@ fn l48_assert_malformed() {
} }
// Line 53 // Line 53
#[test] #[test]
fn l53_assert_invalid() { fn l53_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 0, 2, 127, 127]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 0, 2, 127, 127];
@ -56,7 +53,6 @@ fn l53_assert_invalid() {
} }
// Line 57 // Line 57
#[test] #[test]
fn l57_assert_invalid() { fn l57_assert_invalid() {
let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 0, 2, 127, 127]; let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 0, 2, 127, 127];

View File

@ -152,6 +152,7 @@ impl Instance {
let mut import_functions: Vec<*const u8> = Vec::new(); let mut import_functions: Vec<*const u8> = Vec::new();
// let mut code_base: *const () = ptr::null(); // let mut code_base: *const () = ptr::null();
debug!("Instance - Instantiating functions");
// Instantiate functions // Instantiate functions
{ {
functions.reserve_exact(module.info.functions.len()); functions.reserve_exact(module.info.functions.len());
@ -177,6 +178,7 @@ impl Instance {
import_functions.push(function); import_functions.push(function);
relocations.push(vec![]); relocations.push(vec![]);
} }
debug!("Instance - Compiling functions");
// Compile the functions (from cranelift IR to machine code) // Compile the functions (from cranelift IR to machine code)
for function_body in module.info.function_bodies.values() { for function_body in module.info.function_bodies.values() {
let mut func_context = Context::for_function(function_body.to_owned()); let mut func_context = Context::for_function(function_body.to_owned());
@ -209,6 +211,7 @@ impl Instance {
// total_size += code_size_offset; // total_size += code_size_offset;
} }
debug!("Instance - Relocating functions");
// For each of the functions used, we see what are the calls inside this functions // For each of the functions used, we see what are the calls inside this functions
// and relocate each call to the proper memory address. // and relocate each call to the proper memory address.
// The relocations are relative to the relocation's address plus four bytes // The relocations are relative to the relocation's address plus four bytes
@ -343,6 +346,7 @@ impl Instance {
// } // }
} }
debug!("Instance - Instantiating tables");
// Instantiate tables // Instantiate tables
{ {
// Reserve table space // Reserve table space
@ -375,6 +379,7 @@ impl Instance {
} }
} }
debug!("Instance - Instantiating memories");
// Instantiate memories // Instantiate memories
{ {
// Allocate the underlying memory and initialize it to all zeros. // Allocate the underlying memory and initialize it to all zeros.
@ -401,6 +406,7 @@ impl Instance {
} }
} }
debug!("Instance - Instantiating globals");
// Instantiate Globals // Instantiate Globals
{ {
let globals_count = module.info.globals.len(); let globals_count = module.info.globals.len();
@ -504,7 +510,7 @@ impl Instance {
} }
} }
pub fn generate_context(&mut self) -> VmCtx { pub fn generate_context(&self) -> VmCtx {
let memories: Vec<UncheckedSlice<u8>> = let memories: Vec<UncheckedSlice<u8>> =
self.memories.iter().map(|mem| mem[..].into()).collect(); self.memories.iter().map(|mem| mem[..].into()).collect();
let tables: Vec<BoundedSlice<usize>> = let tables: Vec<BoundedSlice<usize>> =