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

Commit 36ed2a5

Browse files
authored
Merge pull request #432 from tgross35/test-features
Rename the `test-multiprecision` feature to `build-mpfr`, enable by default
2 parents a7a1be1 + 6eef4db commit 36ed2a5

File tree

8 files changed

+34
-35
lines changed

8 files changed

+34
-35
lines changed

libm/.github/workflows/main.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ jobs:
131131
- uses: Swatinem/rust-cache@v2
132132
- name: Download musl source
133133
run: ./ci/download-musl.sh
134-
- run: |
135-
cargo clippy --all \
136-
--features libm-test/build-musl,libm-test/test-multiprecision \
137-
--all-targets
134+
- run: cargo clippy --all --all-features --all-targets
138135

139136
builtins:
140137
name: Check use with compiler-builtins
@@ -241,7 +238,7 @@ jobs:
241238
fi
242239
243240
LIBM_EXTENSIVE_TESTS="$CHANGED" cargo t \
244-
--features test-multiprecision,unstable \
241+
--features build-mpfr,unstable \
245242
--profile release-checked \
246243
-- extensive
247244
- name: Print test logs if available

libm/CONTRIBUTING.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ Check [PR #65] for an example.
6262
Normal tests can be executed with:
6363

6464
```sh
65-
cargo test
65+
# `--release` ables more test cases
66+
cargo test --release
6667
```
6768

68-
If you'd like to run tests with randomized inputs that get compared against
69-
infinite-precision results, run:
70-
71-
```sh
72-
cargo test --features libm-test/test-multiprecision,libm-test/build-musl --release
73-
```
69+
If you are on a system that cannot build musl or MPFR, passing
70+
`--no-default-features` will run some limited tests.
7471

7572
The multiprecision tests use the [`rug`] crate for bindings to MPFR. MPFR can
7673
be difficult to build on non-Unix systems, refer to [`gmp_mpfr_sys`] for help.

libm/ci/run.sh

+20-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ if [ -z "$target" ]; then
1414
target="$host_target"
1515
fi
1616

17-
extra_flags=""
17+
# We enumerate features manually.
18+
extra_flags="--no-default-features"
19+
20+
# Enable arch-specific routines when available.
21+
extra_flags="$extra_flags --features arch"
22+
23+
# Always enable `unstable-float` since it expands available API but does not
24+
# change any implementations.
25+
extra_flags="$extra_flags --features unstable-float"
1826

1927
# We need to specifically skip tests for musl-math-sys on systems that can't
2028
# build musl since otherwise `--all` will activate it.
@@ -44,11 +52,11 @@ case "$target" in
4452
# Targets that aren't cross compiled work fine
4553
# FIXME(ci): we should be able to enable aarch64 Linux here once GHA
4654
# support rolls out.
47-
x86_64*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
48-
i686*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
49-
i586*) extra_flags="$extra_flags --features libm-test/test-multiprecision --features gmp-mpfr-sys/force-cross" ;;
55+
x86_64*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
56+
i686*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
57+
i586*) extra_flags="$extra_flags --features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross" ;;
5058
# Apple aarch64 is native
51-
aarch64*apple*) extra_flags="$extra_flags --features libm-test/test-multiprecision" ;;
59+
aarch64*apple*) extra_flags="$extra_flags --features libm-test/build-mpfr" ;;
5260
esac
5361

5462
# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
@@ -57,14 +65,8 @@ case "$target" in
5765
*windows-gnu) extra_flags="$extra_flags --exclude libm-macros" ;;
5866
esac
5967

60-
# Make sure we can build with overriding features. We test the indibidual
61-
# features it controls separately.
62-
cargo check --no-default-features
63-
cargo check --features "force-soft-floats"
64-
65-
# Always enable `unstable-float` since it expands available API but does not
66-
# change any implementations.
67-
extra_flags="$extra_flags --features unstable-float"
68+
# Make sure we can build with overriding features.
69+
cargo check -p libm --no-default-features
6870

6971
if [ "${BUILD_ONLY:-}" = "1" ]; then
7072
cmd="cargo build --target $target --package libm"
@@ -80,11 +82,14 @@ else
8082
$cmd --features unstable-intrinsics
8183
$cmd --features unstable-intrinsics --benches
8284

83-
# Test the same in release mode, which also increases coverage.
85+
# Test the same in release mode, which also increases coverage. Also ensure
86+
# the soft float routines are checked.
8487
$cmd --profile release-checked
88+
$cmd --profile release-checked --features force-soft-floats
8589
$cmd --profile release-checked --features unstable-intrinsics
8690
$cmd --profile release-checked --features unstable-intrinsics --benches
8791

88-
ENSURE_NO_PANIC=1 cargo build --target "$target" --release
92+
# Ensure that the routines do not panic.
93+
ENSURE_NO_PANIC=1 cargo build -p libm --target "$target" --no-default-features --release
8994
fi
9095

libm/crates/libm-test/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ edition = "2021"
55
publish = false
66

77
[features]
8-
default = ["unstable-float"]
8+
default = ["build-mpfr", "build-musl", "unstable-float"]
99

1010
# Propagated from libm because this affects which functions we test.
1111
unstable-float = ["libm/unstable-float", "rug?/nightly-float"]
1212

1313
# Generate tests which are random inputs and the outputs are calculated with
1414
# musl libc.
15-
test-multiprecision = ["dep:az", "dep:rug", "dep:gmp-mpfr-sys"]
15+
build-mpfr = ["dep:az", "dep:rug", "dep:gmp-mpfr-sys"]
1616

1717
# Build our own musl for testing and benchmarks
1818
build-musl = ["dep:musl-math-sys"]

libm/crates/libm-test/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pub mod domain;
66
mod f8_impl;
77
pub mod gen;
8-
#[cfg(feature = "test-multiprecision")]
8+
#[cfg(feature = "build-mpfr")]
99
pub mod mpfloat;
1010
mod num;
1111
pub mod op;

libm/crates/libm-test/src/run_cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl TestEnv {
126126
let id = ctx.fn_ident;
127127
let op = id.math_op();
128128

129-
let will_run_mp = cfg!(feature = "test-multiprecision");
129+
let will_run_mp = cfg!(feature = "build-mpfr");
130130

131131
// Tests are pretty slow on non-64-bit targets, x86 MacOS, and targets that run in QEMU. Start
132132
// with a reduced number on these platforms.

libm/crates/libm-test/tests/multiprecision.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Test with "infinite precision"
22
3-
#![cfg(feature = "test-multiprecision")]
3+
#![cfg(feature = "build-mpfr")]
44

55
use libm_test::domain::HasDomain;
66
use libm_test::gen::random::RandomInput;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! `main` is just a wrapper to handle configuration.
22
3-
#[cfg(not(feature = "test-multiprecision"))]
3+
#[cfg(not(feature = "build-mpfr"))]
44
fn main() {
55
eprintln!("multiprecision not enabled; skipping extensive tests");
66
}
77

8-
#[cfg(feature = "test-multiprecision")]
8+
#[cfg(feature = "build-mpfr")]
99
mod run;
1010

11-
#[cfg(feature = "test-multiprecision")]
11+
#[cfg(feature = "build-mpfr")]
1212
fn main() {
1313
run::run();
1414
}

0 commit comments

Comments
 (0)