Skip to content

Commit 502a114

Browse files
committed
libm-test: Make extensive an attribute rather than a test type
Currently we run logspace tests for extensive tests, but there isn't any reason we couldn't also run more kinds of tests more extensively (e.g. more edge cases, combine edge cases with logspace for multi-input functions, etc). As a first step toward making this possible, make `extensive` a new field in `CheckCtx`, and rename `QuickSpaced` to `Spaced`.
1 parent 7f37311 commit 502a114

File tree

6 files changed

+60
-25
lines changed

6 files changed

+60
-25
lines changed

libm-test/benches/icount.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! icount_benches {
2323
let mut ctx = CheckCtx::new(
2424
Op::IDENTIFIER,
2525
CheckBasis::None,
26-
GeneratorKind::QuickSpaced
26+
GeneratorKind::Spaced
2727
);
2828
ctx.override_iterations(BENCH_ITER_ITEMS);
2929
let ret = spaced::get_test_cases::<Op>(&ctx).0.collect::<Vec<_>>();

libm-test/examples/plot_domains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ where
5555
Op: MathOp<FTy = f32, RustArgs = (f32,)>,
5656
Op::RustArgs: SpacedInput<Op>,
5757
{
58-
let mut ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr, GeneratorKind::QuickSpaced);
58+
let mut ctx = CheckCtx::new(Op::IDENTIFIER, CheckBasis::Mpfr, GeneratorKind::Spaced);
5959
plot_one_generator(
6060
out_dir,
6161
&ctx,

libm-test/src/run_cfg.rs

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,38 @@ static EXTENSIVE_ITER_OVERRIDE: LazyLock<Option<u64>> = LazyLock::new(|| {
2222

2323
/// Specific tests that need to have a reduced amount of iterations to complete in a reasonable
2424
/// amount of time.
25-
///
26-
/// Contains the itentifier+generator combo to match on, plus the factor to reduce by.
27-
const EXTEMELY_SLOW_TESTS: &[(Identifier, GeneratorKind, u64)] = &[
28-
(Identifier::Fmodf128, GeneratorKind::QuickSpaced, 50),
29-
(Identifier::Fmodf128, GeneratorKind::Extensive, 50),
25+
const EXTREMELY_SLOW_TESTS: &[SlowTest] = &[
26+
SlowTest {
27+
ident: Identifier::Fmodf128,
28+
gen_kind: GeneratorKind::Spaced,
29+
extensive: false,
30+
reduce_factor: 50,
31+
},
32+
SlowTest {
33+
ident: Identifier::Fmodf128,
34+
gen_kind: GeneratorKind::Spaced,
35+
extensive: true,
36+
reduce_factor: 50,
37+
},
3038
];
3139

40+
/// A pattern to match a `CheckCtx`, plus a factor to reduce by.
41+
struct SlowTest {
42+
ident: Identifier,
43+
gen_kind: GeneratorKind,
44+
extensive: bool,
45+
reduce_factor: u64,
46+
}
47+
48+
impl SlowTest {
49+
/// True if the test in `CheckCtx` should be reduced by `reduce_factor`.
50+
fn matches_ctx(&self, ctx: &CheckCtx) -> bool {
51+
self.ident == ctx.fn_ident
52+
&& self.gen_kind == ctx.gen_kind
53+
&& self.extensive == ctx.extensive
54+
}
55+
}
56+
3257
/// Maximum number of iterations to run for a single routine.
3358
///
3459
/// The default value of one greater than `u32::MAX` allows testing single-argument `f32` routines
@@ -54,6 +79,7 @@ pub struct CheckCtx {
5479
/// Source of truth for tests.
5580
pub basis: CheckBasis,
5681
pub gen_kind: GeneratorKind,
82+
pub extensive: bool,
5783
/// If specified, this value will override the value returned by [`iteration_count`].
5884
pub override_iterations: Option<u64>,
5985
}
@@ -69,12 +95,19 @@ impl CheckCtx {
6995
base_name_str: fn_ident.base_name().as_str(),
7096
basis,
7197
gen_kind,
98+
extensive: false,
7299
override_iterations: None,
73100
};
74101
ret.ulp = crate::default_ulp(&ret);
75102
ret
76103
}
77104

105+
/// Configure that this is an extensive test.
106+
pub fn extensive(mut self, extensive: bool) -> Self {
107+
self.extensive = extensive;
108+
self
109+
}
110+
78111
/// The number of input arguments for this function.
79112
pub fn input_count(&self) -> usize {
80113
self.fn_ident.math_op().rust_sig.args.len()
@@ -100,14 +133,17 @@ pub enum CheckBasis {
100133
/// and quantity.
101134
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
102135
pub enum GeneratorKind {
136+
/// Extremes, zeros, nonstandard numbers, etc.
103137
EdgeCases,
104-
Extensive,
105-
QuickSpaced,
138+
/// Spaced by logarithm (floats) or linear (integers).
139+
Spaced,
140+
/// Test inputs from an RNG.
106141
Random,
142+
/// A provided test case list.
107143
List,
108144
}
109145

110-
/// A list of all functions that should get extensive tests.
146+
/// A list of all functions that should get extensive tests, as configured by environment variable.
111147
///
112148
/// This also supports the special test name `all` to run all tests, as well as `all_f16`,
113149
/// `all_f32`, `all_f64`, and `all_f128` to run all tests for a specific float type.
@@ -216,17 +252,17 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
216252
let random_iter_count = domain_iter_count / 100;
217253

218254
let mut total_iterations = match ctx.gen_kind {
219-
GeneratorKind::QuickSpaced => domain_iter_count,
255+
GeneratorKind::Spaced if ctx.extensive => extensive_max_iterations(),
256+
GeneratorKind::Spaced => domain_iter_count,
220257
GeneratorKind::Random => random_iter_count,
221-
GeneratorKind::Extensive => extensive_max_iterations(),
222258
GeneratorKind::EdgeCases | GeneratorKind::List => {
223259
unimplemented!("shoudn't need `iteration_count` for {:?}", ctx.gen_kind)
224260
}
225261
};
226262

227263
// Larger float types get more iterations.
228-
if t_env.large_float_ty && ctx.gen_kind != GeneratorKind::Extensive {
229-
if ctx.gen_kind == GeneratorKind::Extensive {
264+
if t_env.large_float_ty {
265+
if ctx.extensive {
230266
// Extensive already has a pretty high test count.
231267
total_iterations *= 2;
232268
} else {
@@ -244,13 +280,13 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
244280
}
245281

246282
// Some tests are significantly slower than others and need to be further reduced.
247-
if let Some((_id, _gen, scale)) = EXTEMELY_SLOW_TESTS
283+
if let Some(slow) = EXTREMELY_SLOW_TESTS
248284
.iter()
249-
.find(|(id, generator, _scale)| *id == ctx.fn_ident && *generator == ctx.gen_kind)
285+
.find(|slow| slow.matches_ctx(ctx))
250286
{
251287
// However, do not override if the extensive iteration count has been manually set.
252-
if !(ctx.gen_kind == GeneratorKind::Extensive && EXTENSIVE_ITER_OVERRIDE.is_some()) {
253-
total_iterations /= scale;
288+
if !(ctx.extensive && EXTENSIVE_ITER_OVERRIDE.is_some()) {
289+
total_iterations /= slow.reduce_factor;
254290
}
255291
}
256292

@@ -279,7 +315,7 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
279315
let total = ntests.pow(t_env.input_count.try_into().unwrap());
280316

281317
let seed_msg = match ctx.gen_kind {
282-
GeneratorKind::QuickSpaced | GeneratorKind::Extensive => String::new(),
318+
GeneratorKind::Spaced => String::new(),
283319
GeneratorKind::Random => {
284320
format!(
285321
" using `{SEED_ENV}={}`",
@@ -327,8 +363,8 @@ pub fn int_range(ctx: &CheckCtx, argnum: usize) -> RangeInclusive<i32> {
327363
let extensive_range = (-0xfff)..=0xfffff;
328364

329365
match ctx.gen_kind {
330-
GeneratorKind::Extensive => extensive_range,
331-
GeneratorKind::QuickSpaced | GeneratorKind::Random => non_extensive_range,
366+
_ if ctx.extensive => extensive_range,
367+
GeneratorKind::Spaced | GeneratorKind::Random => non_extensive_range,
332368
GeneratorKind::EdgeCases => extensive_range,
333369
GeneratorKind::List => unimplemented!("shoudn't need range for {:?}", ctx.gen_kind),
334370
}

libm-test/tests/compare_built_musl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ macro_rules! musl_tests {
6565
$(#[$attr])*
6666
fn [< musl_quickspace_ $fn_name >]() {
6767
type Op = libm_test::op::$fn_name::Routine;
68-
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::QuickSpaced);
68+
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::Spaced);
6969
let cases = spaced::get_test_cases::<Op>(&ctx).0;
7070
musl_runner::<Op>(&ctx, cases, musl_math_sys::$fn_name);
7171
}

libm-test/tests/multiprecision.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ macro_rules! mp_tests {
5555
$(#[$attr])*
5656
fn [< mp_quickspace_ $fn_name >]() {
5757
type Op = libm_test::op::$fn_name::Routine;
58-
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::QuickSpaced);
58+
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::Spaced);
5959
let cases = spaced::get_test_cases::<Op>(&ctx).0;
6060
mp_runner::<Op>(&ctx, cases);
6161
}

libm-test/tests/z_extensive/run.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rayon::prelude::*;
1717
use spaced::SpacedInput;
1818

1919
const BASIS: CheckBasis = CheckBasis::Mpfr;
20-
const GEN_KIND: GeneratorKind = GeneratorKind::Extensive;
2120

2221
/// Run the extensive test suite.
2322
pub fn run() {
@@ -77,7 +76,7 @@ where
7776
Op::RustArgs: SpacedInput<Op> + Send,
7877
{
7978
let test_name = format!("mp_extensive_{}", Op::NAME);
80-
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GEN_KIND);
79+
let ctx = CheckCtx::new(Op::IDENTIFIER, BASIS, GeneratorKind::Spaced).extensive(true);
8180
let skip = skip_extensive_test(&ctx);
8281

8382
let runner = move || {

0 commit comments

Comments
 (0)