Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to GitHub Actions #147

Merged
merged 2 commits into from Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,86 @@
name: CI
on: [push, pull_request]

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
- run: cargo build --all
- run: cargo test --all
- run: cargo check --benches
- run: cargo test --features parallel
- run: cargo test --features parallel --manifest-path crates/tests/Cargo.toml

fuzz_crate:
name: Fuzz Crate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
- name: Run fuzzer
run: cargo test -p walrus-fuzz-utils > fuzz.log || (tail -n 1000 fuzz.log && exit 1)
env:
# 300 seconds = 5 minutes.
WALRUS_FUZZ_TIMEOUT: 300

fuzz:
name: Fuzz
runs-on: ubuntu-latest
strategy:
matrix:
test: [watgen, wasm-opt-ttf, raw]
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: cargo install cargo-fuzz
- name: Install wabt
run: |
set -e
curl -L https://github.com/WebAssembly/wabt/releases/download/1.0.12/wabt-1.0.12-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/wabt-1.0.12"
- name: Install binaryen
run: |
set -e
curl -L https://github.com/WebAssembly/binaryen/releases/download/1.39.1/binaryen-1.39.1-x86_64-linux.tar.gz | tar xzf -
echo "##[add-path]`pwd`/binaryen-1.39.1"
- name: Run fuzzer
run: |
cargo fuzz run ${{ matrix.test }} -- -max_total_time=300 -rss_limit_mb=4096 > fuzz.log 2>&1 || (tail -n 1000 fuzz.log && exit 1)

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
- run: cargo fmt -- --check
106 changes: 0 additions & 106 deletions .travis.yml

This file was deleted.

6 changes: 4 additions & 2 deletions crates/fuzz-utils/Cargo.toml
Expand Up @@ -6,10 +6,12 @@ version = "0.1.0"
publish = false

[dependencies]
rand = { version = "0.7.0", features = ['small_rng'] }
tempfile = "3.1.0"
anyhow = "1.0"
env_logger = "0.7.0"
rand = { version = "0.7.0", features = ['small_rng'] }
tempfile = "3.1.0"
wasmparser = "0.44"
wat = "1.0"

[dependencies.walrus]
path = "../.."
Expand Down
31 changes: 13 additions & 18 deletions crates/fuzz-utils/src/lib.rs
Expand Up @@ -10,7 +10,7 @@ use std::fs;
use std::marker::PhantomData;
use std::path::Path;
use std::time;
use walrus_tests_utils::{wasm_interp, wat2wasm};
use walrus_tests_utils::wasm_interp;

/// `Ok(T)` or a `Err(anyhow::Error)`
pub type Result<T> = std::result::Result<T, anyhow::Error>;
Expand Down Expand Up @@ -95,8 +95,7 @@ where
}

fn wat2wasm(&self, wat: &str) -> Result<Vec<u8>> {
fs::write(self.scratch.path(), wat).context("failed to write to scratch file")?;
wat2wasm(self.scratch.path(), &[])
Ok(wat::parse_str(wat)?)
}

fn interp(&self, wasm: &[u8]) -> Result<String> {
Expand Down Expand Up @@ -416,22 +415,18 @@ impl TestCaseGenerator for WasmOptTtf {
}
};

if {
// Only generate programs that wat2wasm can handle.
let tmp = tempfile::NamedTempFile::new().unwrap();
fs::write(tmp.path(), &wat).unwrap();
wat2wasm(tmp.path(), &[]).is_err()
} {
eprintln!(
"Warning: `wasm-opt -fff` generated wat that wat2wasm cannot handle; \
skipping. wat =\n{}",
String::from_utf8_lossy(&wat)
);
last_wat = Some(wat);
continue;
// Only generate programs that wat2wasm can handle.
if let Ok(bytes) = wat::parse_bytes(&wat) {
if wasmparser::validate(&bytes, None).is_ok() {
return String::from_utf8(wat).unwrap();
}
}

return String::from_utf8(wat).unwrap();
eprintln!(
"Warning: `wasm-opt -fff` generated wat that wat2wasm cannot handle; \
skipping. wat =\n{}",
String::from_utf8_lossy(&wat)
);
last_wat = Some(wat);
}
}
}
Expand Down
67 changes: 3 additions & 64 deletions crates/tests-utils/src/lib.rs
@@ -1,7 +1,7 @@
use anyhow::{bail, Context};
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::{Command, Stdio};
use std::sync::Once;

