Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 076d7f7

Browse files
committed
Add way to override more
1 parent a7863ad commit 076d7f7

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

crates/libm-test/src/lib.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ 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. Contains the itentifier+generator combo to match on, plus the factor to
23+
/// reduce by.
24+
const EXTEMELY_SLOW_TESTS: &[(Identifier, Option<GeneratorKind>)] = &[];
25+
1626
/// Maximum number of iterations to run for a single routine.
1727
///
1828
/// The default value of one greater than `u32::MAX` allows testing single-argument `f32` routines
1929
/// and single- or double-argument `f16` routines exhaustively. `f64` and `f128` can't feasibly
2030
/// be tested exhaustively; however, [`EXTENSIVE_ITER_ENV`] can be set to run tests for multiple
2131
/// 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-
});
32+
pub fn extensive_max_iterations() -> u64 {
33+
let default = 1 << 32; // default value
34+
EXTENSIVE_ITER_OVERRIDE.unwrap_or(default)
35+
}
2836

2937
/// Context passed to [`CheckOutput`].
3038
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -206,12 +214,23 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
206214
let mut total_iterations = match ctx.gen_kind {
207215
GeneratorKind::QuickSpaced => domain_iter_count,
208216
GeneratorKind::Random => random_iter_count,
209-
GeneratorKind::Extensive => *EXTENSIVE_MAX_ITERATIONS,
217+
GeneratorKind::Extensive => extensive_max_iterations(),
210218
GeneratorKind::EdgeCases => {
211219
unimplemented!("edge case tests shoudn't need `iteration_count`")
212220
}
213221
};
214222

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

0 commit comments

Comments
 (0)