Add quickcheck tests

This commit is contained in:
est31 2017-02-03 22:06:36 +01:00
parent 417b07b821
commit b78e956f08
7 changed files with 171 additions and 0 deletions

View File

@ -60,6 +60,17 @@ fn main() {
"addsf3.c", "addsf3.c",
"powidf2.c", "powidf2.c",
"powisf2.c", "powisf2.c",
// 128 bit integers
"lshrti3.c",
"modti3.c",
"muloti4.c",
"multi3.c",
"udivmodti4.c",
"udivti3.c",
"umodti3.c",
"ashlti3.c",
"ashrti3.c",
"divti3.c",
]); ]);
for src in sources.files.iter() { for src in sources.files.iter() {

View File

@ -58,6 +58,33 @@ declare!(___adddf3, __adddf3);
declare!(___powisf2, __powisf2); declare!(___powisf2, __powisf2);
declare!(___powidf2, __powidf2); declare!(___powidf2, __powidf2);
#[cfg(all(not(windows), target_pointer_width="64"))]
pub mod int_128 {
extern {
fn __lshrti3();
fn __modti3();
fn __muloti4();
fn __multi3();
fn __udivmodti4();
fn __udivti3();
fn __umodti3();
fn __ashlti3();
fn __ashrti3();
fn __divti3();
}
declare!(___lshrti3, __lshrti3);
declare!(___modti3, __modti3);
declare!(___muloti4, __muloti4);
declare!(___multi3, __multi3);
declare!(___udivmodti4, __udivmodti4);
declare!(___udivti3, __udivti3);
declare!(___umodti3, __umodti3);
declare!(___ashlti3, __ashlti3);
declare!(___ashrti3, __ashrti3);
declare!(___divti3, __divti3);
}
#[lang = "eh_personality"] #[lang = "eh_personality"]
fn eh_personality() {} fn eh_personality() {}
#[lang = "panic_fmt"] #[lang = "panic_fmt"]

View File

@ -120,3 +120,27 @@ mod tests {
} }
} }
} }
#[cfg(test)]
#[cfg(all(not(windows), target_pointer_width="64"))]
mod tests_i128 {
use qc::I128;
check! {
fn __multi3(f: extern fn(i128, i128) -> i128, a: I128, b: I128)
-> Option<i128> {
Some(f(a.0, b.0))
}
fn __muloti4(f: extern fn(i128, i128, &mut i32) -> i128,
a: I128,
b: I128) -> Option<(i128, i32)> {
let (a, b) = (a.0, b.0);
let mut overflow = 2;
let r = f(a, b, &mut overflow);
if overflow != 0 && overflow != 1 {
return None
}
Some((r, overflow))
}
}
}

View File

@ -162,3 +162,29 @@ mod tests {
} }
} }
} }
#[cfg(test)]
#[cfg(all(not(windows), target_pointer_width="64"))]
mod tests_i128 {
use qc::U128;
check! {
fn __divti3(f: extern fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> {
let (n, d) = (n.0 as i128, d.0 as i128);
if d == 0 {
None
} else {
Some(f(n, d))
}
}
fn __modti3(f: extern fn(i128, i128) -> i128, n: U128, d: U128) -> Option<i128> {
let (n, d) = (n.0 as i128, d.0 as i128);
if d == 0 {
None
} else {
Some(f(n, d))
}
}
}
}

View File

@ -103,3 +103,39 @@ mod tests {
} }
} }
} }
#[cfg(test)]
#[cfg(all(not(windows), target_pointer_width="64"))]
mod tests_i128 {
use qc::{I128, U128};
// NOTE We purposefully stick to `u32` for `b` here because we want "small" values (b < 64)
check! {
fn __ashlti3(f: extern fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> {
let a = a.0;
if b >= 64 {
None
} else {
Some(f(a, b))
}
}
fn __ashrti3(f: extern fn(i128, u32) -> i128, a: I128, b: u32) -> Option<i128> {
let a = a.0;
if b >= 64 {
None
} else {
Some(f(a, b))
}
}
fn __lshrti3(f: extern fn(u128, u32) -> u128, a: U128, b: u32) -> Option<u128> {
let a = a.0;
if b >= 128 {
None
} else {
Some(f(a, b))
}
}
}
}

View File

@ -380,3 +380,48 @@ mod tests {
} }
} }
} }
#[cfg(test)]
#[cfg(all(not(windows), target_pointer_width="64"))]
mod tests_i128 {
use qc::U128;
check! {
fn __udivti3(f: extern fn(u128, u128) -> u128,
n: U128,
d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0);
if d == 0 {
None
} else {
Some(f(n, d))
}
}
fn __umodti3(f: extern fn(u128, u128) -> u128,
n: U128,
d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0);
if d == 0 {
None
} else {
Some(f(n, d))
}
}
fn __udivmodti4(f: extern fn(u128, u128, Option<&mut u128>) -> u128,
n: U128,
d: U128) -> Option<u128> {
let (n, d) = (n.0, d.0);
if d == 0 {
None
} else {
// FIXME fix the segfault when the remainder is requested
/*let mut r = 0;
let q = f(n, d, Some(&mut r));
Some((q, r))*/
Some(f(n, d, None))
}
}
}
}

View File

@ -144,6 +144,8 @@ macro_rules! arbitrary_large {
arbitrary_large!(I64: i64); arbitrary_large!(I64: i64);
arbitrary_large!(U64: u64); arbitrary_large!(U64: u64);
arbitrary_large!(I128: i128);
arbitrary_large!(U128: u128);
macro_rules! arbitrary_float { macro_rules! arbitrary_float {
($TY:ident : $ty:ident) => { ($TY:ident : $ty:ident) => {