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

Commit 1d1d7de

Browse files
committed
Move CheckBasis and CheckCtx to a new run_cfg module
These are used more places than just test traits, so this new module should be a better home. `run_cfg` will also be expanded in the near future.
1 parent 5c5df51 commit 1d1d7de

File tree

3 files changed

+55
-39
lines changed

3 files changed

+55
-39
lines changed

crates/libm-test/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ pub mod mpfloat;
88
mod num;
99
pub mod op;
1010
mod precision;
11+
mod run_cfg;
1112
mod test_traits;
1213

1314
pub use f8_impl::f8;
1415
pub use libm::support::{Float, Int, IntTy, MinInt};
1516
pub use num::{FloatExt, logspace};
1617
pub use op::{BaseName, FloatTy, Identifier, MathOp, OpCFn, OpFTy, OpRustFn, OpRustRet, Ty};
1718
pub use precision::{MaybeOverride, SpecialCase, default_ulp};
18-
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};
19+
pub use run_cfg::{CheckBasis, CheckCtx};
20+
pub use test_traits::{CheckOutput, GenerateInput, Hex, TupleCall};
1921

2022
/// Result type for tests is usually from `anyhow`. Most times there is no success value to
2123
/// propagate.

crates/libm-test/src/run_cfg.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//! Configuration for how tests get run.
2+
3+
#![allow(unused)]
4+
5+
use std::collections::BTreeMap;
6+
use std::env;
7+
use std::sync::LazyLock;
8+
9+
use crate::{BaseName, FloatTy, Identifier, op};
10+
11+
pub const EXTENSIVE_ENV: &str = "LIBM_EXTENSIVE_TESTS";
12+
13+
/// Context passed to [`CheckOutput`].
14+
#[derive(Clone, Debug, PartialEq, Eq)]
15+
pub struct CheckCtx {
16+
/// Allowed ULP deviation
17+
pub ulp: u32,
18+
pub fn_ident: Identifier,
19+
pub base_name: BaseName,
20+
/// Function name.
21+
pub fn_name: &'static str,
22+
/// Return the unsuffixed version of the function name.
23+
pub base_name_str: &'static str,
24+
/// Source of truth for tests.
25+
pub basis: CheckBasis,
26+
}
27+
28+
impl CheckCtx {
29+
/// Create a new check context, using the default ULP for the function.
30+
pub fn new(fn_ident: Identifier, basis: CheckBasis) -> Self {
31+
let mut ret = Self {
32+
ulp: 0,
33+
fn_ident,
34+
fn_name: fn_ident.as_str(),
35+
base_name: fn_ident.base_name(),
36+
base_name_str: fn_ident.base_name().as_str(),
37+
basis,
38+
};
39+
ret.ulp = crate::default_ulp(&ret);
40+
ret
41+
}
42+
}
43+
44+
/// Possible items to test against
45+
#[derive(Clone, Debug, PartialEq, Eq)]
46+
pub enum CheckBasis {
47+
/// Check against Musl's math sources.
48+
Musl,
49+
/// Check against infinite precision (MPFR).
50+
Mpfr,
51+
}

crates/libm-test/src/test_traits.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,7 @@ use std::fmt;
1111

1212
use anyhow::{Context, bail, ensure};
1313

14-
use crate::{BaseName, Float, Identifier, Int, MaybeOverride, SpecialCase, TestResult};
15-
16-
/// Context passed to [`CheckOutput`].
17-
#[derive(Clone, Debug, PartialEq, Eq)]
18-
pub struct CheckCtx {
19-
/// Allowed ULP deviation
20-
pub ulp: u32,
21-
pub fn_ident: Identifier,
22-
pub base_name: BaseName,
23-
/// Function name.
24-
pub fn_name: &'static str,
25-
/// Source of truth for tests.
26-
pub basis: CheckBasis,
27-
}
28-
29-
impl CheckCtx {
30-
/// Create a new check context, using the default ULP for the function.
31-
pub fn new(fn_ident: Identifier, basis: CheckBasis) -> Self {
32-
let mut ret = Self {
33-
ulp: 0,
34-
fn_ident,
35-
fn_name: fn_ident.as_str(),
36-
base_name: fn_ident.base_name(),
37-
basis,
38-
};
39-
ret.ulp = crate::default_ulp(&ret);
40-
ret
41-
}
42-
}
43-
44-
/// Possible items to test against
45-
#[derive(Clone, Debug, PartialEq, Eq)]
46-
pub enum CheckBasis {
47-
/// Check against Musl's math sources.
48-
Musl,
49-
/// Check against infinite precision (MPFR).
50-
Mpfr,
51-
}
14+
use crate::{CheckCtx, Float, Int, MaybeOverride, SpecialCase, TestResult};
5215

5316
/// Implement this on types that can generate a sequence of tuples for test input.
5417
pub trait GenerateInput<TupleArgs> {

0 commit comments

Comments
 (0)