mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-15 11:10:49 +00:00
Add gas tests.
This commit is contained in:
parent
471a9b3fcc
commit
8db40174ae
@ -74,21 +74,47 @@ fn run_diff_test<F: FnOnce(&[u8]) -> Vec<u8>>(test_dir: &str, name: &str, test:
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! def_stack_height_test {
|
||||
( $name:ident ) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
run_diff_test("stack-height", concat!(stringify!($name), ".wat"), |input| {
|
||||
let module = elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||
let instrumented = utils::stack_height::inject_limiter(module, 1024).expect("Failed to instrument with stack counter");
|
||||
elements::serialize(instrumented).expect("Failed to serialize")
|
||||
});
|
||||
}
|
||||
};
|
||||
mod stack_height {
|
||||
use super::*;
|
||||
|
||||
macro_rules! def_stack_height_test {
|
||||
( $name:ident ) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
run_diff_test("stack-height", concat!(stringify!($name), ".wat"), |input| {
|
||||
let module = elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||
let instrumented = utils::stack_height::inject_limiter(module, 1024).expect("Failed to instrument with stack counter");
|
||||
elements::serialize(instrumented).expect("Failed to serialize")
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
def_stack_height_test!(simple);
|
||||
def_stack_height_test!(start);
|
||||
def_stack_height_test!(table);
|
||||
def_stack_height_test!(global);
|
||||
def_stack_height_test!(imports);
|
||||
}
|
||||
|
||||
def_stack_height_test!(simple);
|
||||
def_stack_height_test!(start);
|
||||
def_stack_height_test!(table);
|
||||
def_stack_height_test!(global);
|
||||
def_stack_height_test!(imports);
|
||||
mod gas {
|
||||
use super::*;
|
||||
|
||||
macro_rules! def_gas_test {
|
||||
( $name:ident ) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
run_diff_test("gas", concat!(stringify!($name), ".wat"), |input| {
|
||||
let rules = utils::rules::Set::default();
|
||||
|
||||
let module = elements::deserialize_buffer(input).expect("Failed to deserialize");
|
||||
let instrumented = utils::inject_gas_counter(module, &rules).expect("Failed to instrument with gas metering");
|
||||
elements::serialize(instrumented).expect("Failed to serialize")
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
def_gas_test!(simple);
|
||||
def_gas_test!(start);
|
||||
}
|
||||
|
26
tests/expectations/gas/simple.wat
Normal file
26
tests/expectations/gas/simple.wat
Normal file
@ -0,0 +1,26 @@
|
||||
(module
|
||||
(type (;0;) (func))
|
||||
(type (;1;) (func (param i32)))
|
||||
(import "env" "gas" (func (;0;) (type 1)))
|
||||
(func (;1;) (type 0)
|
||||
i32.const 3
|
||||
call 0
|
||||
i32.const 1
|
||||
if ;; label = @1
|
||||
i32.const 2
|
||||
call 0
|
||||
loop ;; label = @2
|
||||
i32.const 3
|
||||
call 0
|
||||
i32.const 123
|
||||
drop
|
||||
end
|
||||
end)
|
||||
(func (;2;) (type 0)
|
||||
i32.const 2
|
||||
call 0
|
||||
block ;; label = @1
|
||||
i32.const 1
|
||||
call 0
|
||||
end)
|
||||
(export "simple" (func 1)))
|
20
tests/expectations/gas/start.wat
Normal file
20
tests/expectations/gas/start.wat
Normal file
@ -0,0 +1,20 @@
|
||||
(module
|
||||
(type (;0;) (func (param i32 i32)))
|
||||
(type (;1;) (func))
|
||||
(type (;2;) (func (param i32)))
|
||||
(import "env" "ext_return" (func (;0;) (type 0)))
|
||||
(import "env" "memory" (memory (;0;) 1 1))
|
||||
(import "env" "gas" (func (;1;) (type 2)))
|
||||
(func (;2;) (type 1)
|
||||
i32.const 5
|
||||
call 1
|
||||
i32.const 8
|
||||
i32.const 4
|
||||
call 0
|
||||
unreachable)
|
||||
(func (;3;) (type 1)
|
||||
i32.const 1
|
||||
call 1)
|
||||
(export "call" (func 3))
|
||||
(start 2)
|
||||
(data (i32.const 8) "\01\02\03\04"))
|
15
tests/fixtures/gas/simple.wat
vendored
Normal file
15
tests/fixtures/gas/simple.wat
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
(module
|
||||
(func (export "simple")
|
||||
(if (i32.const 1)
|
||||
(loop
|
||||
i32.const 123
|
||||
drop
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(func
|
||||
block
|
||||
end
|
||||
)
|
||||
)
|
18
tests/fixtures/gas/start.wat
vendored
Normal file
18
tests/fixtures/gas/start.wat
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
(module
|
||||
(import "env" "ext_return" (func $ext_return (param i32 i32)))
|
||||
(import "env" "memory" (memory 1 1))
|
||||
|
||||
(start $start)
|
||||
(func $start
|
||||
(call $ext_return
|
||||
(i32.const 8)
|
||||
(i32.const 4)
|
||||
)
|
||||
(unreachable)
|
||||
)
|
||||
|
||||
(func (export "call")
|
||||
)
|
||||
|
||||
(data (i32.const 8) "\01\02\03\04")
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user