summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-01-10 01:11:55 +0100
committerHenry Gressmann <mail@henrygressmann.de>2024-01-10 01:11:55 +0100
commit525208ec8e86eaf57feb412e6c6c71e6d56d3cb3 (patch)
tree54e6192e868e2afd23a724fce0666106248db34b
parent8077653ddf3d4c555bc90d1647f4a3e9eed576a5 (diff)
chore: improve documentation, tests
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
-rw-r--r--.cargo/config.toml6
-rw-r--r--.github/workflows/test.yaml8
-rw-r--r--Cargo.lock12
-rw-r--r--crates/cli/Cargo.toml2
-rw-r--r--crates/parser/Cargo.toml1
-rw-r--r--crates/parser/src/lib.rs1
-rw-r--r--crates/tinywasm/Cargo.toml2
-rw-r--r--crates/tinywasm/src/func.rs8
-rw-r--r--crates/tinywasm/src/instance.rs29
-rw-r--r--crates/tinywasm/src/lib.rs5
-rw-r--r--crates/tinywasm/src/module.rs4
-rw-r--r--crates/tinywasm/src/store.rs45
-rw-r--r--crates/tinywasm/tests/generate-charts.rs7
-rw-r--r--crates/tinywasm/tests/generated/mvp.csv2
-rw-r--r--crates/tinywasm/tests/generated/progress-mvp.svg6
-rw-r--r--crates/tinywasm/tests/test-mvp.rs5
-rw-r--r--crates/tinywasm/tests/test-wast.rs10
-rw-r--r--crates/tinywasm/tests/testsuite/run.rs21
18 files changed, 123 insertions, 51 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml
index 743421a..3e15584 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -2,6 +2,6 @@
version-dev="workspaces version --no-git-commit --force tinywasm*"
dev="run -- -l debug run"
-test-mvp="test --package tinywasm --test test-mvp"
-test-wast="test --package tinywasm --test test-wast --"
-generate-charts="test --package tinywasm --test generate-charts"
+test-mvp="test --package tinywasm --test test-mvp --release -- --enable "
+test-wast="test --package tinywasm --test test-wast -- --enable "
+generate-charts="test --package tinywasm --test generate-charts -- --enable "
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index c4ae296..d65198f 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -20,10 +20,10 @@ jobs:
rustup default stable
- name: Build (stable)
- run: cargo +stable build --verbose
+ run: cargo +stable build --all
- name: Run tests (stable)
- run: cargo +stable test --verbose
+ run: cargo +stable test --all
test-no-std:
name: Test without default features on nightly Rust
@@ -37,7 +37,7 @@ jobs:
rustup default nightly
- name: Build (nightly, no default features)
- run: cargo +nightly build --verbose --no-default-features
+ run: cargo +nightly build --all --no-default-features
- name: Run tests (nightly, no default features)
- run: cargo +nightly test --verbose --no-default-features
+ run: cargo +nightly test --all --no-default-features
diff --git a/Cargo.lock b/Cargo.lock
index e214f4c..7907fb9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -525,9 +525,9 @@ dependencies = [
[[package]]
name = "getrandom"
-version = "0.2.11"
+version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
+checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [
"cfg-if",
"libc",
@@ -1385,9 +1385,9 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
[[package]]
name = "wasm-encoder"
-version = "0.38.1"
+version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0ad2b51884de9c7f4fe2fd1043fccb8dcad4b1e29558146ee57a144d15779f3f"
+checksum = "111495d6204760238512f57a9af162f45086504da332af210f2f75dd80b34f1d"
dependencies = [
"leb128",
]
@@ -1410,9 +1410,9 @@ dependencies = [
[[package]]
name = "wast"
-version = "69.0.1"
+version = "70.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1ee37317321afde358e4d7593745942c48d6d17e0e6e943704de9bbee121e7a"
+checksum = "2ee4bc54bbe1c6924160b9f75e374a1d07532e7580eb632c0ee6cdd109bb217e"
dependencies = [
"leb128",
"memchr",
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml
index 571dfc0..65a9e72 100644
--- a/crates/cli/Cargo.toml
+++ b/crates/cli/Cargo.toml
@@ -19,7 +19,7 @@ argh="0.1"
color-eyre={version="0.6", default-features=false}
log="0.4"
pretty_env_logger="0.5"
-wast={version="69.0", optional=true}
+wast={version="70.0", optional=true}
[features]
default=["wat"]
diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml
index 1bd4ea3..9e6dc71 100644
--- a/crates/parser/Cargo.toml
+++ b/crates/parser/Cargo.toml
@@ -9,7 +9,6 @@ repository.workspace=true
[dependencies]
# fork of wasmparser with no_std support, see https://github.com/bytecodealliance/wasmtime/issues/3495
-# TODO: create dependency free parser
wasmparser={version="0.100", package="wasmparser-nostd", default-features=false}
log={version="0.4", optional=true}
tinywasm-types={version="0.2.0-alpha.0", path="../types"}
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index 22e2661..561d5c6 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -10,6 +10,7 @@ extern crate alloc;
#[allow(clippy::single_component_path_imports)]
use log;
+// noop fallback if logging is disabled.
#[cfg(not(feature = "logging"))]
mod log {
macro_rules! debug ( ($($tt:tt)*) => {{}} );
diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml
index d04a227..931bb45 100644
--- a/crates/tinywasm/Cargo.toml
+++ b/crates/tinywasm/Cargo.toml
@@ -19,7 +19,7 @@ tinywasm-types={version="0.2.0-alpha.0", path="../types", default-features=false
[dev-dependencies]
wasm-testsuite={path="../wasm-testsuite"}
-wast={version="69.0"}
+wast={version="70.0"}
owo-colors={version="4.0"}
eyre={version="0.6"}
serde_json={version="1.0"}
diff --git a/crates/tinywasm/src/func.rs b/crates/tinywasm/src/func.rs
index 2b70578..b0b359d 100644
--- a/crates/tinywasm/src/func.rs
+++ b/crates/tinywasm/src/func.rs
@@ -19,7 +19,7 @@ pub struct FuncHandle {
}
impl FuncHandle {
- /// Call a function
+ /// Call a function (Invocation)
///
/// See <https://webassembly.github.io/spec/core/exec/modules.html#invocation>
pub fn call(&self, store: &mut Store, params: &[WasmValue]) -> Result<Vec<WasmValue>> {
@@ -66,8 +66,14 @@ impl FuncHandle {
// Once the function returns:
let result_m = func_ty.results.len();
+
+ // 1. Assert: m values are on the top of the stack (Ensured by validation)
+ debug_assert!(stack.values.len() >= result_m);
+
+ // 2. Pop m values from the stack
let res = stack.values.last_n(result_m)?;
+ // The values are returned as the results of the invocation.
Ok(res
.iter()
.zip(func_ty.results.iter())
diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs
index 0ef63a9..ad5e937 100644
--- a/crates/tinywasm/src/instance.rs
+++ b/crates/tinywasm/src/instance.rs
@@ -42,16 +42,30 @@ impl ModuleInstance {
}
/// Instantiate the module in the given store
+ ///
+ /// See <https://webassembly.github.io/spec/core/exec/modules.html#exec-instantiation>
pub fn instantiate(store: &mut Store, module: Module, imports: Option<Imports>) -> Result<Self> {
+ // This doesn't completely follow the steps in the spec, but the end result is the same
+ // Constant expressions are evaluated directly where they are used, so we
+ // don't need to create a auxiliary frame etc.
+
let idx = store.next_module_instance_idx();
let imports = imports.unwrap_or_default();
+
+ // TODO: doesn't link other modules yet
let linked_imports = imports.link(store, &module)?;
+ let global_addrs = store.add_globals(module.data.globals.into(), &module.data.imports, &linked_imports, idx)?;
+ // TODO: imported functions missing
let func_addrs = store.add_funcs(module.data.funcs.into(), idx);
+
let table_addrs = store.add_tables(module.data.table_types.into(), idx);
let mem_addrs = store.add_mems(module.data.memory_types.into(), idx)?;
- let global_addrs = store.add_globals(module.data.globals.into(), &module.data.imports, &linked_imports, idx)?;
+
+ // TODO: active/declared elems need to be initialized
let elem_addrs = store.add_elems(module.data.elements.into(), idx)?;
+
+ // TODO: active data segments need to be initialized
let data_addrs = store.add_datas(module.data.data.into(), idx);
let instance = ModuleInstanceInner {
@@ -70,8 +84,10 @@ impl ModuleInstance {
imports: module.data.imports,
exports: crate::ExportInstance(module.data.exports),
};
+
let instance = ModuleInstance::new(instance);
store.add_instance(instance.clone())?;
+
Ok(instance)
}
@@ -176,13 +192,18 @@ impl ModuleInstance {
}
};
- let func_addr = self.0.func_addrs[func_index as usize];
- let func = store.get_func(func_addr as usize)?;
+ let func_addr = self
+ .0
+ .func_addrs
+ .get(func_index as usize)
+ .expect("No func addr for start func, this is a bug");
+
+ let func = store.get_func(*func_addr as usize)?;
let ty = self.0.types[func.ty_addr() as usize].clone();
Ok(Some(FuncHandle {
module: self.clone(),
- addr: func_addr,
+ addr: *func_addr,
ty,
name: None,
}))
diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs
index 0a2d875..0c1863f 100644
--- a/crates/tinywasm/src/lib.rs
+++ b/crates/tinywasm/src/lib.rs
@@ -43,7 +43,7 @@
//! // Get a typed handle to the exported "add" function
//! // Alternatively, you can use `instance.get_func` to get an untyped handle
//! // that takes and returns WasmValue types
-//! let func = instance.get_typed_func::<(i32, i32), (i32,)>(&mut store, "add")?;
+//! let func = instance.typed_func::<(i32, i32), (i32,)>(&mut store, "add")?;
//! let res = func.call(&mut store, (1, 2))?;
//!
//! assert_eq!(res, (3,));
@@ -60,7 +60,7 @@
//! a custom allocator. This removes support for parsing from files and streams,
//! but otherwise the API is the same.
//!
-//! Additionally, if you want proper error types, you must use a `nightly` compiler.
+//! Additionally, if you want proper error types, you must use a `nightly` compiler to have the error trait in core.
mod std;
extern crate alloc;
@@ -70,6 +70,7 @@ extern crate alloc;
#[allow(clippy::single_component_path_imports)]
use log;
+// noop fallback if logging is disabled.
#[cfg(not(feature = "logging"))]
pub(crate) mod log {
macro_rules! debug ( ($($tt:tt)*) => {{}} );
diff --git a/crates/tinywasm/src/module.rs b/crates/tinywasm/src/module.rs
index 6dfca42..5a2c4f7 100644
--- a/crates/tinywasm/src/module.rs
+++ b/crates/tinywasm/src/module.rs
@@ -55,9 +55,7 @@ impl Module {
/// See <https://webassembly.github.io/spec/core/exec/modules.html#exec-instantiation>
pub fn instantiate(self, store: &mut Store, imports: Option<Imports>) -> Result<ModuleInstance> {
let instance = ModuleInstance::instantiate(store, self, imports)?;
-
- // TODO: this currently panics if theres no start fn
- // let _ = instance.start(store)?;
+ let _ = instance.start(store)?;
Ok(instance)
}
}
diff --git a/crates/tinywasm/src/store.rs b/crates/tinywasm/src/store.rs
index db996c8..564232d 100644
--- a/crates/tinywasm/src/store.rs
+++ b/crates/tinywasm/src/store.rs
@@ -227,19 +227,28 @@ impl Store {
let elem_count = self.data.elems.len();
let mut elem_addrs = Vec::with_capacity(elem_count);
for (i, elem) in elems.into_iter().enumerate() {
- self.data.elems.push(ElemInstance::new(elem.kind, idx));
- elem_addrs.push((i + elem_count) as Addr);
+ match elem.kind {
+ // doesn't need to be initialized, can be initialized lazily using the `table.init` instruction
+ ElementKind::Passive => {}
+
+ // this one is active, so we need to initialize it (essentially a `table.init` instruction)
+ ElementKind::Active { .. } => {
+ // a. Let n be the length of the vector elem[i].init
+ // b. Execute the instruction sequence einstrs
+ // c. Execute the instruction i32.const 0
+ // d. Execute the instruction i32.const n
+ // e. Execute the instruction table.init tableidx i
+ // f. Execute the instruction elm.drop i
+ }
- // match elem.kind {
- // ElementKind::Active { table, offset } => {
- // // let table = self.data.tables[table as usize];
+ // this one is not available to the runtime but needs to be initialized to declare references
+ ElementKind::Declared => {
+ // a. Execute the instruction elm.drop i
+ }
+ }
- // // let offset = self.eval_const(&offset)?;
- // // let offset = offset.raw_value() as usize;
- // // let offset = offset + elem_addrs[i] as usize;
- // // let offset = offset as Addr;
- // }
- // }
+ self.data.elems.push(ElemInstance::new(elem.kind, idx));
+ elem_addrs.push((i + elem_count) as Addr);
}
Ok(elem_addrs)
@@ -252,6 +261,20 @@ impl Store {
for (i, data) in datas.into_iter().enumerate() {
self.data.datas.push(DataInstance::new(data.data.to_vec(), idx));
data_addrs.push((i + data_count) as Addr);
+
+ use tinywasm_types::DataKind::*;
+ match data.kind {
+ Active { .. } => {
+ // a. Assert: memidx == 0
+ // b. Let n be the length of the vector
+ // c. Execute the instruction sequence
+ // d. Execute the instruction
+ // e. Execute the instruction
+ // f. Execute the instruction
+ // g. Execute the instruction
+ }
+ Passive => {}
+ }
}
data_addrs
}
diff --git a/crates/tinywasm/tests/generate-charts.rs b/crates/tinywasm/tests/generate-charts.rs
index f80b092..e8e323d 100644
--- a/crates/tinywasm/tests/generate-charts.rs
+++ b/crates/tinywasm/tests/generate-charts.rs
@@ -6,11 +6,18 @@ fn main() -> Result<()> {
}
fn generate_charts() -> Result<()> {
+ let args = std::env::args().collect::<Vec<_>>();
+ if args.len() < 2 || args[1] != "--enable" {
+ return Ok(());
+ }
+
// Create a line chart
charts::create_progress_chart(
std::path::Path::new("./tests/generated/mvp.csv"),
std::path::Path::new("./tests/generated/progress-mvp.svg"),
)?;
+ println!("created progress chart: ./tests/generated/progress-mvp.svg");
+
Ok(())
}
diff --git a/crates/tinywasm/tests/generated/mvp.csv b/crates/tinywasm/tests/generated/mvp.csv
index b22675c..a238586 100644
--- a/crates/tinywasm/tests/generated/mvp.csv
+++ b/crates/tinywasm/tests/generated/mvp.csv
@@ -2,4 +2,4 @@
0.0.4,9258,10909,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
0.0.5,11135,9093,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":78,"failed":13},{"name":"binary.wast","passed":107,"failed":5},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":22,"failed":39},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":275,"failed":625},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":90},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":7,"failed":29},{"name":"global.wast","passed":50,"failed":60},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":23,"failed":160},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":5,"failed":127},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":30,"failed":49},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":1,"failed":181},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":4,"failed":16},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
0.1.0,17630,2598,[{"name":"address.wast","passed":5,"failed":255},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":110,"failed":2},{"name":"block.wast","passed":193,"failed":30},{"name":"br.wast","passed":84,"failed":13},{"name":"br_if.wast","passed":90,"failed":28},{"name":"br_table.wast","passed":25,"failed":149},{"name":"call.wast","passed":29,"failed":62},{"name":"call_indirect.wast","passed":36,"failed":134},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":371,"failed":248},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":50,"failed":49},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":2,"failed":6},{"name":"float_exprs.wast","passed":761,"failed":139},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":6,"failed":84},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":124,"failed":48},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":51,"failed":59},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":120,"failed":121},{"name":"imports.wast","passed":74,"failed":109},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":14,"failed":15},{"name":"left-to-right.wast","passed":1,"failed":95},{"name":"linking.wast","passed":21,"failed":111},{"name":"load.wast","passed":60,"failed":37},{"name":"local_get.wast","passed":32,"failed":4},{"name":"local_set.wast","passed":50,"failed":3},{"name":"local_tee.wast","passed":68,"failed":29},{"name":"loop.wast","passed":93,"failed":27},{"name":"memory.wast","passed":34,"failed":45},{"name":"memory_grow.wast","passed":12,"failed":84},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":2,"failed":180},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":46,"failed":42},{"name":"return.wast","passed":73,"failed":11},{"name":"select.wast","passed":86,"failed":62},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":9,"failed":11},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":22,"failed":14},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":50,"failed":14},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":35,"failed":15},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
-0.2.0-alpha.0,19345,883,[{"name":"address.wast","passed":181,"failed":79},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":171,"failed":3},{"name":"call.wast","passed":73,"failed":18},{"name":"call_indirect.wast","passed":50,"failed":120},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":439,"failed":180},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":56,"failed":43},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":6,"failed":2},{"name":"float_exprs.wast","passed":890,"failed":10},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":78,"failed":12},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":168,"failed":4},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":103,"failed":7},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":231,"failed":10},{"name":"imports.wast","passed":80,"failed":103},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":26,"failed":3},{"name":"left-to-right.wast","passed":92,"failed":4},{"name":"linking.wast","passed":28,"failed":104},{"name":"load.wast","passed":93,"failed":4},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":93,"failed":4},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":78,"failed":1},{"name":"memory_grow.wast","passed":91,"failed":5},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":35,"failed":7},{"name":"memory_trap.wast","passed":180,"failed":2},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":114,"failed":34},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":13,"failed":7},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
+0.2.0-alpha.0,19344,884,[{"name":"address.wast","passed":181,"failed":79},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":171,"failed":3},{"name":"call.wast","passed":73,"failed":18},{"name":"call_indirect.wast","passed":50,"failed":120},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":439,"failed":180},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":56,"failed":43},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":6,"failed":2},{"name":"float_exprs.wast","passed":890,"failed":10},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":78,"failed":12},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":168,"failed":4},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":103,"failed":7},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":231,"failed":10},{"name":"imports.wast","passed":80,"failed":103},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":26,"failed":3},{"name":"left-to-right.wast","passed":92,"failed":4},{"name":"linking.wast","passed":29,"failed":103},{"name":"load.wast","passed":93,"failed":4},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":93,"failed":4},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":78,"failed":1},{"name":"memory_grow.wast","passed":91,"failed":5},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":35,"failed":7},{"name":"memory_trap.wast","passed":180,"failed":2},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":114,"failed":34},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":11,"failed":9},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
diff --git a/crates/tinywasm/tests/generated/progress-mvp.svg b/crates/tinywasm/tests/generated/progress-mvp.svg
index 6bd9be7..e1fd709 100644
--- a/crates/tinywasm/tests/generated/progress-mvp.svg
+++ b/crates/tinywasm/tests/generated/progress-mvp.svg
@@ -53,12 +53,12 @@ v0.1.0 (17630)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="716,345 716,350 "/>
<text x="898" y="355" dy="0.76em" text-anchor="middle" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000">
-v0.2.0-alpha.0 (19345)
+v0.2.0-alpha.0 (19344)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="898,345 898,350 "/>
-<rect x="85" y="212" width="171" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="266" y="212" width="172" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="630" y="92" width="172" height="252" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="266" y="212" width="172" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="448" y="185" width="172" height="159" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="812" y="67" width="172" height="277" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="85" y="212" width="171" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
</svg>
diff --git a/crates/tinywasm/tests/test-mvp.rs b/crates/tinywasm/tests/test-mvp.rs
index 6f6d9b3..5107551 100644
--- a/crates/tinywasm/tests/test-mvp.rs
+++ b/crates/tinywasm/tests/test-mvp.rs
@@ -4,6 +4,11 @@ use owo_colors::OwoColorize;
use testsuite::TestSuite;
fn main() -> Result<()> {
+ let args = std::env::args().collect::<Vec<_>>();
+ if args.len() < 2 || args[1] != "--enable" {
+ return Ok(());
+ }
+
test_mvp()
}
diff --git a/crates/tinywasm/tests/test-wast.rs b/crates/tinywasm/tests/test-wast.rs
index 8537956..42f7091 100644
--- a/crates/tinywasm/tests/test-wast.rs
+++ b/crates/tinywasm/tests/test-wast.rs
@@ -8,8 +8,12 @@ mod testsuite;
fn main() -> Result<()> {
let args = std::env::args().collect::<Vec<_>>();
- if args.len() < 2 {
- bail!("usage: cargo test-wast <wast-file>")
+ if args.len() < 2 || args[1] != "--enable" {
+ return Ok(());
+ }
+
+ if args.len() < 3 {
+ bail!("usage: cargo test-wast <wast-file>");
}
// cwd for relative paths, absolute paths are kept as-is
@@ -22,7 +26,7 @@ fn main() -> Result<()> {
PathBuf::from("./")
};
- wast_file.push(&args[1]);
+ wast_file.push(&args[2]);
let wast_file = cwd.join(wast_file);
test_wast(wast_file.to_str().expect("wast_file is not a valid path"))?;
diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs
index d34df6c..8a1ddf4 100644
--- a/crates/tinywasm/tests/testsuite/run.rs
+++ b/crates/tinywasm/tests/testsuite/run.rs
@@ -95,7 +95,7 @@ impl TestSuite {
debug!("got wat module");
let result = catch_unwind(AssertUnwindSafe(|| {
let m = parse_module_bytes(&module.encode().expect("failed to encode module"))
- .expect("failed to parse module");
+ .expect("failed to parse module bytes");
tinywasm::Module::from(m)
.instantiate(&mut store, Some(Self::imports(registered_modules.clone()).unwrap()))
.map_err(|e| {
@@ -104,7 +104,7 @@ impl TestSuite {
})
.expect("failed to instantiate module")
}))
- .map_err(|e| eyre!("failed to parse module: {:?}", try_downcast_panic(e)));
+ .map_err(|e| eyre!("failed to parse wat module: {:?}", try_downcast_panic(e)));
match &result {
Err(_) => last_module = None,
@@ -129,7 +129,7 @@ impl TestSuite {
};
let res = catch_unwind_silent(|| parse_module_bytes(&module))
- .map_err(|e| eyre!("failed to parse module: {:?}", try_downcast_panic(e)))
+ .map_err(|e| eyre!("failed to parse module (expected): {:?}", try_downcast_panic(e)))
.and_then(|res| res);
test_group.add_result(
@@ -148,7 +148,7 @@ impl TestSuite {
message: _,
} => {
let res = catch_unwind_silent(move || parse_module_bytes(&module.encode().unwrap()))
- .map_err(|e| eyre!("failed to parse module: {:?}", try_downcast_panic(e)))
+ .map_err(|e| eyre!("failed to parse module (invalid): {:?}", try_downcast_panic(e)))
.and_then(|res| res);
test_group.add_result(
@@ -164,11 +164,18 @@ impl TestSuite {
AssertTrap { exec, message: _, span } => {
let res: Result<tinywasm::Result<()>, _> = catch_unwind_silent(|| {
let (module, name, args) = match exec {
- wast::WastExecute::Wat(_wat) => {
- panic!("wat not supported");
+ wast::WastExecute::Wat(mut wat) => {
+ let module = parse_module_bytes(&wat.encode().expect("failed to encode module"))
+ .expect("failed to parse module");
+ let module = tinywasm::Module::from(module);
+ module.instantiate(
+ &mut store,
+ Some(Self::imports(registered_modules.clone()).unwrap()),
+ )?;
+ return Ok(());
}
wast::WastExecute::Get { module: _, global: _ } => {
- panic!("wat not supported");
+ panic!("get not supported");
}
wast::WastExecute::Invoke(invoke) => (last_module.as_ref(), invoke.name, invoke.args),
};