@@ -22,13 +22,38 @@ static EXTENSIVE_ITER_OVERRIDE: LazyLock<Option<u64>> = LazyLock::new(|| {
22
22
23
23
/// Specific tests that need to have a reduced amount of iterations to complete in a reasonable
24
24
/// 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
+ } ,
30
38
] ;
31
39
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
+
32
57
/// Maximum number of iterations to run for a single routine.
33
58
///
34
59
/// The default value of one greater than `u32::MAX` allows testing single-argument `f32` routines
@@ -54,6 +79,7 @@ pub struct CheckCtx {
54
79
/// Source of truth for tests.
55
80
pub basis : CheckBasis ,
56
81
pub gen_kind : GeneratorKind ,
82
+ pub extensive : bool ,
57
83
/// If specified, this value will override the value returned by [`iteration_count`].
58
84
pub override_iterations : Option < u64 > ,
59
85
}
@@ -69,12 +95,19 @@ impl CheckCtx {
69
95
base_name_str : fn_ident. base_name ( ) . as_str ( ) ,
70
96
basis,
71
97
gen_kind,
98
+ extensive : false ,
72
99
override_iterations : None ,
73
100
} ;
74
101
ret. ulp = crate :: default_ulp ( & ret) ;
75
102
ret
76
103
}
77
104
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
+
78
111
/// The number of input arguments for this function.
79
112
pub fn input_count ( & self ) -> usize {
80
113
self . fn_ident . math_op ( ) . rust_sig . args . len ( )
@@ -100,14 +133,17 @@ pub enum CheckBasis {
100
133
/// and quantity.
101
134
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
102
135
pub enum GeneratorKind {
136
+ /// Extremes, zeros, nonstandard numbers, etc.
103
137
EdgeCases ,
104
- Extensive ,
105
- QuickSpaced ,
138
+ /// Spaced by logarithm (floats) or linear (integers).
139
+ Spaced ,
140
+ /// Test inputs from an RNG.
106
141
Random ,
142
+ /// A provided test case list.
107
143
List ,
108
144
}
109
145
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 .
111
147
///
112
148
/// This also supports the special test name `all` to run all tests, as well as `all_f16`,
113
149
/// `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 {
216
252
let random_iter_count = domain_iter_count / 100 ;
217
253
218
254
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,
220
257
GeneratorKind :: Random => random_iter_count,
221
- GeneratorKind :: Extensive => extensive_max_iterations ( ) ,
222
258
GeneratorKind :: EdgeCases | GeneratorKind :: List => {
223
259
unimplemented ! ( "shoudn't need `iteration_count` for {:?}" , ctx. gen_kind)
224
260
}
225
261
} ;
226
262
227
263
// 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 {
230
266
// Extensive already has a pretty high test count.
231
267
total_iterations *= 2 ;
232
268
} else {
@@ -244,13 +280,13 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
244
280
}
245
281
246
282
// 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
248
284
. iter ( )
249
- . find ( |( id , generator , _scale ) | * id == ctx . fn_ident && * generator == ctx. gen_kind )
285
+ . find ( |slow| slow . matches_ctx ( ctx) )
250
286
{
251
287
// 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 ;
254
290
}
255
291
}
256
292
@@ -279,7 +315,7 @@ pub fn iteration_count(ctx: &CheckCtx, argnum: usize) -> u64 {
279
315
let total = ntests. pow ( t_env. input_count . try_into ( ) . unwrap ( ) ) ;
280
316
281
317
let seed_msg = match ctx. gen_kind {
282
- GeneratorKind :: QuickSpaced | GeneratorKind :: Extensive => String :: new ( ) ,
318
+ GeneratorKind :: Spaced => String :: new ( ) ,
283
319
GeneratorKind :: Random => {
284
320
format ! (
285
321
" using `{SEED_ENV}={}`" ,
@@ -327,8 +363,8 @@ pub fn int_range(ctx: &CheckCtx, argnum: usize) -> RangeInclusive<i32> {
327
363
let extensive_range = ( -0xfff ) ..=0xfffff ;
328
364
329
365
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,
332
368
GeneratorKind :: EdgeCases => extensive_range,
333
369
GeneratorKind :: List => unimplemented ! ( "shoudn't need range for {:?}" , ctx. gen_kind) ,
334
370
}
0 commit comments