mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-26 13:12:04 +00:00
f32 && f64 tests
This commit is contained in:
@ -8,3 +8,5 @@ macro_rules! run_test {
|
||||
}
|
||||
|
||||
run_test!("i32", wasm_i32);
|
||||
run_test!("f32", wasm_f32);
|
||||
run_test!("f64", wasm_f64);
|
||||
|
@ -10,6 +10,7 @@ use serde_json;
|
||||
use test;
|
||||
use parity_wasm;
|
||||
use parity_wasm::interpreter::{
|
||||
RuntimeValue,
|
||||
ProgramInstance, ModuleInstance, ModuleInstanceInterface,
|
||||
Error as InterpreterError,
|
||||
};
|
||||
@ -30,6 +31,18 @@ fn runtime_value(test_val: &test::RuntimeValue) -> parity_wasm::RuntimeValue {
|
||||
let unsigned: u32 = test_val.value.parse().expect("Literal parse error");
|
||||
parity_wasm::RuntimeValue::I32(unsigned as i32)
|
||||
},
|
||||
"i64" => {
|
||||
let unsigned: u64 = test_val.value.parse().expect("Literal parse error");
|
||||
parity_wasm::RuntimeValue::I64(unsigned as i64)
|
||||
},
|
||||
"f32" => {
|
||||
let unsigned: u32 = test_val.value.parse().expect("Literal parse error");
|
||||
parity_wasm::RuntimeValue::decode_f32(unsigned)
|
||||
},
|
||||
"f64" => {
|
||||
let unsigned: u64 = test_val.value.parse().expect("Literal parse error");
|
||||
parity_wasm::RuntimeValue::decode_f64(unsigned)
|
||||
},
|
||||
_ => panic!("Unknwon runtime value type"),
|
||||
}
|
||||
}
|
||||
@ -103,6 +116,24 @@ pub fn spec(name: &str) {
|
||||
}
|
||||
}
|
||||
},
|
||||
&test::Command::AssertReturnCanonicalNan { line, ref action } | &test::Command::AssertReturnArithmeticNan { line, ref action } => {
|
||||
let result = run_action(&*module, action);
|
||||
match result {
|
||||
Ok(result) => {
|
||||
for actual_result in result.into_iter().collect::<Vec<parity_wasm::RuntimeValue>>() {
|
||||
match actual_result {
|
||||
RuntimeValue::F32(val) => if !val.is_nan() { panic!("Expected nan value, got {:?}", val) },
|
||||
RuntimeValue::F64(val) => if !val.is_nan() { panic!("Expected nan value, got {:?}", val) },
|
||||
val @ _ => panic!("Expected action to return float value, got {:?}", val),
|
||||
}
|
||||
}
|
||||
println!("assert_return_nan at line {} - success", line);
|
||||
},
|
||||
Err(e) => {
|
||||
panic!("Expected action to return value, got error: {:?}", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
&test::Command::AssertTrap { line, ref action, .. } => {
|
||||
let result = run_action(&*module, action);
|
||||
match result {
|
||||
|
@ -25,6 +25,16 @@ pub enum Command {
|
||||
action: Action,
|
||||
expected: Vec<RuntimeValue>,
|
||||
},
|
||||
#[serde(rename = "assert_return_canonical_nan")]
|
||||
AssertReturnCanonicalNan {
|
||||
line: u64,
|
||||
action: Action,
|
||||
},
|
||||
#[serde(rename = "assert_return_arithmetic_nan")]
|
||||
AssertReturnArithmeticNan {
|
||||
line: u64,
|
||||
action: Action,
|
||||
},
|
||||
#[serde(rename = "assert_trap")]
|
||||
AssertTrap {
|
||||
line: u64,
|
||||
|
Reference in New Issue
Block a user