diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-12-07 00:40:43 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-12-07 00:40:43 +0100 |
| commit | de0d556e72bc90f58077f05a6232b1083503f89a (patch) | |
| tree | ea13e65080fcf156ac29e008510ae5d33fde730b /crates/wasm-testsuite | |
| parent | c098668a2b0a70fe314209ba1c3e23f576e210ee (diff) | |
chore: move wasm-testsuite to a seperate repo & update tests
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/wasm-testsuite')
| -rw-r--r-- | crates/wasm-testsuite/Cargo.toml | 19 | ||||
| -rw-r--r-- | crates/wasm-testsuite/README.md | 20 | ||||
| m--------- | crates/wasm-testsuite/data | 0 | ||||
| -rw-r--r-- | crates/wasm-testsuite/lib.rs | 86 | ||||
| -rw-r--r-- | crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes-invalid.wast | 112 | ||||
| -rw-r--r-- | crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes.wast | 110 |
6 files changed, 0 insertions, 347 deletions
diff --git a/crates/wasm-testsuite/Cargo.toml b/crates/wasm-testsuite/Cargo.toml deleted file mode 100644 index 46df77f..0000000 --- a/crates/wasm-testsuite/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name="wasm-testsuite" -version="0.6.0-alpha.0" -description="Mirror of the WebAssembly core testsuite for use in testing WebAssembly implementations" -license="Apache-2.0" -readme="README.md" -edition.workspace=true -authors.workspace=true -repository.workspace=true -rust-version.workspace=true - -[lib] -path="lib.rs" - -[package.metadata.workspaces] -independent=true - -[dependencies] -rust-embed={version="8.4", features=["include-exclude"]} diff --git a/crates/wasm-testsuite/README.md b/crates/wasm-testsuite/README.md deleted file mode 100644 index 51d574c..0000000 --- a/crates/wasm-testsuite/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# `wasm-testsuite` - -This crate embeds the latest version of the [WebAssembly Test Suite](https://github.com/WebAssembly/spec/tree/main/test). It is currently mainly used for testing the `tinywasm-parser` crate. Check out the [documentation](https://docs.rs/wasm-testsuite) for more information. - -## Usage - -```rust -use wasm_testsuite::{MVP_TESTS, get_test_wast}; - -MVP_TESTS.iter().for_each(|test| { - let wast_bytes = get_test_wast(test).expect("Failed to get wast bytes"); - let wast = std::str::from_utf8(&wast_bytes).expect("failed to convert wast to utf8"); - - // Do something with the wast (e.g. parse it using the `wast` crate) -}); -``` - -## License - -This crate is licensed under the [Apache License, Version 2.0](https://github.com/WebAssembly/spec/blob/main/test/LICENSE).
\ No newline at end of file diff --git a/crates/wasm-testsuite/data b/crates/wasm-testsuite/data deleted file mode 160000 -Subproject 3d176e3d5dfe70cb2f95afa2e590119d85e6260 diff --git a/crates/wasm-testsuite/lib.rs b/crates/wasm-testsuite/lib.rs deleted file mode 100644 index b2cc7d2..0000000 --- a/crates/wasm-testsuite/lib.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![doc = include_str!("README.md")] -#![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 OfficialTests; - -#[derive(RustEmbed)] -#[folder = "tests/"] -#[include = "*.wast"] -struct CustomTests; - -/// List of all supported proposals. Can be used to filter tests. -/// -/// Includes all proposals from <https://github.com/WebAssembly/testsuite/tree/master/proposals> -#[rustfmt::skip] -pub const PROPOSALS: &[&str] = &["annotations", "exception-handling", "extended-const", "function-references", "gc", "memory64", "multi-memory", "relaxed-simd", "tail-call", "threads", "custom-page-sizes", "wide-arithmetic", "wasm-3.0"]; - -/// List of all tests that apply to the MVP (V1) spec -/// Note that the tests are still for the latest spec, so the latest version of Wast is used. -#[rustfmt::skip] // removed: "break-drop.wast", -pub const MVP_TESTS: &[&str] = &["address.wast", "align.wast", "binary-leb128.wast", "binary.wast", "block.wast", "br.wast", "br_if.wast", "br_table.wast", "call.wast", "call_indirect.wast", "comments.wast", "const.wast", "conversions.wast", "custom.wast", "data.wast", "elem.wast", "endianness.wast", "exports.wast", "f32.wast", "f32_bitwise.wast", "f32_cmp.wast", "f64.wast", "f64_bitwise.wast", "f64_cmp.wast", "fac.wast", "float_exprs.wast", "float_literals.wast", "float_memory.wast", "float_misc.wast", "forward.wast", "func.wast", "func_ptrs.wast", "global.wast", "i32.wast", "i64.wast", "if.wast", "imports.wast", "inline-module.wast", "int_exprs.wast", "int_literals.wast", "labels.wast", "left-to-right.wast", "linking.wast", "load.wast", "local_get.wast", "local_set.wast", "local_tee.wast", "loop.wast", "memory.wast", "memory_grow.wast", "memory_redundancy.wast", "memory_size.wast", "memory_trap.wast", "names.wast", "nop.wast", "return.wast", "select.wast", "skip-stack-guard-page.wast", "stack.wast", "start.wast", "store.wast", "switch.wast", "table.wast", "token.wast", "traps.wast", "type.wast", "unreachable.wast", "unreached-valid.wast", "unreached-invalid.wast", "unwind.wast", "utf8-custom-section-id.wast", "utf8-import-field.wast", "utf8-import-module.wast", "utf8-invalid-encoding.wast"]; - -/// List of all tests that apply to the V2 draft 1 spec. -#[rustfmt::skip] -pub const V2_TESTS: &[&str] = &["address.wast", "align.wast", "binary-leb128.wast", "binary.wast", "block.wast", "br.wast", "br_if.wast", "br_table.wast", "bulk.wast", "call.wast", "call_indirect.wast", "comments.wast", "const.wast", "conversions.wast", "custom.wast", "data.wast", "elem.wast", "endianness.wast", "exports.wast", "f32.wast", "f32_bitwise.wast", "f32_cmp.wast", "f64.wast", "f64_bitwise.wast", "f64_cmp.wast", "fac.wast", "float_exprs.wast", "float_literals.wast", "float_memory.wast", "float_misc.wast", "forward.wast", "func.wast", "func_ptrs.wast", "global.wast", "i32.wast", "i64.wast", "if.wast", "imports.wast", "inline-module.wast", "int_exprs.wast", "int_literals.wast", "labels.wast", "left-to-right.wast", "linking.wast", "load.wast", "local_get.wast", "local_set.wast", "local_tee.wast", "loop.wast", "memory.wast", "memory_copy.wast", "memory_fill.wast", "memory_grow.wast", "memory_init.wast", "memory_redundancy.wast", "memory_size.wast", "memory_trap.wast", "names.wast", "nop.wast", "obsolete-keywords.wast", "ref_func.wast", "ref_is_null.wast", "ref_null.wast", "return.wast", "select.wast", "skip-stack-guard-page.wast", "stack.wast", "start.wast", "store.wast", "switch.wast", "table-sub.wast", "table.wast", "table_copy.wast", "table_fill.wast", "table_get.wast", "table_grow.wast", "table_init.wast", "table_set.wast", "table_size.wast", "token.wast", "traps.wast", "type.wast", "unreachable.wast", "unreached-invalid.wast", "unreached-valid.wast", "unwind.wast", "utf8-custom-section-id.wast", "utf8-import-field.wast", "utf8-import-module.wast", "utf8-invalid-encoding.wast"]; - -/// List of all tests that apply to the simd proposal -#[rustfmt::skip] -pub const SIMD_TESTS: &[&str] = &["simd_address.wast", "simd_align.wast", "simd_bit_shift.wast", "simd_bitwise.wast", "simd_boolean.wast", "simd_const.wast", "simd_conversions.wast", "simd_f32x4.wast", "simd_f32x4_arith.wast", "simd_f32x4_cmp.wast", "simd_f32x4_pmin_pmax.wast", "simd_f32x4_rounding.wast", "simd_f64x2.wast", "simd_f64x2_arith.wast", "simd_f64x2_cmp.wast", "simd_f64x2_pmin_pmax.wast", "simd_f64x2_rounding.wast", "simd_i16x8_arith.wast", "simd_i16x8_arith2.wast", "simd_i16x8_cmp.wast", "simd_i16x8_extadd_pairwise_i8x16.wast", "simd_i16x8_extmul_i8x16.wast", "simd_i16x8_q15mulr_sat_s.wast", "simd_i16x8_sat_arith.wast", "simd_i32x4_arith.wast", "simd_i32x4_arith2.wast", "simd_i32x4_cmp.wast", "simd_i32x4_dot_i16x8.wast", "simd_i32x4_extadd_pairwise_i16x8.wast", "simd_i32x4_extmul_i16x8.wast", "simd_i32x4_trunc_sat_f32x4.wast", "simd_i32x4_trunc_sat_f64x2.wast", "simd_i64x2_arith.wast", "simd_i64x2_arith2.wast", "simd_i64x2_cmp.wast", "simd_i64x2_extmul_i32x4.wast", "simd_i8x16_arith.wast", "simd_i8x16_arith2.wast", "simd_i8x16_cmp.wast", "simd_i8x16_sat_arith.wast", "simd_int_to_int_extend.wast", "simd_lane.wast", "simd_linking.wast", "simd_load.wast", "simd_load16_lane.wast", "simd_load32_lane.wast", "simd_load64_lane.wast", "simd_load8_lane.wast", "simd_load_extend.wast", "simd_load_splat.wast", "simd_load_zero.wast", "simd_splat.wast", "simd_store.wast", "simd_store16_lane.wast", "simd_store32_lane.wast", "simd_store64_lane.wast", "simd_store8_lane.wast"]; - -/// List of all tests that apply to a specific proposal. -pub fn get_proposal_tests(proposal: &str) -> impl Iterator<Item = String> + '_ { - OfficialTests::iter().chain(CustomTests::iter()).filter_map(move |x| { - let mut parts = x.split('/'); - if parts.next() == Some("proposals") && parts.next() == Some(proposal) { - Some(format!("{}/{}", proposal, parts.next().unwrap_or_default())) - } else { - None - } - }) -} - -/// Get the WAST file as a byte slice. -pub fn get_test_wast(name: &str) -> Option<Cow<'static, [u8]>> { - assert!(name.ends_with(".wast"), "Expected .wast file. Got: {name}"); - - match name.contains('/') { - true => OfficialTests::get(&format!("proposals/{name}")) - .or_else(|| CustomTests::get(&format!("proposals/{name}"))) - .map(|x| x.data), - false => OfficialTests::get(name).or_else(|| CustomTests::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 OfficialTests::iter() { - if !proposal.starts_with("proposals/") { - continue; - } - - let proposal = proposal.split('/').nth(1).unwrap(); - unique_proposals.insert(proposal.to_owned()); - assert!(PROPOSALS.contains(&proposal), "Missing proposal: {}", proposal); - } - } -} diff --git a/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes-invalid.wast b/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes-invalid.wast deleted file mode 100644 index 150f58b..0000000 --- a/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes-invalid.wast +++ /dev/null @@ -1,112 +0,0 @@ -;; from https://github.com/WebAssembly/custom-page-sizes/blob/main/test/core/custom-page-sizes/custom-page-sizes-invalid.wast - -;; Page size that is not a power of two. -(assert_malformed - (module quote "(memory 0 (pagesize 3))") - "invalid custom page size" -) - -;; Power-of-two page sizes that are not 1 or 64KiB. -(assert_invalid - (module (memory 0 (pagesize 2))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 4))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 8))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 16))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 32))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 64))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 128))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 256))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 512))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 1024))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 2048))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 4096))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 8192))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 16384))) - "invalid custom page size" -) -(assert_invalid - (module (memory 0 (pagesize 32768))) - "invalid custom page size" -) - -;; Power-of-two page size that is larger than 64KiB. -(assert_invalid - (module (memory 0 (pagesize 0x20000))) - "invalid custom page size" -) - -;; Power of two page size that cannot fit in a u64 to exercise checks against -;; shift overflow. -(assert_malformed - (module binary - "\00asm" "\01\00\00\00" - "\05\04\01" ;; Memory section - - ;; memory 0 - "\08" ;; flags w/ custom page size - "\00" ;; minimum = 0 - "\41" ;; pagesize = 2**65 - ) - "invalid custom page size" -) - -;; Importing a memory with the wrong page size. - -(module $m - (memory (export "small-pages-memory") 0 (pagesize 1)) - (memory (export "large-pages-memory") 0 (pagesize 65536)) -) -(register "m" $m) - -(assert_unlinkable - (module - (memory (import "m" "small-pages-memory") 0 (pagesize 65536)) - ) - "incompatible import type" -) - -(assert_unlinkable - (module - (memory (import "m" "large-pages-memory") 0 (pagesize 1)) - ) - "incompatible import type" -) diff --git a/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes.wast b/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes.wast deleted file mode 100644 index f59d52b..0000000 --- a/crates/wasm-testsuite/tests/proposals/custom-page-sizes/custom-page-sizes.wast +++ /dev/null @@ -1,110 +0,0 @@ -;; from https://github.com/WebAssembly/custom-page-sizes/blob/main/test/core/custom-page-sizes/custom-page-sizes.wast - -;; Check all the valid custom page sizes. -(module (memory 1 (pagesize 1))) -(module (memory 1 (pagesize 65536))) - -;; Check them all again with maximums specified. -(module (memory 1 2 (pagesize 1))) -(module (memory 1 2 (pagesize 65536))) - -;; Check the behavior of memories with page size 1. -(module - (memory 0 (pagesize 1)) - (func (export "size") (result i32) - memory.size - ) - (func (export "grow") (param i32) (result i32) - (memory.grow (local.get 0)) - ) - (func (export "load") (param i32) (result i32) - (i32.load8_u (local.get 0)) - ) - (func (export "store") (param i32 i32) - (i32.store8 (local.get 0) (local.get 1)) - ) -) - -(assert_return (invoke "size") (i32.const 0)) -(assert_trap (invoke "load" (i32.const 0)) "out of bounds memory access") - -(assert_return (invoke "grow" (i32.const 65536)) (i32.const 0)) -(assert_return (invoke "size") (i32.const 65536)) -(assert_return (invoke "load" (i32.const 65535)) (i32.const 0)) -(assert_return (invoke "store" (i32.const 65535) (i32.const 1))) -(assert_return (invoke "load" (i32.const 65535)) (i32.const 1)) -(assert_trap (invoke "load" (i32.const 65536)) "out of bounds memory access") - -(assert_return (invoke "grow" (i32.const 65536)) (i32.const 65536)) -(assert_return (invoke "size") (i32.const 131072)) -(assert_return (invoke "load" (i32.const 131071)) (i32.const 0)) -(assert_return (invoke "store" (i32.const 131071) (i32.const 1))) -(assert_return (invoke "load" (i32.const 131071)) (i32.const 1)) -(assert_trap (invoke "load" (i32.const 131072)) "out of bounds memory access") - -;; Although smaller page sizes let us get to memories larger than 2**16 pages, -;; we can't do that with the default page size, even if we explicitly state it -;; as a custom page size. -(module - (memory 0 (pagesize 65536)) - (func (export "size") (result i32) - memory.size - ) - (func (export "grow") (param i32) (result i32) - (memory.grow (local.get 0)) - ) -) -(assert_return (invoke "size") (i32.const 0)) -(assert_return (invoke "grow" (i32.const 65537)) (i32.const -1)) -(assert_return (invoke "size") (i32.const 0)) - -;; Can copy between memories of different page sizes. -(module - (memory $small 10 (pagesize 1)) - (memory $large 1 (pagesize 65536)) - - (data (memory $small) (i32.const 0) "\11\22\33\44") - (data (memory $large) (i32.const 0) "\55\66\77\88") - - (func (export "copy-small-to-large") (param i32 i32 i32) - (memory.copy $large $small (local.get 0) (local.get 1) (local.get 2)) - ) - - (func (export "copy-large-to-small") (param i32 i32 i32) - (memory.copy $small $large (local.get 0) (local.get 1) (local.get 2)) - ) - - (func (export "load8-small") (param i32) (result i32) - (i32.load8_u $small (local.get 0)) - ) - - (func (export "load8-large") (param i32) (result i32) - (i32.load8_u $large (local.get 0)) - ) -) - -(assert_return (invoke "copy-small-to-large" (i32.const 6) (i32.const 0) (i32.const 2))) -(assert_return (invoke "load8-large" (i32.const 6)) (i32.const 0x11)) -(assert_return (invoke "load8-large" (i32.const 7)) (i32.const 0x22)) - -(assert_return (invoke "copy-large-to-small" (i32.const 4) (i32.const 1) (i32.const 3))) -(assert_return (invoke "load8-small" (i32.const 4)) (i32.const 0x66)) -(assert_return (invoke "load8-small" (i32.const 5)) (i32.const 0x77)) -(assert_return (invoke "load8-small" (i32.const 6)) (i32.const 0x88)) - -;; Can link together modules that export and import memories with custom page -;; sizes. - -(module $m - (memory (export "small-pages-memory") 0 (pagesize 1)) - (memory (export "large-pages-memory") 0 (pagesize 65536)) -) -(register "m" $m) - -(module - (memory (import "m" "small-pages-memory") 0 (pagesize 1)) -) - -(module - (memory (import "m" "large-pages-memory") 0 (pagesize 65536)) -) |
