Merge pull request rust-lang/libm#432 from tgross35/test-features

Rename the `test-multiprecision` feature to `build-mpfr`, enable by default
This commit is contained in:
Trevor Gross 2025-01-12 23:28:51 -05:00 committed by GitHub
commit 4d973b6144
8 changed files with 34 additions and 35 deletions

View file

@ -131,10 +131,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Download musl source
run: ./ci/download-musl.sh
- run: |
cargo clippy --all \
--features libm-test/build-musl,libm-test/test-multiprecision \
--all-targets
- run: cargo clippy --all --all-features --all-targets
builtins:
name: Check use with compiler-builtins
@ -241,7 +238,7 @@ jobs:
fi
LIBM_EXTENSIVE_TESTS="$CHANGED" cargo t \
--features test-multiprecision,unstable \
--features build-mpfr,unstable \
--profile release-checked \
-- extensive
- name: Print test logs if available

View file

@ -62,15 +62,12 @@ Check [PR #65] for an example.
Normal tests can be executed with:
```sh
cargo test
# `--release` ables more test cases
cargo test --release
```
If you'd like to run tests with randomized inputs that get compared against
infinite-precision results, run:
```sh
cargo test --features libm-test/test-multiprecision,libm-test/build-musl --release
```
If you are on a system that cannot build musl or MPFR, passing
`--no-default-features` will run some limited tests.
The multiprecision tests use the [`rug`] crate for bindings to MPFR. MPFR can
be difficult to build on non-Unix systems, refer to [`gmp_mpfr_sys`] for help.

View file

@ -14,7 +14,15 @@ if [ -z "$target" ]; then
target="$host_target"
fi
extra_flags=""
# We enumerate features manually.
extra_flags="--no-default-features"
# Enable arch-specific routines when available.
extra_flags="$extra_flags --features arch"
# Always enable `unstable-float` since it expands available API but does not
# change any implementations.
extra_flags="$extra_flags --features unstable-float"
# We need to specifically skip tests for musl-math-sys on systems that can't
# build musl since otherwise `--all` will activate it.
@ -44,11 +52,11 @@ case "$target" in
# Targets that aren't cross compiled work fine
# FIXME(ci): we should be able to enable aarch64 Linux here once GHA
# support rolls out.
x86_64*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
i686*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
i586*) extra_flags="$extra_flags --features libm-test/test-multiprecision --features gmp-mpfr-sys/force-cross" ;;
x86_64*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
i686*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
i586*) extra_flags="$extra_flags --features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross" ;;
# Apple aarch64 is native
aarch64*apple*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
aarch64*apple*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
esac
# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
@ -57,14 +65,8 @@ case "$target" in
*windows-gnu) extra_flags="$extra_flags --exclude libm-macros" ;;
esac
# Make sure we can build with overriding features. We test the indibidual
# features it controls separately.
cargo check --no-default-features
cargo check --features "force-soft-floats"
# Always enable `unstable-float` since it expands available API but does not
# change any implementations.
extra_flags="$extra_flags --features unstable-float"
# Make sure we can build with overriding features.
cargo check -p libm --no-default-features
if [ "${BUILD_ONLY:-}" = "1" ]; then
cmd="cargo build --target $target --package libm"
@ -80,11 +82,14 @@ else
$cmd --features unstable-intrinsics
$cmd --features unstable-intrinsics --benches
# Test the same in release mode, which also increases coverage.
# Test the same in release mode, which also increases coverage. Also ensure
# the soft float routines are checked.
$cmd --profile release-checked
$cmd --profile release-checked --features force-soft-floats
$cmd --profile release-checked --features unstable-intrinsics
$cmd --profile release-checked --features unstable-intrinsics --benches
ENSURE_NO_PANIC=1 cargo build --target "$target" --release
# Ensure that the routines do not panic.
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
fi

View file

@ -5,14 +5,14 @@ edition = "2021"
publish = false
[features]
default = ["unstable-float"]
default = ["build-mpfr", "build-musl", "unstable-float"]
# Propagated from libm because this affects which functions we test.
unstable-float = ["libm/unstable-float", "rug?/nightly-float"]
# Generate tests which are random inputs and the outputs are calculated with
# musl libc.
test-multiprecision = ["dep:az", "dep:rug", "dep:gmp-mpfr-sys"]
build-mpfr = ["dep:az", "dep:rug", "dep:gmp-mpfr-sys"]
# Build our own musl for testing and benchmarks
build-musl = ["dep:musl-math-sys"]

View file

@ -5,7 +5,7 @@
pub mod domain;
mod f8_impl;
pub mod gen;
#[cfg(feature = "test-multiprecision")]
#[cfg(feature = "build-mpfr")]
pub mod mpfloat;
mod num;
pub mod op;

View file

@ -126,7 +126,7 @@ impl TestEnv {
let id = ctx.fn_ident;
let op = id.math_op();
let will_run_mp = cfg!(feature = "test-multiprecision");
let will_run_mp = cfg!(feature = "build-mpfr");
// Tests are pretty slow on non-64-bit targets, x86 MacOS, and targets that run in QEMU. Start
// with a reduced number on these platforms.

View file

@ -1,6 +1,6 @@
//! Test with "infinite precision"
#![cfg(feature = "test-multiprecision")]
#![cfg(feature = "build-mpfr")]
use libm_test::domain::HasDomain;
use libm_test::gen::random::RandomInput;

View file

@ -1,14 +1,14 @@
//! `main` is just a wrapper to handle configuration.
#[cfg(not(feature = "test-multiprecision"))]
#[cfg(not(feature = "build-mpfr"))]
fn main() {
eprintln!("multiprecision not enabled; skipping extensive tests");
}
#[cfg(feature = "test-multiprecision")]
#[cfg(feature = "build-mpfr")]
mod run;
#[cfg(feature = "test-multiprecision")]
#[cfg(feature = "build-mpfr")]
fn main() {
run::run();
}