diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2023-12-18 19:25:41 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2023-12-18 19:25:41 +0100 |
| commit | 820ecb429f57053098684e209b8a3a00cb0ac973 (patch) | |
| tree | 499721bf99cd5b5dcae34a35e5089377e4c77b79 | |
| parent | c062a18495975a8fd8de13d03fbe607c8837dc5d (diff) | |
test: make more tests pass
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
| -rw-r--r-- | crates/tinywasm/src/lib.rs | 20 | ||||
| -rw-r--r-- | crates/tinywasm/tests/charts/progress.rs | 9 | ||||
| -rw-r--r-- | crates/tinywasm/tests/mvp.csv | 2 | ||||
| -rw-r--r-- | crates/tinywasm/tests/progress-mvp.svg | 14 | ||||
| -rw-r--r-- | crates/tinywasm/tests/testsuite/mod.rs | 1 | ||||
| -rw-r--r-- | crates/tinywasm/tests/testsuite/run.rs | 115 | ||||
| -rw-r--r-- | crates/tinywasm/tests/testsuite/util.rs | 20 |
7 files changed, 97 insertions, 84 deletions
diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs index 179cca3..ec48acf 100644 --- a/crates/tinywasm/src/lib.rs +++ b/crates/tinywasm/src/lib.rs @@ -107,23 +107,3 @@ pub mod parser { pub mod types { pub use tinywasm_types::*; } - -#[cfg(test)] -mod tests { - - // #[test] - // fn naive_add() -> Result<()> { - // let wasm = include_bytes!("../../../examples/wasm/add.wasm"); - // let mut module = naive::Module::new(wasm)?; - - // let args = [WasmValue::I32(1), WasmValue::I32(2)]; - // let res = naive::run(&mut module, "add", &args)?; - // println!("res: {:?}", res); - - // let args = [WasmValue::I64(1), WasmValue::I64(2)]; - // let res = naive::run(&mut module, "add_64", &args)?; - // println!("res: {:?}", res); - - // Ok(()) - // } -} diff --git a/crates/tinywasm/tests/charts/progress.rs b/crates/tinywasm/tests/charts/progress.rs index a8e3912..0bc66a6 100644 --- a/crates/tinywasm/tests/charts/progress.rs +++ b/crates/tinywasm/tests/charts/progress.rs @@ -33,9 +33,6 @@ pub fn create_progress_chart(csv_path: &Path, output_path: &Path) -> Result<()> } } - println!("versions: {:?}", versions); - println!("data: {:?}", data); - let root_area = SVGBackend::new(output_path, (1000, 400)).into_drawing_area(); root_area.fill(&WHITE)?; @@ -49,8 +46,8 @@ pub fn create_progress_chart(csv_path: &Path, output_path: &Path) -> Result<()> chart .configure_mesh() - .light_line_style(&TRANSPARENT) - .bold_line_style(&BLACK.mix(0.3)) + .light_line_style(TRANSPARENT) + .bold_line_style(BLACK.mix(0.3)) .max_light_lines(10) .disable_x_mesh() .y_desc("Tests Passed") @@ -71,7 +68,7 @@ pub fn create_progress_chart(csv_path: &Path, output_path: &Path) -> Result<()> chart.draw_series( Histogram::vertical(&chart) .style(BLUE.mix(0.5).filled()) - .data(data.iter().enumerate().map(|(x, y)| (x as u32, *y as u32))), + .data(data.iter().enumerate().map(|(x, y)| (x as u32, *y))), )?; root_area.present()?; diff --git a/crates/tinywasm/tests/mvp.csv b/crates/tinywasm/tests/mvp.csv index 80ffc8e..dc6a77d 100644 --- a/crates/tinywasm/tests/mvp.csv +++ b/crates/tinywasm/tests/mvp.csv @@ -1,3 +1,3 @@ 0.0.3,9258,7567,[{"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.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-alpha.0,9869,10317,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":46,"failed":110},{"name":"binary-leb128.wast","passed":74,"failed":17},{"name":"binary.wast","passed":105,"failed":7},{"name":"block.wast","passed":15,"failed":208},{"name":"br.wast","passed":0,"failed":97},{"name":"br_if.wast","passed":0,"failed":118},{"name":"br_table.wast","passed":0,"failed":174},{"name":"call.wast","passed":0,"failed":91},{"name":"call_indirect.wast","passed":11,"failed":159},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":0,"failed":619},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":99},{"name":"endianness.wast","passed":0,"failed":69},{"name":"exports.wast","passed":33,"failed":63},{"name":"f32.wast","passed":1007,"failed":1507},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1007,"failed":1507},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":273,"failed":617},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":66},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":32,"failed":140},{"name":"func_ptrs.wast","passed":0,"failed":35},{"name":"global.wast","passed":10,"failed":100},{"name":"i32.wast","passed":2,"failed":458},{"name":"i64.wast","passed":2,"failed":414},{"name":"if.wast","passed":24,"failed":217},{"name":"imports.wast","passed":17,"failed":166},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":10,"failed":19},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":3,"failed":129},{"name":"load.wast","passed":13,"failed":84},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":97},{"name":"loop.wast","passed":15,"failed":105},{"name":"memory.wast","passed":6,"failed":73},{"name":"memory_grow.wast","passed":0,"failed":96},{"name":"memory_redundancy.wast","passed":0,"failed":5},{"name":"memory_size.wast","passed":0,"failed":42},{"name":"memory_trap.wast","passed":0,"failed":182},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":0,"failed":88},{"name":"return.wast","passed":0,"failed":84},{"name":"select.wast","passed":0,"failed":148},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":1,"failed":6},{"name":"start.wast","passed":1,"failed":15},{"name":"store.wast","passed":7,"failed":61},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"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":176,"failed":0}] +0.0.5-alpha.0,11046,9182,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":83,"failed":73},{"name":"binary-leb128.wast","passed":74,"failed":17},{"name":"binary.wast","passed":105,"failed":7},{"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":33,"failed":137},{"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":0,"failed":69},{"name":"exports.wast","passed":61,"failed":35},{"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":273,"failed":627},{"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":21,"failed":162},{"name":"inline-module.wast","passed":0,"failed":1},{"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":3,"failed":129},{"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":24,"failed":55},{"name":"memory_grow.wast","passed":7,"failed":89},{"name":"memory_redundancy.wast","passed":0,"failed":8},{"name":"memory_size.wast","passed":2,"failed":40},{"name":"memory_trap.wast","passed":0,"failed":182},{"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":0,"failed":11},{"name":"stack.wast","passed":1,"failed":6},{"name":"start.wast","passed":4,"failed":16},{"name":"store.wast","passed":58,"failed":10},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":3,"failed":33},{"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}] diff --git a/crates/tinywasm/tests/progress-mvp.svg b/crates/tinywasm/tests/progress-mvp.svg index e23bdb4..c8a9bc1 100644 --- a/crates/tinywasm/tests/progress-mvp.svg +++ b/crates/tinywasm/tests/progress-mvp.svg @@ -13,7 +13,7 @@ TinyWasm Version <line opacity="0.3" stroke="#000000" stroke-width="1" x1="80" y1="273" x2="989" y2="273"/> <line opacity="0.3" stroke="#000000" stroke-width="1" x1="80" y1="201" x2="989" y2="201"/> <line opacity="0.3" stroke="#000000" stroke-width="1" x1="80" y1="129" x2="989" y2="129"/> -<line opacity="0.3" stroke="#000000" stroke-width="1" x1="80" y1="57" x2="989" y2="57"/> +<line opacity="0.3" stroke="#000000" stroke-width="1" x1="80" y1="58" x2="989" y2="58"/> <polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="79,54 79,344 "/> <text x="70" y="344" dy="0.5ex" text-anchor="end" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000"> 0 @@ -31,10 +31,10 @@ TinyWasm Version 15000 </text> <polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="74,129 79,129 "/> -<text x="70" y="57" dy="0.5ex" text-anchor="end" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000"> +<text x="70" y="58" dy="0.5ex" text-anchor="end" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000"> 20000 </text> -<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="74,57 79,57 "/> +<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="74,58 79,58 "/> <polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="80,345 989,345 "/> <text x="231" y="355" dy="0.76em" text-anchor="middle" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000"> v0.0.3 (9258) @@ -45,10 +45,10 @@ v0.0.4 (9258) </text> <polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="534,345 534,350 "/> <text x="837" y="355" dy="0.76em" text-anchor="middle" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000"> -v0.0.5-alpha.0 (9869) +v0.0.5-alpha.0 (11046) </text> <polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="837,345 837,350 "/> -<rect x="85" y="211" width="293" height="133" opacity="0.5" fill="#0000FF" stroke="none"/> -<rect x="388" y="211" width="293" height="133" opacity="0.5" fill="#0000FF" stroke="none"/> -<rect x="691" y="203" width="293" height="141" opacity="0.5" fill="#0000FF" stroke="none"/> +<rect x="388" y="212" width="293" height="132" opacity="0.5" fill="#0000FF" stroke="none"/> +<rect x="691" y="186" width="293" height="158" opacity="0.5" fill="#0000FF" stroke="none"/> +<rect x="85" y="212" width="293" height="132" opacity="0.5" fill="#0000FF" stroke="none"/> </svg> diff --git a/crates/tinywasm/tests/testsuite/mod.rs b/crates/tinywasm/tests/testsuite/mod.rs index b31099f..d5cde5f 100644 --- a/crates/tinywasm/tests/testsuite/mod.rs +++ b/crates/tinywasm/tests/testsuite/mod.rs @@ -43,7 +43,6 @@ impl TestSuite { // Check if the last line starts with the current commit if let Some(last) = last_line { - println!("last line: {}", last); if last.starts_with(version) { // Truncate the file size to remove the last line let len_to_truncate = last.len() as i64; diff --git a/crates/tinywasm/tests/testsuite/run.rs b/crates/tinywasm/tests/testsuite/run.rs index 2c3008d..ec4715b 100644 --- a/crates/tinywasm/tests/testsuite/run.rs +++ b/crates/tinywasm/tests/testsuite/run.rs @@ -2,9 +2,8 @@ use crate::testsuite::util::*; use super::TestSuite; use eyre::{eyre, Result}; -use log::debug; use tinywasm_types::TinyWasmModule; -use wast::{lexer::Lexer, parser::ParseBuffer, QuoteWat, Wast}; +use wast::{lexer::Lexer, parser::ParseBuffer, Wast}; impl TestSuite { pub fn run(&mut self, tests: &[&str]) -> Result<()> { @@ -34,8 +33,6 @@ impl TestSuite { .map_err(|e| eyre!("failed to parse module: {:?}", e)) .and_then(|res| res); - println!("result: {:?}", result); - match &result { Err(_) => last_module = None, Ok(m) => last_module = Some(m.clone()), @@ -50,7 +47,6 @@ impl TestSuite { message: _, } => { let Ok(module) = module.encode() else { - println!("malformed module: {:?}", module); test_group.add_result(&format!("{}-malformed", name), span, Ok(())); continue; }; @@ -69,23 +65,65 @@ impl TestSuite { ); } - AssertReturn { span, exec, results } => { - let Some(module) = last_module.as_ref() else { - println!("no module found for assert_return: {:?}", exec); - test_group.add_result(&format!("{}-return", name), span, Err(eyre!("no module found"))); - continue; - }; + AssertInvalid { + span, + mut module, + message: _, + } => { + let res = catch_unwind_silent(move || parse_module_bytes(&module.encode().unwrap())) + .map_err(|e| eyre!("failed to parse module: {:?}", e)) + .and_then(|res| res); - let res: Result<Result<()>, _> = catch_unwind_silent(|| { - let mut store = tinywasm::Store::new(); - let module = tinywasm::Module::from(module); - let instance = module.instantiate(&mut store)?; + test_group.add_result( + &format!("{}-invalid", name), + span, + match res { + Ok(_) => Err(eyre!("expected module to be invalid")), + Err(_) => Ok(()), + }, + ); + } - use wast::WastExecute::*; + AssertTrap { exec, message: _, span } => { + let res: Result<tinywasm::Result<()>, _> = catch_unwind_silent(|| { + let (module, name) = match exec { + wast::WastExecute::Wat(_wat) => unimplemented!("wat"), + wast::WastExecute::Get { module: _, global: _ } => unimplemented!("get"), + wast::WastExecute::Invoke(invoke) => (last_module.as_ref(), invoke.name), + }; + exec_fn(module, name, &[]).map(|_| ()) + }); + + match res { + Err(err) => test_group.add_result( + &format!("{}-trap", name), + span, + Err(eyre!("test panicked: {:?}", err)), + ), + Ok(Err(tinywasm::Error::Trap(_))) => { + test_group.add_result(&format!("{}-trap", name), span, Ok(())) + } + Ok(Err(err)) => test_group.add_result( + &format!("{}-trap", name), + span, + Err(eyre!("expected trap, got error: {:?}", err)), + ), + Ok(Ok(())) => test_group.add_result( + &format!("{}-trap", name), + span, + Err(eyre!("expected trap, got ok")), + ), + } + } + + AssertReturn { span, exec, results } => { + let res: Result<Result<()>, _> = catch_unwind_silent(|| { let invoke = match exec { - Wat(_) => return Result::Ok(()), // not used by the testsuite - Get { module: _, global: _ } => return Result::Ok(()), - Invoke(invoke) => invoke, + wast::WastExecute::Wat(_) => unimplemented!("wat"), + wast::WastExecute::Get { module: _, global: _ } => { + return Err(eyre!("get not supported")) + } + wast::WastExecute::Invoke(invoke) => invoke, }; let args = invoke @@ -93,41 +131,30 @@ impl TestSuite { .into_iter() .map(wastarg2tinywasmvalue) .collect::<Result<Vec<_>>>()?; - let res = instance.get_func(&store, invoke.name)?.call(&mut store, &args)?; + + let outcomes = exec_fn(last_module.as_ref(), invoke.name, &args)?; let expected = results .into_iter() .map(wastret2tinywasmvalue) .collect::<Result<Vec<_>>>()?; - if res.len() != expected.len() { - return Result::Err(eyre!("expected {} results, got {}", expected.len(), res.len())); - } - - for (i, (res, expected)) in res.iter().zip(expected).enumerate() { - if res != &expected { - return Result::Err(eyre!( - "result {} did not match: {:?} != {:?}", - i, - res, - expected - )); - } + if outcomes.len() != expected.len() { + return Err(eyre!("expected {} results, got {}", expected.len(), outcomes.len())); } - - Ok(()) + outcomes + .iter() + .zip(expected) + .enumerate() + .try_for_each(|(i, (outcome, exp))| { + (outcome == &exp) + .then_some(()) + .ok_or_else(|| eyre!("result {} did not match: {:?} != {:?}", i, outcome, exp)) + }) }); - let res = match res { - Err(e) => Err(eyre!("test panicked: {:?}", e)), - Ok(Err(e)) => Err(e), - Ok(Ok(())) => Ok(()), - }; - + let res = res.map_err(|e| eyre!("test panicked: {:?}", e)).and_then(|r| r); test_group.add_result(&format!("{}-return", name), span, res); } - Invoke(m) => { - debug!("invoke: {:?}", m); - } _ => test_group.add_result(&format!("{}-unknown", name), span, Err(eyre!("unsupported directive"))), } } diff --git a/crates/tinywasm/tests/testsuite/util.rs b/crates/tinywasm/tests/testsuite/util.rs index 882537a..ab2ffa3 100644 --- a/crates/tinywasm/tests/testsuite/util.rs +++ b/crates/tinywasm/tests/testsuite/util.rs @@ -3,6 +3,21 @@ use std::panic; use eyre::{eyre, Result}; use tinywasm_types::TinyWasmModule; +pub fn exec_fn( + module: Option<&TinyWasmModule>, + name: &str, + args: &[tinywasm_types::WasmValue], +) -> Result<Vec<tinywasm_types::WasmValue>, tinywasm::Error> { + let Some(module) = module else { + return Err(tinywasm::Error::Other("no module found".to_string())); + }; + + let mut store = tinywasm::Store::new(); + let module = tinywasm::Module::from(module); + let instance = module.instantiate(&mut store)?; + instance.get_func(&store, name)?.call(&mut store, args) +} + pub fn catch_unwind_silent<F: FnOnce() -> R + panic::UnwindSafe, R>(f: F) -> std::thread::Result<R> { let prev_hook = panic::take_hook(); panic::set_hook(Box::new(|_| {})); @@ -11,11 +26,6 @@ pub fn catch_unwind_silent<F: FnOnce() -> R + panic::UnwindSafe, R>(f: F) -> std result } -pub fn parse_module(mut module: wast::core::Module) -> Result<TinyWasmModule> { - let parser = tinywasm_parser::Parser::new(); - Ok(parser.parse_module_bytes(module.encode().expect("failed to encode module"))?) -} - pub fn parse_module_bytes(bytes: &[u8]) -> Result<TinyWasmModule> { let parser = tinywasm_parser::Parser::new(); Ok(parser.parse_module_bytes(bytes)?) |
