mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-04-25 15:22:17 +00:00
add extra tests and conds
This commit is contained in:
parent
aa08acff8b
commit
acdf61e49e
Binary file not shown.
@ -17,6 +17,8 @@
|
|||||||
i32.const -8192
|
i32.const -8192
|
||||||
i32.const -16384
|
i32.const -16384
|
||||||
i32.const -32768
|
i32.const -32768
|
||||||
|
i32.const -2147483648
|
||||||
|
i32.const 2147483647
|
||||||
return
|
return
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -81,6 +81,10 @@ pub enum Error {
|
|||||||
UnknownOpcode(u8),
|
UnknownOpcode(u8),
|
||||||
/// Invalid VarUint1 value
|
/// Invalid VarUint1 value
|
||||||
InvalidVarUint1(u8),
|
InvalidVarUint1(u8),
|
||||||
|
/// Invalid VarInt32 value
|
||||||
|
InvalidVarInt32,
|
||||||
|
/// Invalid VarInt64 value
|
||||||
|
InvalidVarInt64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for Error {
|
impl From<io::Error> for Error {
|
||||||
|
@ -275,7 +275,7 @@ mod integration_tests {
|
|||||||
|
|
||||||
let module = deserialize_file("./res/cases/v1/const.wasm").expect("Should be deserialized");
|
let module = deserialize_file("./res/cases/v1/const.wasm").expect("Should be deserialized");
|
||||||
let func = &module.code_section().expect("Code section to exist").bodies()[0];
|
let func = &module.code_section().expect("Code section to exist").bodies()[0];
|
||||||
assert_eq!(func.code().elements().len(), 18);
|
assert_eq!(func.code().elements().len(), 20);
|
||||||
|
|
||||||
assert_eq!(I64Const(9223372036854775807), func.code().elements()[0]);
|
assert_eq!(I64Const(9223372036854775807), func.code().elements()[0]);
|
||||||
assert_eq!(I64Const(-9223372036854775808), func.code().elements()[1]);
|
assert_eq!(I64Const(-9223372036854775808), func.code().elements()[1]);
|
||||||
@ -293,6 +293,8 @@ mod integration_tests {
|
|||||||
assert_eq!(I32Const(-8192), func.code().elements()[13]);
|
assert_eq!(I32Const(-8192), func.code().elements()[13]);
|
||||||
assert_eq!(I32Const(-16384), func.code().elements()[14]);
|
assert_eq!(I32Const(-16384), func.code().elements()[14]);
|
||||||
assert_eq!(I32Const(-32768), func.code().elements()[15]);
|
assert_eq!(I32Const(-32768), func.code().elements()[15]);
|
||||||
|
assert_eq!(I32Const(-2147483648), func.code().elements()[16]);
|
||||||
|
assert_eq!(I32Const(2147483647), func.code().elements()[17]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -230,6 +230,7 @@ impl Deserialize for VarInt32 {
|
|||||||
let mut shift = 0;
|
let mut shift = 0;
|
||||||
let mut u8buf = [0u8; 1];
|
let mut u8buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
|
if shift > 31 { return Err(Error::InvalidVarInt32); }
|
||||||
reader.read_exact(&mut u8buf)?;
|
reader.read_exact(&mut u8buf)?;
|
||||||
let b = u8buf[0];
|
let b = u8buf[0];
|
||||||
|
|
||||||
@ -293,13 +294,13 @@ impl Deserialize for VarInt64 {
|
|||||||
let mut shift = 0;
|
let mut shift = 0;
|
||||||
let mut u8buf = [0u8; 1];
|
let mut u8buf = [0u8; 1];
|
||||||
loop {
|
loop {
|
||||||
|
if shift > 63 { return Err(Error::InvalidVarInt64); }
|
||||||
reader.read_exact(&mut u8buf)?;
|
reader.read_exact(&mut u8buf)?;
|
||||||
let b = u8buf[0];
|
let b = u8buf[0];
|
||||||
|
|
||||||
res |= ((b & 0x7f) as i64) << shift;
|
res |= ((b & 0x7f) as i64) << shift;
|
||||||
shift += 7;
|
shift += 7;
|
||||||
if (b >> 7) == 0 {
|
if (b >> 7) == 0 {
|
||||||
println!("shifting {}, b = {:b}, res = {:b}", shift, b, res);
|
|
||||||
if shift < 64 && b & 0b0100_0000 == 0b0100_0000 {
|
if shift < 64 && b & 0b0100_0000 == 0b0100_0000 {
|
||||||
res |= (1i64 << shift).wrapping_neg();
|
res |= (1i64 << shift).wrapping_neg();
|
||||||
}
|
}
|
||||||
@ -690,6 +691,39 @@ mod tests {
|
|||||||
varint64_serde_test(vec![0x80, 0x40], -8192);
|
varint64_serde_test(vec![0x80, 0x40], -8192);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varint64_min() {
|
||||||
|
varint64_serde_test(
|
||||||
|
vec![0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f],
|
||||||
|
-9223372036854775808,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varint64_max() {
|
||||||
|
varint64_serde_test(
|
||||||
|
vec![0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00],
|
||||||
|
9223372036854775807,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varint32_min() {
|
||||||
|
varint32_serde_test(
|
||||||
|
vec![0x80, 0x80, 0x80, 0x80, 0x78],
|
||||||
|
-2147483648,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn varint32_max() {
|
||||||
|
varint32_serde_test(
|
||||||
|
vec![0xff, 0xff, 0xff, 0xff, 0x07],
|
||||||
|
2147483647,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn counted_list() {
|
fn counted_list() {
|
||||||
let payload = vec![
|
let payload = vec![
|
||||||
|
Loading…
x
Reference in New Issue
Block a user