Skip to content

Commit

Permalink
Compiler Test refactor now fully works
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed May 16, 2021
1 parent 71176cc commit c2e11d8
Show file tree
Hide file tree
Showing 23 changed files with 890 additions and 1,566 deletions.
47 changes: 47 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = [
"lib/wasi-experimental-io-devices",
"lib/types",
"tests/lib/wast",
"tests/lib/compiler-test-derive",
"tests/integration/cli",
]
exclude = [
Expand All @@ -68,6 +69,7 @@ blake3 = "0.3"
criterion = "0.3"
lazy_static = "1.4"
wasmer-engine-dummy = { path = "tests/lib/engine-dummy" }
compiler-test-derive = { path = "tests/lib/compiler-test-derive" }
tempfile = "3.1"
loupe = "0.1"

Expand Down
63 changes: 26 additions & 37 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use std::fs;
use std::path::PathBuf;
use std::process::Command;
use test_generator::{
build_ignores_from_textfile, test_directory, test_directory_module, wasi_processor,
wast_processor, with_features, with_test_module, Testsuite,
test_directory, test_directory_module, wasi_processor, wast_processor, with_test_module,
Testsuite,
};

fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=tests/ignores.txt");
// As rerun-if-changed doesn't support globs, we use another crate
// to check changes in directories.
build_deps::rerun_if_changed_paths("tests/wasi-wast/wasi/unstable/*")
Expand All @@ -25,33 +24,27 @@ fn main() -> anyhow::Result<()> {
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 compilers = ["singlepass", "cranelift", "llvm"];

// Spectests test generation
{
let mut spectests = Testsuite {
buffer: String::new(),
path: vec![],
ignores: ignores.clone(),
};

with_features(&mut spectests, &compilers, |mut spectests| {
with_test_module(&mut spectests, "spec", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/spec", wast_processor)?;
test_directory_module(
spectests,
"tests/wast/spec/proposals/multi-value",
wast_processor,
)?;
test_directory_module(spectests, "tests/wast/spec/proposals/simd", wast_processor)?;
// test_directory_module(spectests, "tests/wast/spec/proposals/bulk-memory-operations", wast_processor)?;
Ok(())
})?;
with_test_module(&mut spectests, "wasmer", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/wasmer", wast_processor)?;
Ok(())
})?;
with_test_module(&mut spectests, "spec", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/spec", wast_processor)?;
test_directory_module(
spectests,
"tests/wast/spec/proposals/multi-value",
wast_processor,
)?;
test_directory_module(spectests, "tests/wast/spec/proposals/simd", wast_processor)?;
// test_directory_module(spectests, "tests/wast/spec/proposals/bulk-memory-operations", wast_processor)?;
Ok(())
})?;
with_test_module(&mut spectests, "wasmer", |spectests| {
let _spec_tests = test_directory(spectests, "tests/wast/wasmer", wast_processor)?;
Ok(())
})?;

Expand All @@ -70,23 +63,19 @@ fn main() -> anyhow::Result<()> {
let mut wasitests = Testsuite {
buffer: String::new(),
path: vec![],
ignores,
};
let wasi_versions = ["unstable", "snapshot1"];
with_features(&mut wasitests, &compilers, |mut wasitests| {
with_test_module(&mut wasitests, "wasitests", |wasitests| {
for wasi_version in &wasi_versions {
with_test_module(wasitests, wasi_version, |wasitests| {
let _wasi_tests = test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
wasi_processor,
)?;
Ok(())
})?;
}
Ok(())
})?;
with_test_module(&mut wasitests, "wasitests", |wasitests| {
for wasi_version in &wasi_versions {
with_test_module(wasitests, wasi_version, |wasitests| {
let _wasi_tests = test_directory(
wasitests,
format!("tests/wasi-wast/wasi/{}", wasi_version),
wasi_processor,
)?;
Ok(())
})?;
}
Ok(())
})?;

Expand Down
140 changes: 140 additions & 0 deletions tests/compilers/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
use std::sync::Arc;
use wasmer::{CompilerConfig, Engine as WasmerEngine, Features, ModuleMiddleware, Store};

#[derive(Clone, Debug, PartialEq)]
pub enum Compiler {
LLVM,
Cranelift,
Singlepass,
}

#[derive(Clone, Debug, PartialEq)]
pub enum Engine {
Native,
JIT,
}

#[derive(Clone)]
pub struct Config {
pub compiler: Compiler,
pub engine: Engine,
pub features: Features,
pub middlewares: Vec<Arc<dyn ModuleMiddleware>>,
pub canonicalize_nans: bool,
}

impl Config {
pub fn new(engine: Engine, compiler: Compiler) -> Self {
Self {
compiler,
engine,
features: Default::default(),
canonicalize_nans: false,
middlewares: vec![],
}
}

pub fn set_middlewares(&mut self, middlewares: Vec<Arc<dyn ModuleMiddleware>>) {
self.middlewares = middlewares;
}

pub fn set_features(&mut self, features: Features) {
self.features = features;
}

pub fn set_nan_canonicalization(&mut self, canonicalize_nans: bool) {
self.canonicalize_nans = canonicalize_nans;
}

pub fn store(&self) -> Store {
let compiler_config = self.compiler_config(self.canonicalize_nans);
let engine = self.engine(compiler_config);
Store::new(&*engine)
}

pub fn headless_store(&self) -> Store {
let engine = self.engine_headless();
Store::new(&*engine)
}

pub fn engine(&self, compiler_config: Box<dyn CompilerConfig>) -> Box<dyn WasmerEngine> {
#[cfg(not(feature = "engine"))]
compile_error!("Plese enable at least one engine via the features");
match &self.engine {
#[cfg(feature = "native")]
Engine::Native => Box::new(
wasmer_engine_native::Native::new(compiler_config)
.features(self.features.clone())
.engine(),
),
#[cfg(feature = "jit")]
Engine::JIT => Box::new(
wasmer_engine_jit::JIT::new(compiler_config)
.features(self.features.clone())
.engine(),
),
engine => panic!(
"The {:?} Engine is not enabled. Please enable it using the features",
engine
),
}
}

pub fn engine_headless(&self) -> Box<dyn WasmerEngine> {
match &self.engine {
#[cfg(feature = "native")]
Engine::Native => Box::new(wasmer_engine_native::Native::headless().engine()),
#[cfg(feature = "jit")]
Engine::JIT => Box::new(wasmer_engine_jit::JIT::headless().engine()),
engine => panic!(
"The {:?} Engine is not enabled. Please enable it using the features",
engine
),
}
}

pub fn compiler_config(&self, canonicalize_nans: bool) -> Box<dyn CompilerConfig> {
#[cfg(not(feature = "compiler"))]
compile_error!("Plese enable at least one compiler via the features");

match &self.compiler {
#[cfg(feature = "cranelift")]
Compiler::Cranelift => {
let mut compiler = wasmer_compiler_cranelift::Cranelift::new();
compiler.canonicalize_nans(canonicalize_nans);
compiler.enable_verifier();
self.add_middlewares(&mut compiler);
Box::new(compiler)
}
#[cfg(feature = "llvm")]
Compiler::LLVM => {
let mut compiler = wasmer_compiler_llvm::LLVM::new();
compiler.canonicalize_nans(canonicalize_nans);
compiler.enable_verifier();
self.add_middlewares(&mut compiler);
Box::new(compiler)
}
#[cfg(feature = "singlepass")]
Compiler::SinglePass => {
let mut compiler = wasmer_compiler_singlepass::Singlepass::new();
compiler.canonicalize_nans(canonicalize_nans);
compiler.enable_verifier();
self.add_middlewares(&mut compiler);
Box::new(compiler)
}
#[allow(dead_code)]
compiler => {
panic!(
"The {:?} Compiler is not enabled. Enable it via the features",
compiler
)
}
}
}

fn add_middlewares(&self, config: &mut dyn CompilerConfig) {
for middleware in self.middlewares.iter() {
config.push_middleware(middleware.clone());
}
}
}
Loading

0 comments on commit c2e11d8

Please sign in to comment.