Skip to content

Commit

Permalink
Merge #1719
Browse files Browse the repository at this point in the history
1719: Turn on testing native engine as part of make test. r=nlewycky a=nlewycky

Add support for "on native" and "on jit" to the ignores.txt.

Extend test-no-traps feature to cover tests/compiler/traps.rs and enable it when testing with the native engine.

Turn on testing native engine as part of make test.


Co-authored-by: Nick Lewycky <nick@wasmer.io>
Co-authored-by: nlewycky <nick@wasmer.io>
  • Loading branch information
bors[bot] and nlewycky authored Oct 15, 2020
2 parents e65be6e + 69eef6e commit a663a15
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ test-llvm = [

test-native = [
"native",
"test-generator/test-native",
]
test-jit = [
"jit",
"test-generator/test-jit",
]

# Specifies that we're running in coverage testing mode. This disables tests
Expand Down
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ else
UNAME_S :=
endif

compilers :=
# Which compilers we build. These have dependencies that may not on the system.
compilers := cranelift

# Which engines we test. We always build all engines.
engines := jit

ifeq ($(ARCH), x86_64)
# In X64, Cranelift is enabled
compilers += cranelift
# LLVM could be enabled if not in Windows
ifneq ($(OS), Windows_NT)
# Singlepass doesn't work yet on Windows
Expand All @@ -29,10 +31,14 @@ ifeq ($(ARCH), x86_64)
compilers += llvm
endif
endif

# Native engine doesn't work yet on Windows
engines += native
endif
endif

compilers := $(filter-out ,$(compilers))
engines := $(filter-out ,$(engines))

ifneq ($(OS), Windows_NT)
bold := $(shell tput bold)
Expand Down Expand Up @@ -94,7 +100,7 @@ build-capi-llvm:
# Testing #
###########

test: $(foreach compiler,$(compilers),test-$(compiler)-jit) test-packages test-examples test-deprecated
test: $(foreach engine,$(engines),$(foreach compiler,$(compilers),test-$(compiler)-$(engine))) test-packages test-examples test-deprecated

# Singlepass and native engine don't work together, this rule does nothing.
test-singlepass-native:
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(windows))]
#[cfg(not(any(windows, target_arch = "aarch64")))]
fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> {
main()
}
1 change: 1 addition & 0 deletions examples/engine_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(target_arch = "aarch64"))]
fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> {
main()
}
2 changes: 1 addition & 1 deletion lib/compiler-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2018"
wasmer-compiler = { path = "../compiler", version = "1.0.0-alpha4", features = ["translator"], default-features = false }
wasmer-vm = { path = "../vm", version = "1.0.0-alpha4" }
wasmer-types = { path = "../wasmer-types", version = "1.0.0-alpha4", default-features = false, features = ["std"] }
cranelift-codegen = { version = "0.65", default-features = false }
cranelift-codegen = { version = "0.65", default-features = false, features = ["x86", "arm64"] }
cranelift-frontend = { version = "0.65", default-features = false }
tracing = "0.1"
hashbrown = { version = "0.8", optional = true }
Expand Down
58 changes: 52 additions & 6 deletions tests/compilers/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ fn test_trap_return() -> Result<()> {
}

#[test]
#[cfg_attr(feature = "test-singlepass", ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
),
ignore
)]
fn test_trap_trace() -> Result<()> {
let store = get_store();
let wat = r#"
Expand Down Expand Up @@ -118,7 +125,14 @@ fn test_trap_trace_cb() -> Result<()> {
}

#[test]
#[cfg_attr(feature = "test-singlepass", ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
),
ignore
)]
fn test_trap_stack_overflow() -> Result<()> {
let store = get_store();
let wat = r#"
Expand Down Expand Up @@ -149,7 +163,15 @@ fn test_trap_stack_overflow() -> Result<()> {
}

#[test]
#[cfg_attr(any(feature = "test-singlepass", feature = "test-llvm"), ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
),
ignore
)]
fn trap_display_pretty() -> Result<()> {
let store = get_store();
let wat = r#"
Expand Down Expand Up @@ -182,7 +204,15 @@ RuntimeError: unreachable
}

#[test]
#[cfg_attr(any(feature = "test-singlepass", feature = "test-llvm"), ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
),
ignore
)]
fn trap_display_multi_module() -> Result<()> {
let store = get_store();
let wat = r#"
Expand Down Expand Up @@ -387,7 +417,14 @@ fn mismatched_arguments() -> Result<()> {
}

#[test]
#[cfg_attr(any(feature = "test-singlepass", feature = "test-llvm"), ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native"
),
ignore
)]
fn call_signature_mismatch() -> Result<()> {
let store = get_store();
let binary = r#"
Expand Down Expand Up @@ -418,7 +455,15 @@ RuntimeError: indirect call type mismatch
}

#[test]
#[cfg_attr(any(feature = "test-singlepass", feature = "test-llvm"), ignore)]
#[cfg_attr(
any(
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
),
ignore
)]
fn start_trap_pretty() -> Result<()> {
let store = get_store();
let wat = r#"
Expand Down Expand Up @@ -450,6 +495,7 @@ RuntimeError: unreachable
}

