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

WASM Specification testsuite (mirror) #89

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Format
run: cargo check
- name: Run clippy
Expand All @@ -39,11 +41,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: webiny/[email protected]

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: taiki-e/install-action@cargo-hack
- run: cargo hack check --rust-version --workspace --all-targets --ignore-private
8 changes: 6 additions & 2 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -26,22 +28,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: cachix/cachix-action@v14
with:
name: dlr-ft
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- run: nix build .#wasm-interpreter --print-build-logs
- run: nix build .?submodules=1#wasm-interpreter --print-build-logs
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
verbose: true
file: result/lcov-codecov.json
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- run: nix build .#report --print-build-logs
- run: nix build .?submodules=1#report --print-build-logs
- name: Archive report
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pages_coverage_preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# -=-=-=-= Create report =-=-=-=-
- uses: cachix/install-nix-action@v27
if: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pages_deploy_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: cachix/install-nix-action@v27
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pages_requirement_preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
# -=-=-=-= Strictdoc =-=-=-=-
- name: Install python
uses: actions/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/specification/testsuite"]
path = tests/specification/testsuite
url = https://github.com/WebAssembly/testsuite.git
27 changes: 25 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env_logger = "0.10.1"
wasmparser = "0.119.0"
itertools = "0.12.0"
wat = "1.0.83"
wast = "212.0.0"
criterion = { version = "0.5.1", features = ["html_reports"] }
hexf = "0.2.1"

Expand Down
2 changes: 1 addition & 1 deletion pkgs/wasm-interpreter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rustPlatform.buildRustPackage rec {
src = ./..;

# File suffices to include
extensions = [ "lock" "rs" "toml" ];
extensions = [ "lock" "rs" "toml" "wast" ];
# Files to explicitly include
include = [ ];
# Files to explicitly exclude
Expand Down
25 changes: 25 additions & 0 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ where
}
}

pub fn invoke_named_dynamic(
&mut self,
func_name: &str,
param: Vec<Value>,
ret_types: &[ValType],
) -> Result<Vec<Value>, RuntimeError> {
// TODO: Optimize this search for better than linear-time. Pre-processing will likely be required
let func_idx = self.exports.iter().find_map(|export| {
if export.name == func_name {
match export.desc {
ExportDesc::FuncIdx(idx) => Some(idx),
_ => None,
}
} else {
None
}
});

if let Some(func_idx) = func_idx {
self.invoke_dynamic(func_idx, param, ret_types)
} else {
Err(RuntimeError::FunctionNotFound)
}
}

/// Can only invoke functions with signature `[t1] -> [t2]` as of now.
pub fn invoke_func<Param: InteropValueList, Returns: InteropValueList>(
&mut self,
Expand Down
64 changes: 64 additions & 0 deletions tests/specification/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::{
fs,
path::{Path, PathBuf},
};

mod reports;
mod run;
mod test_errors;

#[test_log::test]
pub fn spec_tests() {
let paths = get_wast_files(Path::new("./tests/specification/testsuite/"))
.expect("Failed to find testsuite");

let mut successful_reports = 0;
let mut failed_reports = 0;
let mut compile_error_reports = 0;

for test_path in paths {
println!("Report for {}:", test_path.display());
let report = run::run_spec_test(test_path.to_str().unwrap());
println!("{}", report);

match report {
reports::WastTestReport::Asserts(assert_report) => {
if assert_report.has_errors() {
failed_reports += 1;
} else {
successful_reports += 1;
}
}
reports::WastTestReport::CompilationError(_) => {
compile_error_reports += 1;
}
}
}

println!(
"Tests: {} Passed, {} Failed, {} Compilation Errors",
successful_reports, failed_reports, compile_error_reports
);
}

// See: https://stackoverflow.com/a/76820878
fn get_wast_files(base_path: &Path) -> Result<Vec<PathBuf>, std::io::Error> {
let mut buf = vec![];
let entries = fs::read_dir(base_path)?;

for entry in entries {
let entry = entry?;
let meta = entry.metadata()?;

if meta.is_dir() {
let mut subdir = get_wast_files(&entry.path())?;
buf.append(&mut subdir);
}

if meta.is_file() && entry.path().extension().unwrap_or_default() == "wast" {
buf.push(entry.path());
}
}

Ok(buf)
}
Loading
Loading