Update tests to use new API where easily possible

This commit is contained in:
Mark McCaskey 2020-04-09 11:47:00 -07:00
parent 3474c31355
commit a149c9aaeb
10 changed files with 87 additions and 64 deletions

View File

@ -58,7 +58,7 @@ pub mod memory {
} }
pub mod wasm { pub mod wasm {
//! Various types exposed by the Wasmer Runtime. //! Various types exposed by the Wasmer Runtime relating to Wasm.
//! //!
//! TODO: Add index with links to sub sections //! TODO: Add index with links to sub sections
//! //!
@ -66,15 +66,25 @@ pub mod wasm {
//! //!
//! # Tables //! # Tables
pub use wasmer_runtime_core::global::Global; pub use wasmer_runtime_core::global::Global;
pub use wasmer_runtime_core::instance::{DynFunc, Instance};
pub use wasmer_runtime_core::memory::Memory;
pub use wasmer_runtime_core::table::Table; pub use wasmer_runtime_core::table::Table;
pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor, ImportDescriptor}; pub use wasmer_runtime_core::types::{ExportDescriptor, ExternDescriptor, ImportDescriptor};
pub use wasmer_runtime_core::types::{ pub use wasmer_runtime_core::types::{
FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type, Value, FuncSig, GlobalDescriptor, MemoryDescriptor, TableDescriptor, Type, Value,
}; };
pub use wasmer_runtime_core::Func;
} }
pub mod vm {
//! Various types exposed by the Wasmer Runtime relating to the VM.
pub use wasmer_runtime_core::vm::Ctx;
}
// TODO: `import` or `imports`?
pub mod import { pub mod import {
//! Types and functions for Wasm imports. //! Types and functions for Wasm imports.
pub use wasmer_runtime_core::import::{ImportObject, LikeNamespace, Namespace};
pub use wasmer_runtime_core::types::{ExternDescriptor, ImportDescriptor}; pub use wasmer_runtime_core::types::{ExternDescriptor, ImportDescriptor};
pub use wasmer_runtime_core::{func, imports}; pub use wasmer_runtime_core::{func, imports};
} }
@ -99,7 +109,11 @@ pub mod types {
pub mod error { pub mod error {
//! Various error types returned by Wasmer APIs. //! Various error types returned by Wasmer APIs.
pub use wasmer_runtime_core::error::{CompileError, CompileResult}; pub use wasmer_runtime_core::backend::ExceptionCode;
pub use wasmer_runtime_core::error::{
CallError, CompileError, CompileResult, CreationError, Error, LinkError, ResolveError,
RuntimeError,
};
#[derive(Debug)] #[derive(Debug)]
pub enum CompileFromFileError { pub enum CompileFromFileError {

View File

@ -2,7 +2,8 @@ mod runtime_core_tests;
pub mod runtime_core_exception_handling { pub mod runtime_core_exception_handling {
use super::runtime_core_tests::{get_compiler, wat2wasm}; use super::runtime_core_tests::{get_compiler, wat2wasm};
use wasmer_runtime_core::{compile_with, imports}; use wasmer::imports;
use wasmer_runtime_core::compile_with;
#[test] #[test]
fn exception_handling_works() { fn exception_handling_works() {

View File

@ -5,17 +5,14 @@ pub mod runtime_core_imports {
use super::runtime_core_tests::{get_compiler, wat2wasm}; use super::runtime_core_tests::{get_compiler, wat2wasm};
use std::{convert::TryInto, sync::Arc}; use std::{convert::TryInto, sync::Arc};
use wasmer_runtime_core::{ use wasmer::error::RuntimeError;
compile_with, use wasmer::imports;
error::RuntimeError, use wasmer::units::Pages;
global::Global, use wasmer::vm;
imports, use wasmer::wasm::{
memory::Memory, DynFunc, Func, FuncSig, Global, Instance, Memory, MemoryDescriptor, Type, Value,
typed_func::{DynamicFunc, Func},
types::{FuncSig, MemoryDescriptor, Type, Value},
units::Pages,
vm, DynFunc, Instance,
}; };
use wasmer_runtime_core::{compile_with, typed_func::DynamicFunc};
#[test] #[test]
fn runtime_core_new_api_works() { fn runtime_core_new_api_works() {

View File

@ -17,8 +17,9 @@ pub fn get_compiler() -> impl Compiler {
LLVMCompiler::new() LLVMCompiler::new()
} }
use wasmer::imports;
use wasmer_llvm_backend::{InkwellModule, LLVMBackendConfig, LLVMCallbacks}; use wasmer_llvm_backend::{InkwellModule, LLVMBackendConfig, LLVMCallbacks};
use wasmer_runtime::{imports, CompilerConfig}; use wasmer_runtime::CompilerConfig;
use wasmer_runtime_core::{backend::BackendCompilerConfig, compile_with, compile_with_config}; use wasmer_runtime_core::{backend::BackendCompilerConfig, compile_with, compile_with_config};
use std::cell::RefCell; use std::cell::RefCell;

View File

@ -2,12 +2,14 @@
mod tests { mod tests {
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer::imports;
use wasmer::wasm::Func;
use wasmer_middleware_common::metering::*; use wasmer_middleware_common::metering::*;
use wasmer_runtime_core::codegen::ModuleCodeGenerator; use wasmer_runtime_core::codegen::ModuleCodeGenerator;
use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler};
use wasmer_runtime_core::fault::{pop_code_version, push_code_version}; use wasmer_runtime_core::fault::{pop_code_version, push_code_version};
use wasmer_runtime_core::state::CodeVersion; use wasmer_runtime_core::state::CodeVersion;
use wasmer_runtime_core::{backend::Compiler, compile_with, imports, Func}; use wasmer_runtime_core::{backend::Compiler, compile_with};
#[cfg(feature = "backend-llvm")] #[cfg(feature = "backend-llvm")]
use wasmer_llvm_backend::ModuleCodeGenerator as MCG; use wasmer_llvm_backend::ModuleCodeGenerator as MCG;

View File

@ -1,5 +1,10 @@
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_runtime::{compile, DynFunc, ImportObject, Instance, Value}; use wasmer::{
import::ImportObject,
wasm::{Instance, Value},
DynFunc,
};
use wasmer_runtime::compile;
#[test] #[test]
fn override_works() { fn override_works() {

View File

@ -271,14 +271,18 @@ mod tests {
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use wabt::script::{Action, Command, CommandKind, ScriptParser, Value}; use wabt::script::{Action, Command, CommandKind, ScriptParser, Value};
use wasmer_runtime::{ use wasmer::{
compile_with_config_with, compiler_for_backend,
error::CompileError, error::CompileError,
func, imports, func,
types::{ElementType, MemoryDescriptor, TableDescriptor}, import::{ImportObject, LikeNamespace},
imports,
types::ElementType,
units::Pages, units::Pages,
Backend, CompilerConfig, Ctx, Export, Features, Global, ImportObject, Instance, vm::Ctx,
LikeNamespace, Memory, Table, wasm::{self, Global, Instance, Memory, MemoryDescriptor, Table, TableDescriptor},
};
use wasmer_runtime::{
compile_with_config_with, compiler_for_backend, Backend, CompilerConfig, Export, Features,
}; };
fn format_panic(e: &dyn std::any::Any) -> String { fn format_panic(e: &dyn std::any::Any) -> String {
@ -416,7 +420,7 @@ mod tests {
&named_modules, &named_modules,
&module, &module,
|instance| { |instance| {
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}, },
@ -548,7 +552,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -619,7 +623,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -721,7 +725,7 @@ mod tests {
} else { } else {
false false
}; };
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
let ret = instance.call(&field, &params[..]); let ret = instance.call(&field, &params[..]);
#[cfg(unix)] #[cfg(unix)]
@ -746,7 +750,7 @@ mod tests {
); );
} else { } else {
let call_result = maybe_call_result.unwrap(); let call_result = maybe_call_result.unwrap();
use wasmer_runtime::error::{CallError, RuntimeError}; use wasmer::error::{CallError, RuntimeError};
match call_result { match call_result {
Err(e) => match e { Err(e) => match e {
CallError::Resolve(_) => { CallError::Resolve(_) => {
@ -763,7 +767,7 @@ mod tests {
); );
} }
CallError::Runtime(RuntimeError(e)) => { CallError::Runtime(RuntimeError(e)) => {
use wasmer_runtime::ExceptionCode; use wasmer::error::ExceptionCode;
if let Some(_) = e.downcast_ref::<ExceptionCode>() { if let Some(_) = e.downcast_ref::<ExceptionCode>() {
test_report.count_passed(); test_report.count_passed();
} else { } else {
@ -964,7 +968,7 @@ mod tests {
&named_modules, &named_modules,
&module, &module,
|instance| { |instance| {
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}, },
@ -1061,7 +1065,7 @@ mod tests {
); );
} }
Err(e) => match e { Err(e) => match e {
wasmer_runtime::error::Error::LinkError(_) => { wasmer::error::Error::LinkError(_) => {
test_report.count_passed(); test_report.count_passed();
} }
_ => { _ => {
@ -1120,7 +1124,7 @@ mod tests {
} => { } => {
let maybe_call_result = let maybe_call_result =
with_instance(instance.clone(), &named_modules, &module, |instance| { with_instance(instance.clone(), &named_modules, &module, |instance| {
let params: Vec<wasmer_runtime::types::Value> = let params: Vec<wasm::Value> =
args.iter().cloned().map(convert_value).collect(); args.iter().cloned().map(convert_value).collect();
instance.call(&field, &params[..]) instance.call(&field, &params[..])
}); });
@ -1183,29 +1187,29 @@ mod tests {
Ok(test_report) Ok(test_report)
} }
fn is_canonical_nan(val: wasmer_runtime::types::Value) -> bool { fn is_canonical_nan(val: wasm::Value) -> bool {
match val { match val {
wasmer_runtime::types::Value::F32(x) => x.is_canonical_nan(), wasm::Value::F32(x) => x.is_canonical_nan(),
wasmer_runtime::types::Value::F64(x) => x.is_canonical_nan(), wasm::Value::F64(x) => x.is_canonical_nan(),
_ => panic!("value is not a float {:?}", val), _ => panic!("value is not a float {:?}", val),
} }
} }
fn is_arithmetic_nan(val: wasmer_runtime::types::Value) -> bool { fn is_arithmetic_nan(val: wasm::Value) -> bool {
match val { match val {
wasmer_runtime::types::Value::F32(x) => x.is_quiet_nan(), wasm::Value::F32(x) => x.is_quiet_nan(),
wasmer_runtime::types::Value::F64(x) => x.is_quiet_nan(), wasm::Value::F64(x) => x.is_quiet_nan(),
_ => panic!("value is not a float {:?}", val), _ => panic!("value is not a float {:?}", val),
} }
} }
fn value_to_hex(val: wasmer_runtime::types::Value) -> String { fn value_to_hex(val: wasm::Value) -> String {
match val { match val {
wasmer_runtime::types::Value::I32(x) => format!("{:#x}", x), wasm::Value::I32(x) => format!("{:#x}", x),
wasmer_runtime::types::Value::I64(x) => format!("{:#x}", x), wasm::Value::I64(x) => format!("{:#x}", x),
wasmer_runtime::types::Value::F32(x) => format!("{:#x}", x.to_bits()), wasm::Value::F32(x) => format!("{:#x}", x.to_bits()),
wasmer_runtime::types::Value::F64(x) => format!("{:#x}", x.to_bits()), wasm::Value::F64(x) => format!("{:#x}", x.to_bits()),
wasmer_runtime::types::Value::V128(x) => format!("{:#x}", x), wasm::Value::V128(x) => format!("{:#x}", x),
} }
} }
@ -1218,13 +1222,13 @@ mod tests {
V128(u128), V128(u128),
} }
fn convert_wasmer_value(other: wasmer_runtime::types::Value) -> SpectestValue { fn convert_wasmer_value(other: wasm::Value) -> SpectestValue {
match other { match other {
wasmer_runtime::types::Value::I32(v) => SpectestValue::I32(v), wasm::Value::I32(v) => SpectestValue::I32(v),
wasmer_runtime::types::Value::I64(v) => SpectestValue::I64(v), wasm::Value::I64(v) => SpectestValue::I64(v),
wasmer_runtime::types::Value::F32(v) => SpectestValue::F32(v.to_bits()), wasm::Value::F32(v) => SpectestValue::F32(v.to_bits()),
wasmer_runtime::types::Value::F64(v) => SpectestValue::F64(v.to_bits()), wasm::Value::F64(v) => SpectestValue::F64(v.to_bits()),
wasmer_runtime::types::Value::V128(v) => SpectestValue::V128(v), wasm::Value::V128(v) => SpectestValue::V128(v),
} }
} }
@ -1238,13 +1242,13 @@ mod tests {
} }
} }
fn convert_value(other: Value<f32, f64>) -> wasmer_runtime::types::Value { fn convert_value(other: Value<f32, f64>) -> wasm::Value {
match other { match other {
Value::I32(v) => wasmer_runtime::types::Value::I32(v), Value::I32(v) => wasm::Value::I32(v),
Value::I64(v) => wasmer_runtime::types::Value::I64(v), Value::I64(v) => wasm::Value::I64(v),
Value::F32(v) => wasmer_runtime::types::Value::F32(v), Value::F32(v) => wasm::Value::F32(v),
Value::F64(v) => wasmer_runtime::types::Value::F64(v), Value::F64(v) => wasm::Value::F64(v),
Value::V128(v) => wasmer_runtime::types::Value::V128(v), Value::V128(v) => wasm::Value::V128(v),
} }
} }
@ -1288,9 +1292,9 @@ mod tests {
let memory_desc = MemoryDescriptor::new(Pages(1), Some(Pages(2)), false).unwrap(); let memory_desc = MemoryDescriptor::new(Pages(1), Some(Pages(2)), false).unwrap();
let memory = Memory::new(memory_desc).unwrap(); let memory = Memory::new(memory_desc).unwrap();
let global_i32 = Global::new(wasmer_runtime::types::Value::I32(666)); let global_i32 = Global::new(wasm::Value::I32(666));
let global_f32 = Global::new(wasmer_runtime::types::Value::F32(666.0)); let global_f32 = Global::new(wasm::Value::F32(666.0));
let global_f64 = Global::new(wasmer_runtime::types::Value::F64(666.0)); let global_f64 = Global::new(wasm::Value::F64(666.0));
let table = Table::new(TableDescriptor { let table = Table::new(TableDescriptor {
element: ElementType::Anyfunc, element: ElementType::Anyfunc,

View File

@ -1,10 +1,8 @@
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use wabt::wat2wasm; use wabt::wat2wasm;
use wasmer_runtime::{ use wasmer::error::{CallError, ExceptionCode, RuntimeError};
error::{CallError, RuntimeError}, use wasmer::import::ImportObject;
ExceptionCode, ImportObject,
};
// The semantics of stack overflow are documented at: // The semantics of stack overflow are documented at:
// https://webassembly.org/docs/semantics/#stack-overflow // https://webassembly.org/docs/semantics/#stack-overflow

View File

@ -1,5 +1,6 @@
#![cfg(test)] #![cfg(test)]
use wasmer_runtime::{compile, Ctx, Func}; use wasmer::{vm::Ctx, Func};
use wasmer_runtime::compile;
use wasmer_wasi::{state::*, *}; use wasmer_wasi::{state::*, *};
use std::ffi::c_void; use std::ffi::c_void;

View File

@ -33,7 +33,7 @@ pub fn get_backend() -> Option<Backend> {
macro_rules! assert_wasi_output { macro_rules! assert_wasi_output {
($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{
use crate::dev_utils::stdio::StdioCapturer; use crate::dev_utils::stdio::StdioCapturer;
use wasmer_runtime::Func; use wasmer::Func;
use wasmer_wasi::{generate_import_object_for_version, get_wasi_version}; use wasmer_wasi::{generate_import_object_for_version, get_wasi_version};
let wasm_bytes = include_bytes!($file); let wasm_bytes = include_bytes!($file);