Skip to content

Commit 954e3b7

Browse files
committed
Auto merge of #86 - mattico:multitester, r=japaric
Initial implementation of multitester Implements part of #72. I wanted to work on this first because it should help me find the problem in the add implementation. Test failures now look like this: ``` __addsf3 - Args: 1 1264853201 rustc-builtins: Some(0) compiler_rt: Some(14950609) gcc_s: None __addsf3 - Args: 1 632426600 rustc-builtins: Some(0) compiler_rt: Some(0.00000000000000030889195) gcc_s: None __addsf3 - Args: 1 316213300 rustc-builtins: Some(0) compiler_rt: Some(0.0000000000000000000000000013696648) gcc_s: None [snip] thread 'float::add::tests::_test::__addsf3' panicked at '[quickcheck] TEST FAILED. Arguments: (1, 1)', /home/matt/.cargo/registry/src/github.com-1ecc6299db9ec823/quickcheck-0.3.1/src/tester.rs:118 ``` It currently prints all of the errors, if that's undesirable we'd need to remove the shrinkers or modify quickcheck.
2 parents 0827f8c + 02140cd commit 954e3b7

File tree

2 files changed

+41
-54
lines changed

2 files changed

+41
-54
lines changed

src/float/add.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,13 @@ add!(__adddf3: f64);
186186
#[cfg(test)]
187187
mod tests {
188188
use core::{f32, f64};
189+
use core::fmt;
189190

190191
use float::Float;
191192
use qc::{U32, U64};
192193

193-
// NOTE The tests below have special handing for NaN values.
194-
// Because NaN != NaN, the floating-point representations must be used
195-
// Because there are many diffferent values of NaN, and the implementation
196-
// doesn't care about calculating the 'correct' one, if both values are NaN
197-
// the values are considered equivalent.
198-
194+
// TODO: Move this to F32/F64 in qc.rs
195+
#[derive(Copy, Clone)]
199196
struct FRepr<F>(F);
200197

201198
impl<F: Float> PartialEq for FRepr<F> {
@@ -212,6 +209,12 @@ mod tests {
212209
}
213210
}
214211

212+
impl<F: fmt::Debug> fmt::Debug for FRepr<F> {
213+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
214+
self.0.fmt(f)
215+
}
216+
}
217+
215218
// TODO: Add F32/F64 to qc so that they print the right values (at the very least)
216219
check! {
217220
fn __addsf3(f: extern fn(f32, f32) -> f32,

src/qc.rs

+32-48
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ macro_rules! check {
195195
}
196196
)*
197197

198-
mod _compiler_rt {
198+
mod _test {
199199
use qc::*;
200200
use std::mem;
201201
use quickcheck::TestResult;
@@ -207,56 +207,40 @@ macro_rules! check {
207207
let my_answer = super::$name(super::super::$name,
208208
$($arg),*);
209209
let compiler_rt_fn = ::compiler_rt::get(stringify!($name));
210-
unsafe {
211-
let compiler_rt_answer =
212-
super::$name(mem::transmute(compiler_rt_fn),
213-
$($arg),*);
214-
match (my_answer, compiler_rt_answer) {
215-
(None, _) | (_, None) => TestResult::discard(),
216-
(Some(a), Some(b)) => {
217-
TestResult::from_bool(a == b)
218-
}
219-
}
220-
}
221-
}
222-
223-
::quickcheck::quickcheck(my_check as fn($($t),*) -> TestResult)
224-
}
225-
)*
226-
}
227-
228-
mod _gcc_s {
229-
use qc::*;
230-
use std::mem;
231-
use quickcheck::TestResult;
232-
233-
$(
234-
#[test]
235-
fn $name() {
236-
fn my_check($($arg:$t),*) -> TestResult {
237-
let my_answer = super::$name(super::super::$name,
238-
$($arg),*);
239-
let gcc_s_fn = ::gcc_s::get(stringify!($name)).unwrap();
240-
unsafe {
241-
let gcc_s_answer =
242-
super::$name(mem::transmute(gcc_s_fn),
243-
$($arg),*);
244-
match (my_answer, gcc_s_answer) {
245-
(None, _) | (_, None) => TestResult::discard(),
246-
(Some(a), Some(b)) => {
247-
TestResult::from_bool(a == b)
248-
}
249-
}
210+
let compiler_rt_answer = unsafe {
211+
super::$name(mem::transmute(compiler_rt_fn),
212+
$($arg),*)
213+
};
214+
let gcc_s_answer =
215+
match ::gcc_s::get(stringify!($name)) {
216+
Some(f) => unsafe {
217+
Some(super::$name(mem::transmute(f),
218+
$($arg),*))
219+
},
220+
None => None,
221+
};
222+
223+
let print_values = || {
224+
print!("{} - Args: ", stringify!($name));
225+
$(print!("{:?} ", $arg);)*
226+
print!("\n");
227+
println!(" rustc-builtins: {:?}", my_answer);
228+
println!(" compiler_rt: {:?}", compiler_rt_answer);
229+
println!(" gcc_s: {:?}", gcc_s_answer);
230+
};
231+
232+
if my_answer != compiler_rt_answer {
233+
print_values();
234+
TestResult::from_bool(false)
235+
} else if gcc_s_answer.is_some() &&
236+
my_answer != gcc_s_answer.unwrap() {
237+
print_values();
238+
TestResult::from_bool(false)
239+
} else {
240+
TestResult::from_bool(true)
250241
}
251242
}
252243

253-
// If it's not in libgcc, or we couldn't find libgcc, then
254-
// just ignore this. We should have tests through
255-
// compiler-rt in any case
256-
if ::gcc_s::get(stringify!($name)).is_none() {
257-
return
258-
}
259-
260244
::quickcheck::quickcheck(my_check as fn($($t),*) -> TestResult)
261245
}
262246
)*

0 commit comments

Comments
 (0)