diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..26445d1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "spec/wabt"] + path = spec/wabt + url = https://github.com/WebAssembly/wabt +[submodule "spec/testsuite"] + path = spec/testsuite + url = https://github.com/WebAssembly/testsuite diff --git a/Cargo.toml b/Cargo.toml index 57381e5..b5c8cda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ homepage = "https://github.com/nikvolf/parity-wasm" documentation = "https://nikvolf.github.io/parity-wasm/parity_wasm/" description = "WebAssembly binary format serialization/deserialization/interpreter" keywords = ["wasm", "webassembly", "bytecode", "serde", "interpreter"] -exclude = [ "res/*" ] +exclude = [ "res/*", "spec/*" ] [dependencies] byteorder = "1.0" -parking_lot = "0.4" +parking_lot = "0.4" \ No newline at end of file diff --git a/spec/Cargo.toml b/spec/Cargo.toml new file mode 100644 index 0000000..2fad2bd --- /dev/null +++ b/spec/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "parity-wasm-testsuite" +version = "0.5.6" +authors = ["NikVolf "] +license = "MIT/Apache-2.0" +readme = "README.md" +repository = "https://github.com/nikvolf/parity-wasm" +homepage = "https://github.com/nikvolf/parity-wasm" +description = "parity-wasm testsuite" +build = "build.rs" + +[build-dependencies] +cmake = "0.1" + +[dependencies] +parity-wasm = { path = ".." } +serde_json = "1.0" +serde_derive = "1.0" +serde = "1.0" + +[dev-dependencies] +parity-wasm = { path = ".." } +serde_json = "1.0" +serde_derive = "1.0" +serde = "1.0" \ No newline at end of file diff --git a/spec/build.rs b/spec/build.rs new file mode 100644 index 0000000..596e8a4 --- /dev/null +++ b/spec/build.rs @@ -0,0 +1,8 @@ +extern crate cmake; +use cmake::Config; + +fn main() { + let _dst = Config::new("wabt") + .define("BUILD_TESTS", "OFF") + .build(); +} \ No newline at end of file diff --git a/spec/src/lib.rs b/spec/src/lib.rs new file mode 100644 index 0000000..74fb42a --- /dev/null +++ b/spec/src/lib.rs @@ -0,0 +1,7 @@ +#[macro_use] extern crate serde_derive; +extern crate parity_wasm; +extern crate serde; +extern crate serde_json; + +mod run; +mod test; \ No newline at end of file diff --git a/spec/src/run.rs b/spec/src/run.rs new file mode 100644 index 0000000..8a1f166 --- /dev/null +++ b/spec/src/run.rs @@ -0,0 +1,35 @@ +#![cfg(test)] + +use std::env; +use std::path::PathBuf; +use std::process::Command; +use std::fs::File; + +use serde_json; +use test; + +#[test] +fn i32_tests() { + let outdir = env::var("OUT_DIR").unwrap(); + println!("outdir {}", outdir); + + let spec_name = "i32"; + + let mut wast2wasm_path = PathBuf::from(outdir.clone()); + wast2wasm_path.push("bin"); + wast2wasm_path.push("wast2wasm"); + + let mut json_spec_path = PathBuf::from(outdir.clone()); + json_spec_path.push(&format!("{}.json", spec_name)); + + let _output = Command::new(wast2wasm_path) + .arg("--spec") + .arg("-o") + .arg(&json_spec_path) + .arg(&format!("./testsuite/{}.wast", spec_name)) + .output() + .expect("Failed to execute process"); + + let mut f = File::open(&format!("{}/{}.json", outdir, spec_name)).unwrap(); + let commands: test::Commands = serde_json::from_reader(&mut f).unwrap(); +} \ No newline at end of file diff --git a/spec/src/test.rs b/spec/src/test.rs new file mode 100644 index 0000000..686022f --- /dev/null +++ b/spec/src/test.rs @@ -0,0 +1,40 @@ +#![cfg(test)] + +#[derive(Deserialize)] +pub struct RuntimeValue { + #[serde(rename = "type")] + value_type: String, + value: String, +} + +#[derive(Deserialize)] +#[serde(tag = "type")] +pub enum Action { + #[serde(rename = "invoke")] + Invoke { field: String, args: Vec } +} + +#[derive(Deserialize)] +#[serde(tag = "type")] +pub enum Command { + #[serde(rename = "module")] + Module { line: u64, filename: String }, + #[serde(rename = "assert_return")] + AssertReturn { + line: u64, + action: Action, + expected: Vec, + }, + #[serde(rename = "assert_trap")] + AssertTrap { + line: u64, + action: Action, + text: String, + }, +} + +#[derive(Deserialize)] +pub struct Commands { + source_filename: String, + commands: Vec, +} \ No newline at end of file diff --git a/spec/testsuite b/spec/testsuite new file mode 160000 index 0000000..434fe2f --- /dev/null +++ b/spec/testsuite @@ -0,0 +1 @@ +Subproject commit 434fe2f1cb4c2a545e8b6165b695435e1adfeb2a diff --git a/spec/wabt b/spec/wabt new file mode 160000 index 0000000..7425bcc --- /dev/null +++ b/spec/wabt @@ -0,0 +1 @@ +Subproject commit 7425bcc31e6516375391d18a62daee4c9f3502de