From a149c9aaeb6a15f9044f2ae6f9e952bacf5ea15c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Thu, 9 Apr 2020 11:47:00 -0700 Subject: [PATCH] Update tests to use new API where easily possible --- lib/api/src/lib.rs | 18 +++++++- tests/exception_handling.rs | 3 +- tests/imports.rs | 17 +++---- tests/llvm_compile.rs | 3 +- tests/middleware_common.rs | 4 +- tests/override.rs | 7 ++- tests/spectest.rs | 88 +++++++++++++++++++------------------ tests/spectest_semantics.rs | 6 +-- tests/wasi_serialization.rs | 3 +- tests/wasitests/_common.rs | 2 +- 10 files changed, 87 insertions(+), 64 deletions(-) diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 4968e9493..3740a3fe3 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -58,7 +58,7 @@ pub mod memory { } 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 //! @@ -66,15 +66,25 @@ pub mod wasm { //! //! # Tables 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::types::{ExportDescriptor, ExternDescriptor, ImportDescriptor}; pub use wasmer_runtime_core::types::{ 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 { //! 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::{func, imports}; } @@ -99,7 +109,11 @@ pub mod types { pub mod error { //! 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)] pub enum CompileFromFileError { diff --git a/tests/exception_handling.rs b/tests/exception_handling.rs index edb686495..7a590527d 100644 --- a/tests/exception_handling.rs +++ b/tests/exception_handling.rs @@ -2,7 +2,8 @@ mod runtime_core_tests; pub mod runtime_core_exception_handling { 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] fn exception_handling_works() { diff --git a/tests/imports.rs b/tests/imports.rs index 92fe73835..b8572be4e 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -5,17 +5,14 @@ pub mod runtime_core_imports { use super::runtime_core_tests::{get_compiler, wat2wasm}; use std::{convert::TryInto, sync::Arc}; - use wasmer_runtime_core::{ - compile_with, - error::RuntimeError, - global::Global, - imports, - memory::Memory, - typed_func::{DynamicFunc, Func}, - types::{FuncSig, MemoryDescriptor, Type, Value}, - units::Pages, - vm, DynFunc, Instance, + use wasmer::error::RuntimeError; + use wasmer::imports; + use wasmer::units::Pages; + use wasmer::vm; + use wasmer::wasm::{ + DynFunc, Func, FuncSig, Global, Instance, Memory, MemoryDescriptor, Type, Value, }; + use wasmer_runtime_core::{compile_with, typed_func::DynamicFunc}; #[test] fn runtime_core_new_api_works() { diff --git a/tests/llvm_compile.rs b/tests/llvm_compile.rs index 8477d0fa4..b389ab0c2 100644 --- a/tests/llvm_compile.rs +++ b/tests/llvm_compile.rs @@ -17,8 +17,9 @@ pub fn get_compiler() -> impl Compiler { LLVMCompiler::new() } +use wasmer::imports; 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 std::cell::RefCell; diff --git a/tests/middleware_common.rs b/tests/middleware_common.rs index 22c5ce688..67cd67b55 100644 --- a/tests/middleware_common.rs +++ b/tests/middleware_common.rs @@ -2,12 +2,14 @@ mod tests { use wabt::wat2wasm; + use wasmer::imports; + use wasmer::wasm::Func; use wasmer_middleware_common::metering::*; use wasmer_runtime_core::codegen::ModuleCodeGenerator; use wasmer_runtime_core::codegen::{MiddlewareChain, StreamingCompiler}; use wasmer_runtime_core::fault::{pop_code_version, push_code_version}; 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")] use wasmer_llvm_backend::ModuleCodeGenerator as MCG; diff --git a/tests/override.rs b/tests/override.rs index ee299ff16..278e55c51 100644 --- a/tests/override.rs +++ b/tests/override.rs @@ -1,5 +1,10 @@ use wabt::wat2wasm; -use wasmer_runtime::{compile, DynFunc, ImportObject, Instance, Value}; +use wasmer::{ + import::ImportObject, + wasm::{Instance, Value}, + DynFunc, +}; +use wasmer_runtime::compile; #[test] fn override_works() { diff --git a/tests/spectest.rs b/tests/spectest.rs index efaa2fc07..975904a71 100644 --- a/tests/spectest.rs +++ b/tests/spectest.rs @@ -271,14 +271,18 @@ mod tests { use std::path::PathBuf; use std::str::FromStr; use wabt::script::{Action, Command, CommandKind, ScriptParser, Value}; - use wasmer_runtime::{ - compile_with_config_with, compiler_for_backend, + use wasmer::{ error::CompileError, - func, imports, - types::{ElementType, MemoryDescriptor, TableDescriptor}, + func, + import::{ImportObject, LikeNamespace}, + imports, + types::ElementType, units::Pages, - Backend, CompilerConfig, Ctx, Export, Features, Global, ImportObject, Instance, - LikeNamespace, Memory, Table, + vm::Ctx, + 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 { @@ -416,7 +420,7 @@ mod tests { &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }, @@ -548,7 +552,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -619,7 +623,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -721,7 +725,7 @@ mod tests { } else { false }; - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); let ret = instance.call(&field, ¶ms[..]); #[cfg(unix)] @@ -746,7 +750,7 @@ mod tests { ); } else { let call_result = maybe_call_result.unwrap(); - use wasmer_runtime::error::{CallError, RuntimeError}; + use wasmer::error::{CallError, RuntimeError}; match call_result { Err(e) => match e { CallError::Resolve(_) => { @@ -763,7 +767,7 @@ mod tests { ); } CallError::Runtime(RuntimeError(e)) => { - use wasmer_runtime::ExceptionCode; + use wasmer::error::ExceptionCode; if let Some(_) = e.downcast_ref::() { test_report.count_passed(); } else { @@ -964,7 +968,7 @@ mod tests { &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }, @@ -1061,7 +1065,7 @@ mod tests { ); } Err(e) => match e { - wasmer_runtime::error::Error::LinkError(_) => { + wasmer::error::Error::LinkError(_) => { test_report.count_passed(); } _ => { @@ -1120,7 +1124,7 @@ mod tests { } => { let maybe_call_result = with_instance(instance.clone(), &named_modules, &module, |instance| { - let params: Vec = + let params: Vec = args.iter().cloned().map(convert_value).collect(); instance.call(&field, ¶ms[..]) }); @@ -1183,29 +1187,29 @@ mod tests { Ok(test_report) } - fn is_canonical_nan(val: wasmer_runtime::types::Value) -> bool { + fn is_canonical_nan(val: wasm::Value) -> bool { match val { - wasmer_runtime::types::Value::F32(x) => x.is_canonical_nan(), - wasmer_runtime::types::Value::F64(x) => x.is_canonical_nan(), + wasm::Value::F32(x) => x.is_canonical_nan(), + wasm::Value::F64(x) => x.is_canonical_nan(), _ => 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 { - wasmer_runtime::types::Value::F32(x) => x.is_quiet_nan(), - wasmer_runtime::types::Value::F64(x) => x.is_quiet_nan(), + wasm::Value::F32(x) => x.is_quiet_nan(), + wasm::Value::F64(x) => x.is_quiet_nan(), _ => 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 { - wasmer_runtime::types::Value::I32(x) => format!("{:#x}", x), - wasmer_runtime::types::Value::I64(x) => format!("{:#x}", x), - wasmer_runtime::types::Value::F32(x) => format!("{:#x}", x.to_bits()), - wasmer_runtime::types::Value::F64(x) => format!("{:#x}", x.to_bits()), - wasmer_runtime::types::Value::V128(x) => format!("{:#x}", x), + wasm::Value::I32(x) => format!("{:#x}", x), + wasm::Value::I64(x) => format!("{:#x}", x), + wasm::Value::F32(x) => format!("{:#x}", x.to_bits()), + wasm::Value::F64(x) => format!("{:#x}", x.to_bits()), + wasm::Value::V128(x) => format!("{:#x}", x), } } @@ -1218,13 +1222,13 @@ mod tests { V128(u128), } - fn convert_wasmer_value(other: wasmer_runtime::types::Value) -> SpectestValue { + fn convert_wasmer_value(other: wasm::Value) -> SpectestValue { match other { - wasmer_runtime::types::Value::I32(v) => SpectestValue::I32(v), - wasmer_runtime::types::Value::I64(v) => SpectestValue::I64(v), - wasmer_runtime::types::Value::F32(v) => SpectestValue::F32(v.to_bits()), - wasmer_runtime::types::Value::F64(v) => SpectestValue::F64(v.to_bits()), - wasmer_runtime::types::Value::V128(v) => SpectestValue::V128(v), + wasm::Value::I32(v) => SpectestValue::I32(v), + wasm::Value::I64(v) => SpectestValue::I64(v), + wasm::Value::F32(v) => SpectestValue::F32(v.to_bits()), + wasm::Value::F64(v) => SpectestValue::F64(v.to_bits()), + wasm::Value::V128(v) => SpectestValue::V128(v), } } @@ -1238,13 +1242,13 @@ mod tests { } } - fn convert_value(other: Value) -> wasmer_runtime::types::Value { + fn convert_value(other: Value) -> wasm::Value { match other { - Value::I32(v) => wasmer_runtime::types::Value::I32(v), - Value::I64(v) => wasmer_runtime::types::Value::I64(v), - Value::F32(v) => wasmer_runtime::types::Value::F32(v), - Value::F64(v) => wasmer_runtime::types::Value::F64(v), - Value::V128(v) => wasmer_runtime::types::Value::V128(v), + Value::I32(v) => wasm::Value::I32(v), + Value::I64(v) => wasm::Value::I64(v), + Value::F32(v) => wasm::Value::F32(v), + Value::F64(v) => wasm::Value::F64(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 = Memory::new(memory_desc).unwrap(); - let global_i32 = Global::new(wasmer_runtime::types::Value::I32(666)); - let global_f32 = Global::new(wasmer_runtime::types::Value::F32(666.0)); - let global_f64 = Global::new(wasmer_runtime::types::Value::F64(666.0)); + let global_i32 = Global::new(wasm::Value::I32(666)); + let global_f32 = Global::new(wasm::Value::F32(666.0)); + let global_f64 = Global::new(wasm::Value::F64(666.0)); let table = Table::new(TableDescriptor { element: ElementType::Anyfunc, diff --git a/tests/spectest_semantics.rs b/tests/spectest_semantics.rs index 2edfa7cd1..26b704c1b 100644 --- a/tests/spectest_semantics.rs +++ b/tests/spectest_semantics.rs @@ -1,10 +1,8 @@ #[cfg(test)] mod tests { use wabt::wat2wasm; - use wasmer_runtime::{ - error::{CallError, RuntimeError}, - ExceptionCode, ImportObject, - }; + use wasmer::error::{CallError, ExceptionCode, RuntimeError}; + use wasmer::import::ImportObject; // The semantics of stack overflow are documented at: // https://webassembly.org/docs/semantics/#stack-overflow diff --git a/tests/wasi_serialization.rs b/tests/wasi_serialization.rs index 8d42cc736..b588ddf36 100644 --- a/tests/wasi_serialization.rs +++ b/tests/wasi_serialization.rs @@ -1,5 +1,6 @@ #![cfg(test)] -use wasmer_runtime::{compile, Ctx, Func}; +use wasmer::{vm::Ctx, Func}; +use wasmer_runtime::compile; use wasmer_wasi::{state::*, *}; use std::ffi::c_void; diff --git a/tests/wasitests/_common.rs b/tests/wasitests/_common.rs index 6cc303332..248eee46d 100644 --- a/tests/wasitests/_common.rs +++ b/tests/wasitests/_common.rs @@ -33,7 +33,7 @@ pub fn get_backend() -> Option { macro_rules! assert_wasi_output { ($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{ use crate::dev_utils::stdio::StdioCapturer; - use wasmer_runtime::Func; + use wasmer::Func; use wasmer_wasi::{generate_import_object_for_version, get_wasi_version}; let wasm_bytes = include_bytes!($file);