Skip to content

Commit b31d50e

Browse files
authored
Merge pull request #615 from tgross35/test-refactoring
Rework the test crate to separate individual tests
2 parents 449643f + 658cac7 commit b31d50e

File tree

7 files changed

+756
-615
lines changed

7 files changed

+756
-615
lines changed

testcrate/tests/addsub.rs

+118-108
Original file line numberDiff line numberDiff line change
@@ -4,139 +4,149 @@
44

55
use testcrate::*;
66

7-
macro_rules! sum {
8-
($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => {
9-
$(
10-
fuzz_2(N, |x: $i, y: $i| {
11-
let add0 = x.wrapping_add(y);
12-
let sub0 = x.wrapping_sub(y);
13-
let add1: $i = $fn_add(x, y);
14-
let sub1: $i = $fn_sub(x, y);
15-
if add0 != add1 {
16-
panic!(
17-
"{}({}, {}): std: {}, builtins: {}",
18-
stringify!($fn_add), x, y, add0, add1
19-
);
20-
}
21-
if sub0 != sub1 {
22-
panic!(
23-
"{}({}, {}): std: {}, builtins: {}",
24-
stringify!($fn_sub), x, y, sub0, sub1
25-
);
26-
}
27-
});
28-
)*
29-
};
30-
}
7+
mod int_addsub {
8+
use super::*;
319

32-
macro_rules! overflowing_sum {
33-
($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => {
34-
$(
35-
fuzz_2(N, |x: $i, y: $i| {
36-
let add0 = x.overflowing_add(y);
37-
let sub0 = x.overflowing_sub(y);
38-
let add1: ($i, bool) = $fn_add(x, y);
39-
let sub1: ($i, bool) = $fn_sub(x, y);
40-
if add0.0 != add1.0 || add0.1 != add1.1 {
41-
panic!(
42-
"{}({}, {}): std: {:?}, builtins: {:?}",
43-
stringify!($fn_add), x, y, add0, add1
44-
);
45-
}
46-
if sub0.0 != sub1.0 || sub0.1 != sub1.1 {
47-
panic!(
48-
"{}({}, {}): std: {:?}, builtins: {:?}",
49-
stringify!($fn_sub), x, y, sub0, sub1
50-
);
10+
macro_rules! sum {
11+
($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => {
12+
$(
13+
#[test]
14+
fn $fn_add() {
15+
use compiler_builtins::int::addsub::{$fn_add, $fn_sub};
16+
17+
fuzz_2(N, |x: $i, y: $i| {
18+
let add0 = x.wrapping_add(y);
19+
let sub0 = x.wrapping_sub(y);
20+
let add1: $i = $fn_add(x, y);
21+
let sub1: $i = $fn_sub(x, y);
22+
if add0 != add1 {
23+
panic!(
24+
"{}({}, {}): std: {}, builtins: {}",
25+
stringify!($fn_add), x, y, add0, add1
26+
);
27+
}
28+
if sub0 != sub1 {
29+
panic!(
30+
"{}({}, {}): std: {}, builtins: {}",
31+
stringify!($fn_sub), x, y, sub0, sub1
32+
);
33+
}
34+
});
5135
}
52-
});
53-
)*
54-
};
55-
}
36+
)*
37+
};
38+
}
39+
40+
macro_rules! overflowing_sum {
41+
($($i:ty, $fn_add:ident, $fn_sub:ident);*;) => {
42+
$(
43+
#[test]
44+
fn $fn_add() {
45+
use compiler_builtins::int::addsub::{$fn_add, $fn_sub};
5646

57-
#[test]
58-
fn addsub() {
59-
use compiler_builtins::int::addsub::{
60-
__rust_i128_add, __rust_i128_addo, __rust_i128_sub, __rust_i128_subo, __rust_u128_add,
61-
__rust_u128_addo, __rust_u128_sub, __rust_u128_subo,
62-
};
47+
fuzz_2(N, |x: $i, y: $i| {
48+
let add0 = x.overflowing_add(y);
49+
let sub0 = x.overflowing_sub(y);
50+
let add1: ($i, bool) = $fn_add(x, y);
51+
let sub1: ($i, bool) = $fn_sub(x, y);
52+
if add0.0 != add1.0 || add0.1 != add1.1 {
53+
panic!(
54+
"{}({}, {}): std: {:?}, builtins: {:?}",
55+
stringify!($fn_add), x, y, add0, add1
56+
);
57+
}
58+
if sub0.0 != sub1.0 || sub0.1 != sub1.1 {
59+
panic!(
60+
"{}({}, {}): std: {:?}, builtins: {:?}",
61+
stringify!($fn_sub), x, y, sub0, sub1
62+
);
63+
}
64+
});
65+
}
66+
)*
67+
};
68+
}
6369

6470
// Integer addition and subtraction is very simple, so 100 fuzzing passes should be plenty.
65-
sum!(
71+
sum! {
6672
u128, __rust_u128_add, __rust_u128_sub;
6773
i128, __rust_i128_add, __rust_i128_sub;
68-
);
69-
overflowing_sum!(
74+
}
75+
76+
overflowing_sum! {
7077
u128, __rust_u128_addo, __rust_u128_subo;
7178
i128, __rust_i128_addo, __rust_i128_subo;
72-
);
79+
}
7380
}
7481

7582
macro_rules! float_sum {
7683
($($f:ty, $fn_add:ident, $fn_sub:ident, $apfloat_ty:ident, $sys_available:meta);*;) => {
7784
$(
78-
fuzz_float_2(N, |x: $f, y: $f| {
79-
let add0 = apfloat_fallback!($f, $apfloat_ty, $sys_available, Add::add, x, y);
80-
let sub0 = apfloat_fallback!($f, $apfloat_ty, $sys_available, Sub::sub, x, y);
81-
let add1: $f = $fn_add(x, y);
82-
let sub1: $f = $fn_sub(x, y);
83-
if !Float::eq_repr(add0, add1) {
84-
panic!(
85-
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
86-
stringify!($fn_add), x, y, add0, add1
87-
);
88-
}
89-
if !Float::eq_repr(sub0, sub1) {
90-
panic!(
91-
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
92-
stringify!($fn_sub), x, y, sub0, sub1
93-
);
94-
}
95-
});
85+
#[test]
86+
fn $fn_add() {
87+
use core::ops::{Add, Sub};
88+
use compiler_builtins::float::{{add::$fn_add, sub::$fn_sub}, Float};
89+
90+
fuzz_float_2(N, |x: $f, y: $f| {
91+
let add0 = apfloat_fallback!($f, $apfloat_ty, $sys_available, Add::add, x, y);
92+
let sub0 = apfloat_fallback!($f, $apfloat_ty, $sys_available, Sub::sub, x, y);
93+
let add1: $f = $fn_add(x, y);
94+
let sub1: $f = $fn_sub(x, y);
95+
if !Float::eq_repr(add0, add1) {
96+
panic!(
97+
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
98+
stringify!($fn_add), x, y, add0, add1
99+
);
100+
}
101+
if !Float::eq_repr(sub0, sub1) {
102+
panic!(
103+
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
104+
stringify!($fn_sub), x, y, sub0, sub1
105+
);
106+
}
107+
});
108+
}
96109
)*
97110
}
98111
}
99112

100113
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
101-
#[test]
102-
fn float_addsub() {
103-
use compiler_builtins::float::{
104-
add::{__adddf3, __addsf3},
105-
sub::{__subdf3, __subsf3},
106-
Float,
107-
};
108-
use core::ops::{Add, Sub};
109-
110-
float_sum!(
114+
mod float_addsub {
115+
use super::*;
116+
117+
float_sum! {
111118
f32, __addsf3, __subsf3, Single, all();
112119
f64, __adddf3, __subdf3, Double, all();
113-
);
114-
115-
#[cfg(not(feature = "no-f16-f128"))]
116-
{
117-
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
118-
use compiler_builtins::float::{add::__addkf3 as __addtf3, sub::__subkf3 as __subtf3};
119-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
120-
use compiler_builtins::float::{add::__addtf3, sub::__subtf3};
121-
122-
float_sum!(
123-
f128, __addtf3, __subtf3, Quad, not(feature = "no-sys-f128");
124-
);
120+
}
121+
}
122+
123+
#[cfg(not(feature = "no-f16-f128"))]
124+
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
125+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
126+
mod float_addsub_f128 {
127+
use super::*;
128+
129+
float_sum! {
130+
f128, __addtf3, __subtf3, Quad, not(feature = "no-sys-f128");
131+
}
132+
}
133+
134+
#[cfg(not(feature = "no-f16-f128"))]
135+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
136+
mod float_addsub_f128_ppc {
137+
use super::*;
138+
139+
float_sum! {
140+
f128, __addkf3, __subkf3, Quad, not(feature = "no-sys-f128");
125141
}
126142
}
127143

128144
#[cfg(target_arch = "arm")]
129-
#[test]
130-
fn float_addsub_arm() {
131-
use compiler_builtins::float::{
132-
add::{__adddf3vfp, __addsf3vfp},
133-
sub::{__subdf3vfp, __subsf3vfp},
134-
Float,
135-
};
136-
use core::ops::{Add, Sub};
137-
138-
float_sum!(
145+
mod float_addsub_arm {
146+
use super::*;
147+
148+
float_sum! {
139149
f32, __addsf3vfp, __subsf3vfp, Single, all();
140150
f64, __adddf3vfp, __subdf3vfp, Double, all();
141-
);
151+
}
142152
}

0 commit comments

Comments
 (0)