cranelift: Bitwise compare fuzzgen results (#4855)
This commit is contained in:
@@ -154,6 +154,25 @@ impl DataValue {
|
|||||||
ty,
|
ty,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Performs a bitwise comparison over the contents of [DataValue].
|
||||||
|
///
|
||||||
|
/// Returns true if all bits are equal.
|
||||||
|
///
|
||||||
|
/// This behaviour is different from PartialEq for NaN floats.
|
||||||
|
pub fn bitwise_eq(&self, other: &DataValue) -> bool {
|
||||||
|
match (self, other) {
|
||||||
|
// We need to bit compare the floats to ensure that we produce the correct values
|
||||||
|
// on NaN's. The test suite expects to assert the precise bit pattern on NaN's or
|
||||||
|
// works around it in the tests themselves.
|
||||||
|
(DataValue::F32(a), DataValue::F32(b)) => a.bits() == b.bits(),
|
||||||
|
(DataValue::F64(a), DataValue::F64(b)) => a.bits() == b.bits(),
|
||||||
|
|
||||||
|
// We don't need to worry about F32x4 / F64x2 Since we compare V128 which is already the
|
||||||
|
// raw bytes anyway
|
||||||
|
(a, b) => a == b,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Record failures to cast [DataValue].
|
/// Record failures to cast [DataValue].
|
||||||
|
|||||||
@@ -54,20 +54,11 @@ impl RunCommand {
|
|||||||
actual: &Vec<DataValue>,
|
actual: &Vec<DataValue>,
|
||||||
expected: &Vec<DataValue>,
|
expected: &Vec<DataValue>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let are_equal = actual
|
let are_equal = actual.len() == expected.len()
|
||||||
|
&& actual
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(expected.into_iter())
|
.zip(expected.into_iter())
|
||||||
.all(|(a, b)| match (a, b) {
|
.all(|(a, b)| a.bitwise_eq(b));
|
||||||
// We need to bit compare the floats to ensure that we produce the correct values
|
|
||||||
// on NaN's. The test suite expects to assert the precise bit pattern on NaN's or
|
|
||||||
// works around it in the tests themselves.
|
|
||||||
(DataValue::F32(a), DataValue::F32(b)) => a.bits() == b.bits(),
|
|
||||||
(DataValue::F64(a), DataValue::F64(b)) => a.bits() == b.bits(),
|
|
||||||
|
|
||||||
// We don't need to worry about F32x4 / F64x2 Since we compare V128 which is already the
|
|
||||||
// raw bytes anyway
|
|
||||||
(a, b) => a == b,
|
|
||||||
});
|
|
||||||
|
|
||||||
match compare {
|
match compare {
|
||||||
Comparison::Equals => are_equal,
|
Comparison::Equals => are_equal,
|
||||||
|
|||||||
@@ -27,11 +27,12 @@ enum RunResult {
|
|||||||
Error(Box<dyn std::error::Error>),
|
Error(Box<dyn std::error::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunResult {
|
impl PartialEq for RunResult {
|
||||||
pub fn unwrap(self) -> Vec<DataValue> {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
match self {
|
if let (RunResult::Success(l), RunResult::Success(r)) = (self, other) {
|
||||||
RunResult::Success(d) => d,
|
l.len() == r.len() && l.iter().zip(r).all(|(l, r)| l.bitwise_eq(r))
|
||||||
_ => panic!("Expected RunResult::Success in unwrap but got: {:?}", self),
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,6 +124,6 @@ fuzz_target!(|testcase: TestCase| {
|
|||||||
_ => panic!("host failed: {:?}", host_res),
|
_ => panic!("host failed: {:?}", host_res),
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(int_res.unwrap(), host_res.unwrap());
|
assert_eq!(int_res, host_res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user