Fix unused imports in oracles

This commit is contained in:
Alex Crichton
2020-03-17 12:01:11 -07:00
parent 532422a5d9
commit 210bfddfa9

View File

@@ -12,8 +12,7 @@
pub mod dummy; pub mod dummy;
use dummy::{dummy_imports, dummy_values}; use dummy::dummy_imports;
use std::collections::{HashMap, HashSet};
use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use std::sync::atomic::{AtomicUsize, Ordering::SeqCst};
use wasmtime::*; use wasmtime::*;
@@ -114,6 +113,8 @@ pub fn differential_execution(
ttf: &crate::generators::WasmOptTtf, ttf: &crate::generators::WasmOptTtf,
configs: &[crate::generators::DifferentialConfig], configs: &[crate::generators::DifferentialConfig],
) { ) {
use std::collections::{HashMap, HashSet};
crate::init_fuzzing(); crate::init_fuzzing();
// We need at least two configs. // We need at least two configs.
@@ -205,7 +206,7 @@ pub fn differential_execution(
}; };
let ty = f.ty(); let ty = f.ty();
let params = match dummy_values(ty.params()) { let params = match dummy::dummy_values(ty.params()) {
Ok(p) => p, Ok(p) => p,
Err(_) => continue, Err(_) => continue,
}; };
@@ -217,69 +218,69 @@ pub fn differential_execution(
assert_same_export_func_result(&existing_result, &this_result, name); assert_same_export_func_result(&existing_result, &this_result, name);
} }
} }
}
fn init_hang_limit(instance: &Instance) { fn init_hang_limit(instance: &Instance) {
match instance.get_export("hangLimitInitializer") { match instance.get_export("hangLimitInitializer") {
None => return, None => return,
Some(Extern::Func(f)) => { Some(Extern::Func(f)) => {
f.call(&[]) f.call(&[])
.expect("initializing the hang limit should not fail"); .expect("initializing the hang limit should not fail");
}
Some(_) => panic!("unexpected hangLimitInitializer export"),
}
}
fn assert_same_export_func_result(
lhs: &Result<Box<[Val]>, Trap>,
rhs: &Result<Box<[Val]>, Trap>,
func_name: &str,
) {
let fail = || {
panic!(
"differential fuzzing failed: exported func {} returned two \
different results: {:?} != {:?}",
func_name, lhs, rhs
)
};
match (lhs, rhs) {
(Err(_), Err(_)) => {}
(Ok(lhs), Ok(rhs)) => {
if lhs.len() != rhs.len() {
fail();
} }
for (lhs, rhs) in lhs.iter().zip(rhs.iter()) { Some(_) => panic!("unexpected hangLimitInitializer export"),
match (lhs, rhs) { }
(Val::I32(lhs), Val::I32(rhs)) if lhs == rhs => continue, }
(Val::I64(lhs), Val::I64(rhs)) if lhs == rhs => continue,
(Val::V128(lhs), Val::V128(rhs)) if lhs == rhs => continue, fn assert_same_export_func_result(
(Val::F32(lhs), Val::F32(rhs)) => { lhs: &Result<Box<[Val]>, Trap>,
let lhs = f32::from_bits(*lhs); rhs: &Result<Box<[Val]>, Trap>,
let rhs = f32::from_bits(*rhs); func_name: &str,
if lhs == rhs || (lhs.is_nan() && rhs.is_nan()) { ) {
continue; let fail = || {
} else { panic!(
fail() "differential fuzzing failed: exported func {} returned two \
different results: {:?} != {:?}",
func_name, lhs, rhs
)
};
match (lhs, rhs) {
(Err(_), Err(_)) => {}
(Ok(lhs), Ok(rhs)) => {
if lhs.len() != rhs.len() {
fail();
}
for (lhs, rhs) in lhs.iter().zip(rhs.iter()) {
match (lhs, rhs) {
(Val::I32(lhs), Val::I32(rhs)) if lhs == rhs => continue,
(Val::I64(lhs), Val::I64(rhs)) if lhs == rhs => continue,
(Val::V128(lhs), Val::V128(rhs)) if lhs == rhs => continue,
(Val::F32(lhs), Val::F32(rhs)) => {
let lhs = f32::from_bits(*lhs);
let rhs = f32::from_bits(*rhs);
if lhs == rhs || (lhs.is_nan() && rhs.is_nan()) {
continue;
} else {
fail()
}
} }
} (Val::F64(lhs), Val::F64(rhs)) => {
(Val::F64(lhs), Val::F64(rhs)) => { let lhs = f64::from_bits(*lhs);
let lhs = f64::from_bits(*lhs); let rhs = f64::from_bits(*rhs);
let rhs = f64::from_bits(*rhs); if lhs == rhs || (lhs.is_nan() && rhs.is_nan()) {
if lhs == rhs || (lhs.is_nan() && rhs.is_nan()) { continue;
continue; } else {
} else { fail()
fail() }
} }
(Val::AnyRef(_), Val::AnyRef(_)) | (Val::FuncRef(_), Val::FuncRef(_)) => {
continue
}
_ => fail(),
} }
(Val::AnyRef(_), Val::AnyRef(_)) | (Val::FuncRef(_), Val::FuncRef(_)) => {
continue
}
_ => fail(),
} }
} }
_ => fail(),
} }
_ => fail(),
} }
} }
@@ -287,6 +288,7 @@ fn assert_same_export_func_result(
#[cfg(feature = "binaryen")] #[cfg(feature = "binaryen")]
pub fn make_api_calls(api: crate::generators::api::ApiCalls) { pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
use crate::generators::api::ApiCall; use crate::generators::api::ApiCall;
use std::collections::HashMap;
crate::init_fuzzing(); crate::init_fuzzing();
@@ -401,7 +403,7 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
let nth = nth % funcs.len(); let nth = nth % funcs.len();
let f = &funcs[nth]; let f = &funcs[nth];
let ty = f.ty(); let ty = f.ty();
let params = match dummy_values(ty.params()) { let params = match dummy::dummy_values(ty.params()) {
Ok(p) => p, Ok(p) => p,
Err(_) => continue, Err(_) => continue,
}; };