mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-29 22:51:56 +00:00
Fix wasm tests
This commit is contained in:
@ -113,4 +113,8 @@ impl ProgramInstance {
|
|||||||
pub fn store(&self) -> &Store {
|
pub fn store(&self) -> &Store {
|
||||||
&self.store
|
&self.store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn module(&self, name: &str) -> Option<ModuleId> {
|
||||||
|
self.modules.get(name).cloned()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
mod basics;
|
mod basics;
|
||||||
mod wabt;
|
mod wabt;
|
||||||
// mod wasm;
|
mod wasm;
|
||||||
|
|
||||||
mod utils {
|
mod utils {
|
||||||
use elements::{Internal, ExportEntry, InitExpr, Opcode, ValueType, GlobalType, GlobalEntry};
|
use elements::{Internal, ExportEntry, InitExpr, Opcode, ValueType, GlobalType, GlobalEntry};
|
||||||
|
@ -2,7 +2,7 @@ use elements::deserialize_file;
|
|||||||
use elements::Module;
|
use elements::Module;
|
||||||
use interpreter::ExecutionParams;
|
use interpreter::ExecutionParams;
|
||||||
use interpreter::value::RuntimeValue;
|
use interpreter::value::RuntimeValue;
|
||||||
use interpreter::module::{ModuleInstanceInterface, ItemIndex};
|
use interpreter::module::{ItemIndex};
|
||||||
use super::utils::program_with_default_env;
|
use super::utils::program_with_default_env;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -12,7 +12,7 @@ fn interpreter_inc_i32() {
|
|||||||
// The WASM file containing the module and function
|
// The WASM file containing the module and function
|
||||||
const WASM_FILE: &str = &"res/cases/v1/inc_i32.wasm";
|
const WASM_FILE: &str = &"res/cases/v1/inc_i32.wasm";
|
||||||
|
|
||||||
let program = program_with_default_env();
|
let mut program = program_with_default_env();
|
||||||
|
|
||||||
let module: Module =
|
let module: Module =
|
||||||
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
||||||
@ -20,17 +20,13 @@ fn interpreter_inc_i32() {
|
|||||||
// the functions expects a single i32 parameter
|
// the functions expects a single i32 parameter
|
||||||
let args = vec![RuntimeValue::I32(i32_val)];
|
let args = vec![RuntimeValue::I32(i32_val)];
|
||||||
let exp_retval = Some(RuntimeValue::I32(i32_val + 1));
|
let exp_retval = Some(RuntimeValue::I32(i32_val + 1));
|
||||||
let execution_params = ExecutionParams::from(args);
|
|
||||||
|
|
||||||
let module_result = program
|
let module_result = program.add_module("main", module, &mut ());
|
||||||
.add_module("main", module, None);
|
|
||||||
|
|
||||||
let module = module_result
|
let module = module_result
|
||||||
.expect("Failed to initialize module");
|
.expect("Failed to initialize module");
|
||||||
|
|
||||||
let retval = module
|
let retval = program.invoke_export("main", FUNCTION_NAME, args, &mut ()).expect("");
|
||||||
.execute_export(FUNCTION_NAME, execution_params)
|
|
||||||
.expect("");
|
|
||||||
assert_eq!(exp_retval, retval);
|
assert_eq!(exp_retval, retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,29 +39,26 @@ fn interpreter_accumulate_u8() {
|
|||||||
// The octet sequence being accumulated
|
// The octet sequence being accumulated
|
||||||
const BUF: &[u8] = &[9,8,7,6,5,4,3,2,1];
|
const BUF: &[u8] = &[9,8,7,6,5,4,3,2,1];
|
||||||
|
|
||||||
let program = program_with_default_env();
|
let mut program = program_with_default_env();
|
||||||
|
|
||||||
// Load the module-structure from wasm-file and add to program
|
// Load the module-structure from wasm-file and add to program
|
||||||
let module: Module =
|
let module: Module =
|
||||||
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
deserialize_file(WASM_FILE).expect("Failed to deserialize module from buffer");
|
||||||
let module = program
|
let module = program
|
||||||
.add_module("main", module, None)
|
.add_module("main", module, &mut ())
|
||||||
.expect("Failed to initialize module");
|
.expect("Failed to initialize module");
|
||||||
|
|
||||||
// => env module is created
|
let env_module = program.module("env").unwrap();
|
||||||
let env_instance = program.module("env").unwrap();
|
let env_memory = env_module.memory_by_index(program.store(), 0).unwrap();
|
||||||
// => linear memory is created
|
|
||||||
let env_memory = env_instance.memory(ItemIndex::Internal(0)).unwrap();
|
|
||||||
|
|
||||||
// Place the octet-sequence at index 0 in linear memory
|
// Place the octet-sequence at index 0 in linear memory
|
||||||
let offset: u32 = 0;
|
let offset: u32 = 0;
|
||||||
let _ = env_memory.set(offset, BUF);
|
let _ = env_memory.resolve(program.store()).set(offset, BUF);
|
||||||
|
|
||||||
// Set up the function argument list and invoke the function
|
// Set up the function argument list and invoke the function
|
||||||
let args = vec![RuntimeValue::I32(BUF.len() as i32), RuntimeValue::I32(offset as i32)];
|
let args = vec![RuntimeValue::I32(BUF.len() as i32), RuntimeValue::I32(offset as i32)];
|
||||||
let execution_params = ExecutionParams::from(args);
|
let retval = program
|
||||||
let retval = module
|
.invoke_export("main", FUNCTION_NAME, args, &mut ())
|
||||||
.execute_export(FUNCTION_NAME, execution_params)
|
|
||||||
.expect("Failed to execute function");
|
.expect("Failed to execute function");
|
||||||
|
|
||||||
// For verification, repeat accumulation using native code
|
// For verification, repeat accumulation using native code
|
||||||
|
Reference in New Issue
Block a user