Skip to content

Commit a9d3ba4

Browse files
committed
Add way to override the number of iterations for specific tests
Certain functions (`fmodf128`) are significantly slower than others, to the point that running the default number of tests adds tens of minutes to PR CI and extensive test time increases to ~1day. It does not make sense to do this by default; so, introduce `EXTREMELY_SLOW_TESTS` to test configuration that allows setting specific tests that need to have a reduced iteration count.
1 parent bae270f commit a9d3ba4

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

crates/libm-test/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use op::{
2828
Ty,
2929
};
3030
pub use precision::{MaybeOverride, SpecialCase, default_ulp};
31-
use run_cfg::EXTENSIVE_MAX_ITERATIONS;
31+
use run_cfg::extensive_max_iterations;
3232
pub use run_cfg::{CheckBasis, CheckCtx, EXTENSIVE_ENV, GeneratorKind, skip_extensive_test};
3333
pub use test_traits::{CheckOutput, Hex, TupleCall};
3434

@@ -89,7 +89,7 @@ pub fn test_log(s: &str) {
8989
writeln!(f, "cargo features: {}", env!("CFG_CARGO_FEATURES")).unwrap();
9090
writeln!(f, "opt level: {}", env!("CFG_OPT_LEVEL")).unwrap();
9191
writeln!(f, "target features: {}", env!("CFG_TARGET_FEATURES")).unwrap();
92-
writeln!(f, "extensive iterations {}", *EXTENSIVE_MAX_ITERATIONS).unwrap();
92+
writeln!(f, "extensive iterations {}", extensive_max_iterations()).unwrap();
9393

9494
Some(f)
9595
});

crates/libm-test/src/run_cfg.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,27 @@ pub const EXTENSIVE_ENV: &str = "LIBM_EXTENSIVE_TESTS";
1313
/// Specify the number of iterations via this environment variable, rather than using the default.
1414
pub const EXTENSIVE_ITER_ENV: &str = "LIBM_EXTENSIVE_ITERATIONS";
1515

16+
/// The override value, if set by the above environment.
17+
static EXTENSIVE_ITER_OVERRIDE: LazyLock<Option<u64>> = LazyLock::new(|| {
18+
env::var(EXTENSIVE_ITER_ENV).map(|v| v.parse().expect("failed to parse iteration count")).ok()
19+
});
20+
21+
/// Specific tests that need to have a reduced amount of iterations to complete in a reasonable
22+
/// amount of time.
23+
///
24+
/// Contains the itentifier+generator combo to match on, plus the factor to reduce by.
25+
const EXTEMELY_SLOW_TESTS: &[(Identifier, GeneratorKind, u64)] = &[];
26+
1627
/// Maximum number of iterations to run for a single routine.
1728
///
1829
/// The default value of one greater than `u32::MAX` allows testing single-argument `f32` routines
1930
/// and single- or double-argument `f16` routines exhaustively. `f64` and `f128` can't feasibly
2031
/// be tested exhaustively; however, [`EXTENSIVE_ITER_ENV`] can be set to run tests for multiple
2132
/// hours.
22-
pub static EXTENSIVE_MAX_ITERATIONS: LazyLock<u64> = LazyLock::new(|| {
23-
let default = 1 << 32;
24-
env::var(EXTENSIVE_ITER_ENV)
25-
.map(|v| v.parse().expect("failed to parse iteration count"))
26-
.unwrap_or(default)
27-
});
33+
pub fn extensive_max_iterations() -> u64 {
34+
let default = 1 << 32; // default value
35+
EXTENSIVE_ITER_OVERRIDE.unwrap_or(default)
36+
}
2837

2938
/// Context passed to [`CheckOutput`].
3039
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -206,12 +215,23 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
206215
let mut total_iterations = match ctx.gen_kind {
207216
GeneratorKind::QuickSpaced => domain_iter_count,
208217
GeneratorKind::Random => random_iter_count,
209-
GeneratorKind::Extensive => *EXTENSIVE_MAX_ITERATIONS,
218+
GeneratorKind::Extensive => extensive_max_iterations(),
210219
GeneratorKind::EdgeCases => {
211220
unimplemented!("edge case tests shoudn't need `iteration_count`")
212221
}
213222
};
214223

224+
// Some tests are significantly slower than others and need to be further reduced.
225+
if let Some((_id, _gen, scale)) = EXTEMELY_SLOW_TESTS
226+
.iter()
227+
.find(|(id, gen, _scale)| *id == ctx.fn_ident && *gen == ctx.gen_kind)
228+
{
229+
// However, do not override if the extensive iteration count has been manually set.
230+
if !(ctx.gen_kind == GeneratorKind::Extensive && EXTENSIVE_ITER_OVERRIDE.is_some()) {
231+
total_iterations /= scale;
232+
}
233+
}
234+
215235
// FMA has a huge domain but is reasonably fast to run, so increase iterations.
216236
if ctx.base_name == BaseName::Fma {
217237
total_iterations *= 4;

0 commit comments

Comments
 (0)