Skip to content

Commit

Permalink
Merge commit 'bc376544cf1ea8dcff406f9d621f390a668183ea' as 'tests/was…
Browse files Browse the repository at this point in the history
…i-wast'
  • Loading branch information
Mark McCaskey committed Jun 24, 2020
2 parents 4661e27 + bc37654 commit 6d4cbd1
Show file tree
Hide file tree
Showing 147 changed files with 10,081 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/wasi-wast/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target

259 changes: 259 additions & 0 deletions tests/wasi-wast/Cargo.lock

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

16 changes: 16 additions & 0 deletions tests/wasi-wast/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "wasi-test-generator"
version = "0.17.0"
description = "Tests for our WASI implementation"
license = "MIT"
authors = ["The Wasmer Engineering Team <[email protected]>"]
edition = "2018"
publish = false

[dependencies]
glob = "0.3"
gumdrop = "0.8"
tempfile = "3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
wast = "20"
27 changes: 27 additions & 0 deletions tests/wasi-wast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# WASI test suite

WASI test files with expected output in a custom WAST format.

## Setup

In order to run the test generator properly you will need:

- `rustup` installed and on your PATH
- `wasm-opt` and `wasm-strip` from `wabt` installed and on your PATH

## Usage

```
Optional arguments:
-a, --all-versions Whether or not to do operations for all versions of WASI or just the latest.
-g, --generate-wasm Whether or not the Wasm will be generated.
-s, --set-up-toolchain Whether or not the logic to install the needed Rust compilers is run.
-h, --help Print the help message
```

And here's an example of how to generate these tests:

```bash
cargo run -- -as # set up the toolchains for all targets
cargo run -- -ag # generate the WASI tests for all targets
```
53 changes: 53 additions & 0 deletions tests/wasi-wast/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[macro_use]
extern crate serde;

mod set_up_toolchain;
mod util;
mod wasi_version;
mod wasitests;

pub use crate::set_up_toolchain::install_toolchains;
pub use crate::wasi_version::{WasiVersion, ALL_WASI_VERSIONS, LATEST_WASI_VERSION};
pub use crate::wasitests::{build, WasiOptions, WasiTest};

use gumdrop::Options;

#[derive(Debug, Options)]
pub struct TestGenOptions {
/// Whether or not to do operations for all versions of WASI or just the latest.
all_versions: bool,
/// Whether or not the Wasm will be generated.
generate_wasm: bool,
/// Whether or not the logic to install the needed Rust compilers is run.
set_up_toolchain: bool,
/// Print the help message
help: bool,
}

fn main() {
let opts = TestGenOptions::parse_args_default_or_exit();

if opts.help {
println!("{}", TestGenOptions::usage());
std::process::exit(0);
}

let generate_all = opts.all_versions;
let set_up_toolchain = opts.set_up_toolchain;
let generate_wasm = opts.generate_wasm;
let wasi_versions = if generate_all {
ALL_WASI_VERSIONS
} else {
LATEST_WASI_VERSION
};

// Install the Rust WASI toolchains for each of the versions
if set_up_toolchain {
install_toolchains(wasi_versions);
}

// Generate the WASI Wasm files
if generate_wasm {
build(wasi_versions);
}
}
35 changes: 35 additions & 0 deletions tests/wasi-wast/src/set_up_toolchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::util;
use super::wasi_version::*;

use std::process::Command;

fn install_toolchain(toolchain_name: &str) {
println!("Installing rustup toolchain: {}", toolchain_name);
let rustup_out = Command::new("rustup")
.arg("toolchain")
.arg("install")
.arg(toolchain_name)
.output()
.expect("Failed to install toolchain with rustup");
util::print_info_on_error(&rustup_out, "TOOLCHAIN INSTALL FAILED");

println!("Installing rustup WASI target");
let rustup_out = Command::new("rustup")
.arg("target")
.arg("add")
.arg("wasm32-wasi")
.arg("--toolchain")
.arg(toolchain_name)
.output()
.expect("Failed to wasi target in Rust toolchain");
util::print_info_on_error(&rustup_out, "WASI TARGET IN TOOLCHAIN INSTALL FAILED");
}

pub fn install_toolchains(wasi_versions: &[WasiVersion]) {
println!("Setting up system to generate the WASI tests.");
println!("WARNING: this may use a lot of disk space.");

for wasi_version in wasi_versions {
install_toolchain(wasi_version.get_compiler_toolchain());
}
}
Loading

0 comments on commit 6d4cbd1

Please sign in to comment.