Skip to content

Commit 14ec32e

Browse files
authored
Rollup merge of rust-lang#63404 - RalfJung:flt2dec, r=Centril
enable flt2dec tests in Miri With ldexp implemented (thanks to @christianpoveda), we can finally enable these tests in Miri. Well, most of them -- some are just too slow.
2 parents 171e845 + 29ca428 commit 14ec32e

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

src/libcore/tests/num/dec2flt/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn infinity() {
7777
fn zero() {
7878
test_literal!(0.0);
7979
test_literal!(1e-325);
80+
#[cfg(not(miri))] // Miri is too slow
8081
test_literal!(1e-326);
8182
#[cfg(not(miri))] // Miri is too slow
8283
test_literal!(1e-500);

src/libcore/tests/num/flt2dec/estimator.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ fn test_estimate_scaling_factor() {
4242
assert_almost_eq!(estimate_scaling_factor(1, -1074), -323);
4343
assert_almost_eq!(estimate_scaling_factor(0x1fffffffffffff, 971), 309);
4444

45-
for i in -1074..972 {
45+
#[cfg(not(miri))] // Miri is too slow
46+
let iter = -1074..972;
47+
#[cfg(miri)]
48+
let iter = (-1074..972).step_by(37);
49+
50+
for i in iter {
4651
let expected = super::ldexp_f64(1.0, i).log10().ceil();
4752
assert_almost_eq!(estimate_scaling_factor(1, i as i16), expected as i16);
4853
}

src/libcore/tests/num/flt2dec/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))] // Miri does not implement ldexp, which most tests here need
2-
31
use std::prelude::v1::*;
42
use std::{str, i16, f32, f64, fmt};
53

@@ -257,6 +255,7 @@ pub fn f32_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
257255
check_shortest!(f(minf32) => b"1", -44);
258256
}
259257

258+
#[cfg(not(miri))] // Miri is too slow
260259
pub fn f32_exact_sanity_test<F>(mut f: F)
261260
where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
262261
let minf32 = ldexp_f32(1.0, -149);
@@ -362,6 +361,7 @@ pub fn f64_shortest_sanity_test<F>(mut f: F) where F: FnMut(&Decoded, &mut [u8])
362361
check_shortest!(f(minf64) => b"5", -323);
363362
}
364363

364+
#[cfg(not(miri))] // Miri is too slow
365365
pub fn f64_exact_sanity_test<F>(mut f: F)
366366
where F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
367367
let minf64 = ldexp_f64(1.0, -1074);
@@ -553,6 +553,10 @@ pub fn to_shortest_str_test<F>(mut f_: F)
553553
assert_eq!(to_string(f, minf64, Minus, 324, false), format!("0.{:0>323}5", ""));
554554
assert_eq!(to_string(f, minf64, Minus, 325, false), format!("0.{:0>323}50", ""));
555555

556+
if cfg!(miri) { // Miri is too slow
557+
return;
558+
}
559+
556560
// very large output
557561
assert_eq!(to_string(f, 1.1, Minus, 80000, false), format!("1.1{:0>79999}", ""));
558562
}
@@ -807,6 +811,10 @@ pub fn to_exact_exp_str_test<F>(mut f_: F)
807811
"1.401298464324817070923729583289916131280261941876515771757068283\
808812
8897910826858606014866381883621215820312500000000000000000000000e-45");
809813

814+
if cfg!(miri) { // Miri is too slow
815+
return;
816+
}
817+
810818
assert_eq!(to_string(f, f64::MAX, Minus, 1, false), "2e308");
811819
assert_eq!(to_string(f, f64::MAX, Minus, 2, false), "1.8e308");
812820
assert_eq!(to_string(f, f64::MAX, Minus, 4, false), "1.798e308");
@@ -1040,6 +1048,10 @@ pub fn to_exact_fixed_str_test<F>(mut f_: F)
10401048
assert_eq!(to_string(f, f32::MAX, Minus, 2, false),
10411049
"340282346638528859811704183484516925440.00");
10421050

1051+
if cfg!(miri) { // Miri is too slow
1052+
return;
1053+
}
1054+
10431055
let minf32 = ldexp_f32(1.0, -149);
10441056
assert_eq!(to_string(f, minf32, Minus, 0, false), "0");
10451057
assert_eq!(to_string(f, minf32, Minus, 1, false), "0.0");

src/libcore/tests/num/flt2dec/random.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ pub fn f32_exhaustive_equivalence_test<F, G>(f: F, g: G, k: usize)
109109
#[test]
110110
fn shortest_random_equivalence_test() {
111111
use core::num::flt2dec::strategy::dragon::format_shortest as fallback;
112-
f64_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, 10_000);
113-
f32_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, 10_000);
112+
#[cfg(not(miri))] // Miri is too slow
113+
const N: usize = 10_000;
114+
#[cfg(miri)]
115+
const N: usize = 10;
116+
117+
f64_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, N);
118+
f32_random_equivalence_test(format_shortest_opt, fallback, MAX_SIG_DIGITS, N);
114119
}
115120

116121
#[test] #[ignore] // it is too expensive
@@ -138,17 +143,27 @@ fn shortest_f64_hard_random_equivalence_test() {
138143
#[test]
139144
fn exact_f32_random_equivalence_test() {
140145
use core::num::flt2dec::strategy::dragon::format_exact as fallback;
146+
#[cfg(not(miri))] // Miri is too slow
147+
const N: usize = 1_000;
148+
#[cfg(miri)]
149+
const N: usize = 3;
150+
141151
for k in 1..21 {
142152
f32_random_equivalence_test(|d, buf| format_exact_opt(d, buf, i16::MIN),
143-
|d, buf| fallback(d, buf, i16::MIN), k, 1_000);
153+
|d, buf| fallback(d, buf, i16::MIN), k, N);
144154
}
145155
}
146156

147157
#[test]
148158
fn exact_f64_random_equivalence_test() {
149159
use core::num::flt2dec::strategy::dragon::format_exact as fallback;
160+
#[cfg(not(miri))] // Miri is too slow
161+
const N: usize = 1_000;
162+
#[cfg(miri)]
163+
const N: usize = 3;
164+
150165
for k in 1..21 {
151166
f64_random_equivalence_test(|d, buf| format_exact_opt(d, buf, i16::MIN),
152-
|d, buf| fallback(d, buf, i16::MIN), k, 1_000);
167+
|d, buf| fallback(d, buf, i16::MIN), k, N);
153168
}
154169
}

src/libcore/tests/num/flt2dec/strategy/dragon.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn shortest_sanity_test() {
2323
}
2424

2525
#[test]
26+
#[cfg(not(miri))] // Miri is too slow
2627
fn exact_sanity_test() {
2728
// This test ends up running what I can only assume is some corner-ish case
2829
// of the `exp2` library function, defined in whatever C runtime we're

src/libcore/tests/num/flt2dec/strategy/grisu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn shortest_sanity_test() {
3636
}
3737

3838
#[test]
39+
#[cfg(not(miri))] // Miri is too slow
3940
fn exact_sanity_test() {
4041
// See comments in dragon.rs's exact_sanity_test for why this test is
4142
// ignored on MSVC

0 commit comments

Comments
 (0)