Skip to content

Commit

Permalink
Switch to fetching tests directly from proposals
Browse files Browse the repository at this point in the history
testsuite repo is usually severely outdated, so it's better to fetch tests directly from the spec and proposal repos for more control. We already have deduplication mechanism anyway, so this shouldn't cause any issues.
  • Loading branch information
RReverser committed Jan 17, 2024
1 parent 04cedfb commit 30b7451
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 56 deletions.
23 changes: 20 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
[submodule "tests/testsuite"]
path = tests/testsuite
url = https://github.com/WebAssembly/testsuite.git
[submodule "tests/spec"]
path = tests/spec
url = https://github.com/WebAssembly/spec
shallow = true
[submodule "tests/exception-handling"]
path = tests/exception-handling
url = https://github.com/WebAssembly/exception-handling
shallow = true
[submodule "tests/extended-name-section"]
path = tests/extended-name-section
url = https://github.com/WebAssembly/extended-name-section
shallow = true
[submodule "tests/tail-call"]
path = tests/tail-call
url = https://github.com/WebAssembly/tail-call
shallow = true
[submodule "tests/threads"]
path = tests/threads
url = https://github.com/WebAssembly/threads
shallow = true
74 changes: 22 additions & 52 deletions tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use fs_err::{read_dir, read_to_string};
use indexmap::IndexMap;
use libtest_mimic::{run as run_tests, Arguments, Failed, Trial};
use rayon::prelude::*;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use wasmbin::io::DecodeError;
use wasmbin::visit::{Visit, VisitError};
Expand All @@ -39,24 +39,6 @@ const IGNORED_ERRORS: &[&str] = &[
];

const IGNORED_MODULES: &[&[u8]] = &[
// These are outdated tests in WebAssembly/testsuite itself.
// It needs updating, but see https://github.com/WebAssembly/testsuite/pull/39#issuecomment-863496809.
&[
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x00, 0x0B, 0x07,
0x01, 0x80, 0x00, 0x41, 0x00, 0x0B, 0x00,
],
&[
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x04, 0x04, 0x01, 0x70, 0x00, 0x00, 0x09,
0x07, 0x01, 0x80, 0x00, 0x41, 0x00, 0x0B, 0x00,
],
&[
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x05, 0x03, 0x01, 0x00, 0x00, 0x0B, 0x06,
0x01, 0x01, 0x41, 0x00, 0x0B, 0x00,
],
&[
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x0B, 0x06, 0x01, 0x01, 0x41, 0x00, 0x0B,
0x00,
],
// Upstream malformed test that becomes well-formed if threads are enabled.
#[cfg(feature = "threads")]
&[
Expand Down Expand Up @@ -149,46 +131,34 @@ impl Tests {
}

#[throws]
fn read_all_tests(path: &Path) -> Vec<Trial> {
let mut test_files = Vec::new();

let mut add_test_files_in_dir = |path: &Path| -> anyhow::Result<()> {
for file in read_dir(path)? {
fn read_all_tests() -> Vec<Trial> {
#[throws]
fn add_test_files_in_dir(test_files: &mut Vec<PathBuf>, dir: PathBuf) {
for file in read_dir(dir)? {
let path = file?.path();
if path.extension().map_or(false, |ext| ext == "wast") {
test_files.push(path);
} else if path.is_dir() {
add_test_files_in_dir(test_files, path)?;
}
}
Ok(())
};

add_test_files_in_dir(path)?;

let proposals_dir = path.join("proposals");

macro_rules! read_proposal_tests {
($name:literal) => {
add_test_files_in_dir(&proposals_dir.join($name))?;
};

(? $name:literal) => {
if cfg!(feature = $name) {
read_proposal_tests!($name);
}
};
}

read_proposal_tests!("bulk-memory-operations");
read_proposal_tests!(? "exception-handling");
read_proposal_tests!("reference-types");
read_proposal_tests!("simd");
read_proposal_tests!(? "tail-call");
read_proposal_tests!(? "threads");
let mut test_files = Vec::new();

ensure!(
!test_files.is_empty(),
"Couldn't find any tests. Did you run `git submodule update --init`?"
);
let root = Path::new("tests");

for dir in [
"spec",
#[cfg(feature = "exception-handling")]
"exception-handling",
#[cfg(feature = "tail-call")]
"tail-call",
#[cfg(feature = "threads")]
"threads",
] {
add_test_files_in_dir(&mut test_files, root.join(dir).join("test").join("core"))?;
}

test_files
.into_par_iter()
Expand Down Expand Up @@ -244,7 +214,7 @@ fn run_test(mut test_module: &[u8], expect_result: Result<(), String>) {

#[throws]
fn main() {
let tests = Tests::read_all_tests(&Path::new("tests").join("testsuite"))?;
let tests = Tests::read_all_tests()?;

let mut args = Arguments::from_args();
// Default to terse output as we have *a lot* of tests.
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite
Submodule testsuite deleted from 5fddf1

0 comments on commit 30b7451

Please sign in to comment.