#[test]
#[cfg_attr(feature = "test-native", ignore)]
fn present_after_module_drop() -> Result<()> {
let store = get_store();
let module = Module::new(&store, r#"(func (export "foo") unreachable)"#)?;
Expand Down
14 changes: 14 additions & 0 deletions tests/compilers/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ pub fn run_wast(wast_path: &str, compiler: &str) -> anyhow::Result<()> {
}
let store = get_store(features, try_nan_canonicalization);
let mut wast = Wast::new_with_spectest(store);
// `bulk-memory-operations/bulk.wast` checks for a message that
// specifies which element is uninitialized, but our traps don't
// shepherd that information out.
wast.allow_trap_message("uninitialized element 2", "uninitialized element");
if compiler == "cranelift" && cfg!(feature = "test-native") {
wast.allow_trap_message("call stack exhausted", "out of bounds memory access");
wast.allow_trap_message("indirect call type mismatch", "call stack exhausted");
wast.allow_trap_message("integer divide by zero", "call stack exhausted");
wast.allow_trap_message("integer overflow", "call stack exhausted");
wast.allow_trap_message("invalid conversion to integer", "call stack exhausted");
wast.allow_trap_message("undefined element", "call stack exhausted");
wast.allow_trap_message("uninitialized element", "call stack exhausted");
wast.allow_trap_message("unreachable", "call stack exhausted");
}
if cfg!(feature = "coverage") {
wast.disable_assert_and_exhaustion();
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ singlepass on windows # Singlepass is not yet supported on Windows
cranelift::spec::skip_stack_guard_page on darwin
llvm::spec::skip_stack_guard_page on darwin

# TODO(https://github.com/wasmerio/wasmer/issues/1727): Traps in native engine
cranelift::spec::linking on native
# TODO(https://github.com/wasmerio/wasmer/pull/1710): Library is dropped too soon.
llvm::spec::linking on native

# https://github.com/wasmerio/wasmer/issues/1722
llvm::spec::skip_stack_guard_page on native

# Cranelift on arm failures
cranelift::spec::align on aarch64
cranelift::spec::memory_trap on aarch64
cranelift::spec::simd::simd_bit_shift on aarch64
cranelift::spec::simd::simd_boolean on aarch64
cranelift::spec::simd::simd_const on aarch64
cranelift::spec::simd::simd_i16x8_arith on aarch64
cranelift::spec::simd::simd_i16x8_sat_arith on aarch64
cranelift::spec::simd::simd_i32x4_arith on aarch64
cranelift::spec::simd::simd_i64x2_arith on aarch64
cranelift::spec::simd::simd_i8x16_arith on aarch64
cranelift::spec::simd::simd_i8x16_sat_arith on aarch64
cranelift::spec::simd::simd_lane on aarch64
cranelift::spec::skip_stack_guard_page on aarch64

# Frontends

## WASI
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/test-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ publish = false
[dependencies]
anyhow = "1.0"
target-lexicon = "0.10"

[features]
test-native = []
test-jit = []
13 changes: 11 additions & 2 deletions tests/lib/test-generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub fn build_ignores_from_textfile(path: PathBuf) -> anyhow::Result<Ignores> {
let file = File::open(path)?;
let reader = BufReader::new(file);
let host = Triple::host().to_string();
let engine = if cfg!(feature = "test-native") {
Some("native")
} else if cfg!(feature = "test-jit") {
Some("jit")
} else {
None
};
for line in reader.lines() {
let line = line.unwrap();
// If the line has a `#` we discard all the content that comes after
Expand Down Expand Up @@ -75,8 +82,10 @@ pub fn build_ignores_from_textfile(path: PathBuf) -> anyhow::Result<Ignores> {
}

// We skip the ignore if doesn't apply to the current
// host target
if target.map(|t| !host.contains(&t)).unwrap_or(false) {
// host target or engine
if target.clone().map(|t| !host.contains(&t)).unwrap_or(false)
&& target.clone() != engine.map(str::to_string)
{
continue;
}

Expand Down
23 changes: 17 additions & 6 deletions tests/lib/wast/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct Wast {
instances: HashMap<String, Instance>,
/// Allowed failures (ideally this should be empty)
allowed_instantiation_failures: HashSet<String>,
/// If the (expected from .wast, actual) message pair is in this list,
/// treat the strings as matching.
match_trap_messages: HashMap<String, String>,
/// If the current module was an allowed failure, we allow test to fail
current_is_allowed_failure: bool,
/// The wasm Store
Expand All @@ -37,6 +40,7 @@ impl Wast {
store,
import_object,
allowed_instantiation_failures: HashSet::new(),
match_trap_messages: HashMap::new(),
current_is_allowed_failure: false,
instances: HashMap::new(),
fail_fast: true,
Expand All @@ -52,6 +56,12 @@ impl Wast {
}
}

/// A list of alternative messages to permit for a trap failure.
pub fn allow_trap_message(&mut self, expected: &str, allowed: &str) {
self.match_trap_messages
.insert(expected.into(), allowed.into());
}

/// Do not run any code in assert_trap or assert_exhaustion.
pub fn disable_assert_and_exhaustion(&mut self) {
self.disable_assert_trap_exhaustion = true;
Expand Down Expand Up @@ -132,7 +142,7 @@ impl Wast {
Ok(values) => bail!("expected trap, got {:?}", values),
Err(t) => format!("{}", t),
};
if Self::matches_message_assert_trap(expected, &actual) {
if self.matches_message_assert_trap(expected, &actual) {
return Ok(());
}
bail!("expected '{}', got '{}'", expected, actual)
Expand Down Expand Up @@ -414,12 +424,13 @@ impl Wast {
}

// Checks if the `assert_trap` message matches the expected one
fn matches_message_assert_trap(expected: &str, actual: &str) -> bool {
fn matches_message_assert_trap(&self, expected: &str, actual: &str) -> bool {
actual.contains(expected)
// `bulk-memory-operations/bulk.wast` checks for a message that
// specifies which element is uninitialized, but our traps don't
// shepherd that information out.
|| (expected.contains("uninitialized element 2") && actual.contains("uninitialized element"))
|| self
.match_trap_messages
.get(expected)
.map(|alternative| actual.contains(alternative))
.unwrap_or(false)
}
}

Expand Down

0 comments on commit a663a15

Please sign in to comment.