Expand All @@ -22,7 +22,7 @@ pub const FEATURES: &[&str] = &[

fn require_tool(tool: &str, repo: &str) {
let diagnostic = format!("Could not spawn {}; do you have {} installed?", tool, repo);
let status = Command::new("wat2wasm")
let status = Command::new(tool)
.arg("--help")
.stdout(Stdio::null())
.stderr(Stdio::null())
Expand All @@ -31,69 +31,8 @@ fn require_tool(tool: &str, repo: &str) {
assert!(status.success(), "{}", diagnostic)
}

fn require_wat2wasm() {
require_tool("wat2wasm", "https://github.com/WebAssembly/wabt");
}

/// Compile the `.wat` file at the given path into a `.wasm`.
pub fn wat2wasm(path: &Path, extra_args: &[&str]) -> Result<Vec<u8>> {
static CHECK: Once = Once::new();
CHECK.call_once(require_wat2wasm);

let file = tempfile::NamedTempFile::new().context("could not create named temp file")?;

let mut wasm = PathBuf::from(path);
wasm.set_extension("wasm");

let mut cmd = Command::new("wat2wasm");
cmd.arg(path)
.args(FEATURES)
.arg("--debug-names")
.arg("-o")
.arg(file.path())
.args(extra_args);
println!("running: {:?}", cmd);
let output = cmd.output().context("could not spawn wat2wasm")?;

if !output.status.success() {
bail!(
"wat2wasm exited with status {:?}\n\nstderr = '''\n{}\n'''",
output.status,
String::from_utf8_lossy(&output.stderr)
);
}

let buf = fs::read(file.path())?;
Ok(buf)
}

fn require_wasm2wat() {
require_tool("wasm2wat", "https://github.com/WebAssembly/wabt");
}

/// Disassemble the `.wasm` file at the given path into a `.wat`.
pub fn wasm2wat(path: &Path) -> Result<String> {
static CHECK: Once = Once::new();
CHECK.call_once(require_wasm2wat);

let mut cmd = Command::new("wasm2wat");
cmd.arg(path);
cmd.args(FEATURES);
println!("running: {:?}", cmd);
let output = cmd.output().context("could not run wasm2wat")?;
if !output.status.success() {
bail!(
"wasm2wat exited with status {:?}\n\nstderr = '''\n{}\n'''",
output.status,
String::from_utf8_lossy(&output.stderr)
);
}

Ok(String::from_utf8_lossy(&output.stdout).into_owned())
}

fn require_wasm_interp() {
require_tool("wasm-insterp", "https://github.com/WebAssembly/wabt");
require_tool("wasm-interp", "https://github.com/WebAssembly/wabt");
}

/// Run `wasm-interp` on the given wat file.
Expand Down
10 changes: 6 additions & 4 deletions crates/tests/Cargo.toml
Expand Up @@ -10,12 +10,14 @@ walkdir = "2.2.9"

[dev-dependencies]
anyhow = "1.0"
env_logger = "0.7.0"
serde = { version = "1.0.99", features = ['derive'] }
serde_json = { version = "1.0.40", features = ['preserve_order'] }
tempfile = "3.1.0"
walrus = { path = "../.." }
walrus-tests-utils = { path = "../tests-utils" }
tempfile = "3.1.0"
serde_json = { version = "1.0.40", features = ['preserve_order'] }
serde = { version = "1.0.99", features = ['derive'] }
env_logger = "0.7.0"
wasmprinter = "0.2"
wat = "1.0"

[features]
parallel = ['walrus/parallel']
Expand Down
3 changes: 1 addition & 2 deletions crates/tests/tests/function_imports.rs
@@ -1,13 +1,12 @@
use std::path::Path;
use walrus_tests_utils::wat2wasm;

fn run(wat_path: &Path) -> Result<(), anyhow::Error> {
static INIT_LOGS: std::sync::Once = std::sync::Once::new();
INIT_LOGS.call_once(|| {
env_logger::init();
});

let wasm = wat2wasm(wat_path, &[])?;
let wasm = wat::parse_file(wat_path)?;
let module = walrus::Module::from_buffer(&wasm)?;

assert!(module.imports.find("doggo", "husky").is_some());
Expand Down
2 changes: 1 addition & 1 deletion crates/tests/tests/invalid.rs
Expand Up @@ -7,7 +7,7 @@ fn run(wat: &Path) -> Result<(), anyhow::Error> {
env_logger::init();
});

let wasm = walrus_tests_utils::wat2wasm(wat, &["--no-check"])?;
let wasm = wat::parse_file(wat)?;

// NB: reading the module will do the validation.
match walrus::Module::from_buffer(&wasm) {
Expand Down