From 52bebfac2e6a2dc934273e38230d3986e68a3fe3 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sun, 10 Dec 2023 13:35:13 +0100 Subject: feat: move wasm core testsuite to a seperate crate Signed-off-by: Henry Gressmann --- .gitmodules | 4 +- Cargo.lock | 149 +++++++++++++++++++++++++++++++++++ crates/tinywasm/tests/spec/testsuite | 1 - crates/wasm-testsuite/Cargo.toml | 17 ++++ crates/wasm-testsuite/data | 1 + crates/wasm-testsuite/lib.rs | 112 ++++++++++++++++++++++++++ 6 files changed, 281 insertions(+), 3 deletions(-) delete mode 160000 crates/tinywasm/tests/spec/testsuite create mode 100644 crates/wasm-testsuite/Cargo.toml create mode 160000 crates/wasm-testsuite/data create mode 100644 crates/wasm-testsuite/lib.rs diff --git a/.gitmodules b/.gitmodules index a7949f3..0fa174a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "crates/tinywasm/tests/spec/testsuite"] - path = crates/tinywasm/tests/spec/testsuite +[submodule "crates/wasm-testsuite/data"] + path = crates/wasm-testsuite/data url = https://github.com/WebAssembly/testsuite.git diff --git a/Cargo.lock b/Cargo.lock index b1289e6..70df919 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,25 @@ dependencies = [ "wyz", ] +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bstr" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "bytecheck" version = "0.6.11" @@ -151,6 +170,35 @@ dependencies = [ "owo-colors", ] +[[package]] +name = "cpufeatures" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "env_logger" version = "0.10.1" @@ -190,6 +238,16 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.2.11" @@ -207,6 +265,19 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -431,6 +502,41 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "rust-embed" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810294a8a4a0853d4118e3b94bb079905f2107c7fe979d8f0faae98765eb6378" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfc144a1273124a67b8c1d7cd19f5695d1878b31569c0512f6086f0f4676604e" +dependencies = [ + "proc-macro2", + "quote", + "rust-embed-utils", + "syn 2.0.39", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "816ccd4875431253d6bb54b804bcff4369cbde9bae33defde25fdf6c2ef91d40" +dependencies = [ + "globset", + "sha2", + "walkdir", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -450,6 +556,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "seahash" version = "4.1.0" @@ -476,6 +591,17 @@ dependencies = [ "syn 2.0.39", ] +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "simdutf8" version = "0.1.4" @@ -572,6 +698,12 @@ dependencies = [ "rkyv", ] +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.12" @@ -596,6 +728,16 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -611,6 +753,13 @@ dependencies = [ "leb128", ] +[[package]] +name = "wasm-testsuite" +version = "0.0.1" +dependencies = [ + "rust-embed", +] + [[package]] name = "wasmparser-nostd" version = "0.100.1" diff --git a/crates/tinywasm/tests/spec/testsuite b/crates/tinywasm/tests/spec/testsuite deleted file mode 160000 index dc27dad..0000000 --- a/crates/tinywasm/tests/spec/testsuite +++ /dev/null @@ -1 +0,0 @@ -Subproject commit dc27dad3e34e466bdbfea32fe3c73f5e31f88560 diff --git a/crates/wasm-testsuite/Cargo.toml b/crates/wasm-testsuite/Cargo.toml new file mode 100644 index 0000000..1145b3c --- /dev/null +++ b/crates/wasm-testsuite/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name="wasm-testsuite" +version="0.0.1" +description="Mirror of the WebAssembly core testsuite for use in testing WebAssembly implementations" +edition.workspace=true +license.workspace=true +authors.workspace=true +repository.workspace=true + +[lib] +path="lib.rs" + +[package.metadata.workspaces] +independent=true + +[dependencies] +rust-embed={version="8.1.0", features=["include-exclude"]} diff --git a/crates/wasm-testsuite/data b/crates/wasm-testsuite/data new file mode 160000 index 0000000..dc27dad --- /dev/null +++ b/crates/wasm-testsuite/data @@ -0,0 +1 @@ +Subproject commit dc27dad3e34e466bdbfea32fe3c73f5e31f88560 diff --git a/crates/wasm-testsuite/lib.rs b/crates/wasm-testsuite/lib.rs new file mode 100644 index 0000000..102389a --- /dev/null +++ b/crates/wasm-testsuite/lib.rs @@ -0,0 +1,112 @@ +//! This crate provides a way to access the WebAssembly spec testsuite. +//! +//! The testsuite is included as a git submodule and embedded into the binary. +//! +//! Generated from https://github.com/WebAssembly/testsuite + +#![forbid(unsafe_code)] +#![doc(test( + no_crate_inject, + attr( + deny(warnings, rust_2018_idioms), + allow(dead_code, unused_assignments, unused_variables) + ) +))] +#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)] + +use rust_embed::RustEmbed; +use std::borrow::Cow; + +#[derive(RustEmbed)] +#[folder = "data/"] +#[include = "*.wast"] +struct Asset; + +/// List of all proposals. +/// This list is generated from the `proposals` folder in https://github.com/WebAssembly/testsuite +#[rustfmt::skip] +pub const PROPOSALS: &[&str] = &["annotations", "exception-handling", "memory64", "function-references", "multi-memory", "relaxed-simd", "tail-call", "threads", "extended-const", "gc"]; + +/// Get all test file names and their contents. +/// +/// Proposals can be filtered by passing a list of proposal names. +/// Valid proposal names are listed in [`PROPOSALS`]. +/// Returns an iterator over tuples of the form `(test_name, test_data)`. +/// test_name is the name of the test file and the proposal name (if any), e.g. `annotations/br.wast`. +pub fn get_tests(include_proposals: &[String]) -> impl Iterator)> { + let include_proposals = include_proposals.to_vec(); + + Asset::iter().filter_map(move |x| { + let mut parts = x.split('/'); + match parts.next() { + Some("proposals") => { + let proposal = parts.next(); + let test_name = parts.next().unwrap_or_default(); + + if proposal.map_or(false, |p| include_proposals.contains(&p.to_string())) { + let full_path = format!("{}/{}", proposal.unwrap_or_default(), test_name); + let data = Asset::get(&x).unwrap().data; + Some((full_path, data)) + } else { + None + } + } + Some(test_name) => { + let data = Asset::get(&x).unwrap().data; + Some((test_name.to_owned(), data)) + } + None => None, + } + }) +} + +/// Get the WAST file as a byte slice. +/// +/// # Examples +/// proposals: {proposal}/{test_name}.wast +/// tests: {test_name}.wast +pub fn get_wast(name: &str) -> Option> { + if !name.ends_with(".wast") { + panic!("Expected .wast file. Got: {}", name); + } + + match name.contains('/') { + true => Asset::get(&format!("proposals/{}", name)).map(|x| x.data), + false => Asset::get(name).map(|x| x.data), + } +} + +#[cfg(test)] +mod tests { + use std::collections::HashSet; + + use super::*; + + #[test] + fn test_proposals() { + let mut unique_proposals = HashSet::new(); + + // check that all proposals are present + for proposal in Asset::iter() { + if !proposal.starts_with("proposals/") { + continue; + } + + let proposal = proposal.split('/').nth(1).unwrap(); + unique_proposals.insert(proposal.to_owned()); + // assert!(PROPOSALS.contains(&proposal)); + } + println!("{:?}", unique_proposals); + } + + #[test] + fn test_get_tests() { + let tests = get_tests(&["annotations".to_owned()]); + let tests: Vec<_> = tests.collect(); + println!("{:?}", tests.iter().map(|(name, _)| name).collect::>()); + + // for (name, data) in tests { + // println!("{}: {}", name, data.len()); + // } + } +} -- cgit v1.3.1