forked from bytecodealliance/wasm-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.rs
More file actions
58 lines (51 loc) · 1.41 KB
/
Copy pathtests.rs
File metadata and controls
58 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use anyhow::Result;
use wasm_shrink::WasmShrink;
fn wasm() -> Vec<u8> {
let _ = env_logger::try_init();
wat::parse_str(
r#"
(module
(table 1 funcref)
(memory 1)
(func $a (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add
)
(func (export "f") (param i32 i32) (result i32)
local.get 0
local.get 1
call $a
)
)
"#,
)
.unwrap()
}
#[test]
fn shrink_to_empty_is_error() -> Result<()> {
let result = WasmShrink::default().run(wasm(), |_| Ok(true));
assert!(result.is_err());
let err_msg = result.err().unwrap().to_string();
assert!(err_msg.contains("empty Wasm module"));
Ok(())
}
#[test]
fn shrink_to_empty_allowed() -> Result<()> {
WasmShrink::default()
.allow_empty(true)
.run(wasm(), |_| Ok(true))?;
Ok(())
}
#[test]
fn smoke_test() -> Result<()> {
let info = WasmShrink::default().attempts(100).run(wasm(), |wasm| {
let wat = wasmprinter::print_bytes(&wasm)?;
Ok(wat.contains("local.get"))
})?;
assert!(info.input_size > info.output_size);
let wat = wasmprinter::print_bytes(&info.output)?;
assert!(wat.contains("local.get"));
wasmparser::validate(&info.output)?;
Ok(())
}