Skip to content

Commit

Permalink
Improved test generation
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Apr 14, 2020
1 parent c2306bd commit a7dba54
Show file tree
Hide file tree
Showing 15 changed files with 1,020 additions and 1,560 deletions.
40 changes: 35 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,23 @@ members = [
"examples/parallel",
"examples/plugin-for-example",
"examples/parallel-guest",
"tests/test-generator",
"tests/generate-wasi-tests",
"tests/generate-emscripten-tests",
"tests/wast",
]

[build-dependencies]
wabt = "0.9.1"
anyhow = "1.0.19"
generate-emscripten-tests = { path = "tests/generate-emscripten-tests" }
generate-wasi-tests = { path = "tests/generate-wasi-tests" }
test-generator = { path = "tests/test-generator" }
glob = "0.3"
rustc_version = "0.2"

[dev-dependencies]
anyhow = "1.0.19"
wasmer-wast = { path = "tests/wast" }
criterion = "0.3"
glob = "0.3"
libc = "0.2.60" # for `tests/dev-utils`'s Stdout capturing
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ generate: generate-emtests generate-wasitests

# Spectests
spectests-singlepass:
WASMER_TEST_SINGLEPASS=1 cargo test test_run_spectests --release --no-default-features --features "wasi backend-singlepass" -- --nocapture --test-threads 1
WASMER_TEST_SINGLEPASS=1 cargo test singlepass::spec --release --no-default-features --features "wasi backend-singlepass"

spectests-cranelift:
WASMER_TEST_CRANELFIT=1 cargo test test_run_spectests --release --no-default-features --features "wasi backend-cranelift" -- --nocapture
WASMER_TEST_CRANELFIT=1 cargo test cranelift::spec --release --no-default-features --features "wasi backend-cranelift"

spectests-llvm:
WASMER_TEST_LLVM=1 cargo test test_run_spectests --release --no-default-features --features "wasi backend-llvm wasmer-llvm-backend/test" -- --nocapture
WASMER_TEST_LLVM=1 cargo test llvm::spec --release --no-default-features --features "wasi backend-llvm wasmer-llvm-backend/test"

spectests-all:
WASMER_TEST_CRANELIFT=1 WASMER_TEST_LLVM=1 WASMER_TEST_SINGLEPASS=1 \
cargo test test_run_spectests --release --no-default-features --features "wasi backend-cranelift backend-singlepass backend-llvm wasmer-llvm-backend/test" -- --nocapture --test-threads 1
cargo test spec --release --no-default-features --features "wasi backend-cranelift backend-singlepass backend-llvm wasmer-llvm-backend/test"


spectests: spectests-singlepass spectests-cranelift spectests-llvm
Expand Down
102 changes: 101 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,108 @@
use generate_emscripten_tests;
use generate_wasi_tests;
use std::env;
use std::fmt::Write;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
use test_generator::{
build_ignores_from_textfile, extract_name, test_directory, test_directory_module,
with_test_module, Test, Testsuite,
};

/// Given a Testsuite and a path, process the path in case is a wast
/// file.
fn wast_processor(out: &mut Testsuite, p: PathBuf) -> Option<Test> {
let ext = p.extension()?;
// Only look at wast files.
if ext != "wast" {
return None;
}

// Ignore files starting with `.`, which could be editor temporary files
if p.file_stem()?.to_str()?.starts_with(".") {
return None;
}

let testname = extract_name(&p);
let body = format!(
"crate::run_wast(r#\"{}\"#, \"{}\")",
p.display(),
out.path.get(0).unwrap()
);

Some(Test {
name: testname.to_string(),
body: body.to_string(),
})
}

fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=test/ignores.txt");

fn main() {
generate_wasi_tests::build();
generate_emscripten_tests::build();

let out_dir = PathBuf::from(
env::var_os("OUT_DIR").expect("The OUT_DIR environment variable must be set"),
);
let ignores = build_ignores_from_textfile("tests/ignores.txt".into())?;
let mut out = Testsuite {
buffer: String::new(),
path: vec![],
ignores: ignores,
};

for compiler in &["singlepass", "cranelift", "llvm"] {
writeln!(out.buffer, "#[cfg(feature=\"backend-{}\")]", compiler);
writeln!(out.buffer, "#[cfg(test)]")?;
writeln!(out.buffer, "#[allow(non_snake_case)]")?;
with_test_module(&mut out, compiler, |mut out| {
with_test_module(&mut out, "spec", |out| {
let spec_tests = test_directory(out, "tests/spectests", wast_processor)?;
// Skip running spec_testsuite tests if the submodule isn't checked
// out.
// if spec_tests > 0 {
// test_directory_module(
// out,
// "tests/spec_testsuite/proposals/simd",
// wast_processor,
// )?;
// test_directory_module(
// out,
// "tests/spec_testsuite/proposals/multi-value",
// wast_processor,
// )?;
// test_directory_module(
// out,
// "tests/spec_testsuite/proposals/reference-types",
// wast_processor,
// )?;
// test_directory_module(
// out,
// "tests/spec_testsuite/proposals/bulk-memory-operations",
// wast_processor,
// )?;
// } else {
// println!(
// "cargo:warning=The spec testsuite is disabled. To enable, run `git submodule \
// update --remote`."
// );
// }
Ok(())
})?;
Ok(())
})?;
}

// println!("{}", out.buffer);
// std::process::exit(1);
// Write out our auto-generated tests and opportunistically format them with
// `rustfmt` if it's installed.
let output = out_dir.join("generated_tests.rs");
fs::write(&output, out.buffer)?;
drop(Command::new("rustfmt").arg(&output).status());
Ok(())
}
5 changes: 5 additions & 0 deletions lib/runtime-core/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ impl ImportObject {
}
out
}

/// Returns true if the ImportObject contains namespace with the provided name.
pub fn contains_namespace(&self, name: &str) -> bool {
self.map.lock().unwrap().borrow().contains_key(name)
}
}

/// Iterator for an `ImportObject`'s exports.
Expand Down
2 changes: 1 addition & 1 deletion tests/emtest.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod utils;
mod emtests;
pub mod utils;
Loading

0 comments on commit a7dba54

Please sign in to comment.