From 11d970dae73d55533271e25e3ec8de8beaddcbd6 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 13 Feb 2026 09:53:15 -0600 Subject: [PATCH 1/3] test-float-parse: Upgrade dependencies --- Cargo.lock | 275 +++++++++++++++++- src/bootstrap/src/utils/proc_macro_deps.rs | 19 ++ src/tools/test-float-parse/Cargo.toml | 8 +- src/tools/test-float-parse/src/gen_/fuzz.rs | 2 +- .../test-float-parse/src/gen_/many_digits.rs | 2 +- 5 files changed, 285 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4c1a02c018af..f931752071dda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -565,6 +565,17 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.0", +] + [[package]] name = "chrono" version = "0.4.42" @@ -892,6 +903,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "console" +version = "0.16.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d64e8af5551369d19cf50138de61f1c42074ab970f74e99be916646777f8fc87" +dependencies = [ + "encode_unicode", + "libc", + "windows-sys 0.61.2", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -926,6 +948,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.0" @@ -1585,10 +1616,24 @@ checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 5.3.0", "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.0", + "wasip2", + "wasip3", +] + [[package]] name = "gimli" version = "0.31.1" @@ -1968,13 +2013,24 @@ version = "0.17.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" dependencies = [ - "console", + "console 0.15.11", "number_prefix", "portable-atomic", "unicode-width 0.2.2", "web-time", ] +[[package]] +name = "indicatif" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25470f23803092da7d239834776d653104d551bc4d7eacaf31e6837854b8e9eb" +dependencies = [ + "console 0.16.3", + "portable-atomic", + "unit-prefix", +] + [[package]] name = "indoc" version = "1.0.9" @@ -2999,9 +3055,9 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.11.1" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" @@ -3074,6 +3130,16 @@ dependencies = [ "owo-colors", ] +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.110", +] + [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -3163,6 +3229,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rancor" version = "0.1.1" @@ -3193,6 +3265,17 @@ dependencies = [ "rand_core 0.9.3", ] +[[package]] +name = "rand" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.0", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -3213,6 +3296,16 @@ dependencies = [ "rand_core 0.9.3", ] +[[package]] +name = "rand_chacha" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e6af7f3e25ded52c41df4e0b1af2d047e45896c2f3281792ed68a1c243daedb" +dependencies = [ + "ppv-lite86", + "rand_core 0.10.0", +] + [[package]] name = "rand_core" version = "0.6.4" @@ -3231,6 +3324,12 @@ dependencies = [ "getrandom 0.3.3", ] +[[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + [[package]] name = "rand_xorshift" version = "0.4.0" @@ -5209,7 +5308,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -5220,7 +5319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -5531,10 +5630,10 @@ checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" name = "test-float-parse" version = "0.1.0" dependencies = [ - "indicatif", + "indicatif 0.18.4", "num", - "rand 0.9.2", - "rand_chacha 0.9.0", + "rand 0.10.0", + "rand_chacha 0.10.0", "rayon", ] @@ -5946,7 +6045,7 @@ dependencies = [ "colored 3.0.0", "comma", "crossbeam-channel", - "indicatif", + "indicatif 0.17.11", "levenshtein", "prettydiff", "regex", @@ -6083,6 +6182,12 @@ dependencies = [ "diff", ] +[[package]] +name = "unit-prefix" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3" + [[package]] name = "unstable-book-gen" version = "0.1.0" @@ -6202,6 +6307,24 @@ version = "40.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb5e2b9858989c3a257de4ca169977f4f79897b64e4f482f188f4fcf8ac557d1" +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.105" @@ -6264,8 +6387,8 @@ dependencies = [ "wat", "windows-sys 0.61.2", "winsplit", - "wit-component", - "wit-parser", + "wit-component 0.245.1", + "wit-parser 0.245.1", ] [[package]] @@ -6285,6 +6408,16 @@ dependencies = [ "wasmparser 0.219.2", ] +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser 0.244.0", +] + [[package]] name = "wasm-encoder" version = "0.245.1" @@ -6295,6 +6428,18 @@ dependencies = [ "wasmparser 0.245.1", ] +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder 0.244.0", + "wasmparser 0.244.0", +] + [[package]] name = "wasm-metadata" version = "0.245.1" @@ -6327,6 +6472,18 @@ dependencies = [ "indexmap", ] +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "wasmparser" version = "0.245.1" @@ -6771,6 +6928,26 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck 0.5.0", + "wit-parser 0.244.0", +] + [[package]] name = "wit-bindgen-rt" version = "0.39.0" @@ -6780,6 +6957,56 @@ dependencies = [ "bitflags", ] +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck 0.5.0", + "indexmap", + "prettyplease", + "syn 2.0.110", + "wasm-metadata 0.244.0", + "wit-bindgen-core", + "wit-component 0.244.0", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.110", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder 0.244.0", + "wasm-metadata 0.244.0", + "wasmparser 0.244.0", + "wit-parser 0.244.0", +] + [[package]] name = "wit-component" version = "0.245.1" @@ -6794,9 +7021,27 @@ dependencies = [ "serde_derive", "serde_json", "wasm-encoder 0.245.1", - "wasm-metadata", + "wasm-metadata 0.245.1", "wasmparser 0.245.1", - "wit-parser", + "wit-parser 0.245.1", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser 0.244.0", ] [[package]] diff --git a/src/bootstrap/src/utils/proc_macro_deps.rs b/src/bootstrap/src/utils/proc_macro_deps.rs index fee9b12aca069..8472c61f82c3c 100644 --- a/src/bootstrap/src/utils/proc_macro_deps.rs +++ b/src/bootstrap/src/utils/proc_macro_deps.rs @@ -3,9 +3,12 @@ /// See pub static CRATES: &[&str] = &[ // tidy-alphabetical-start + "allocator-api2", + "anyhow", "askama_derive", "askama_parser", "basic-toml", + "bitflags", "block-buffer", "bumpalo", "cfg-if", @@ -24,24 +27,32 @@ pub static CRATES: &[&str] = &[ "generic-array", "hashbrown", "heck", + "id-arena", "ident_case", "indexmap", "intl-memoizer", "intl_pluralrules", + "itoa", + "leb128fmt", "libc", + "log", "memchr", "minimal-lexical", "nom", "pest", "pest_generator", "pest_meta", + "prettyplease", "proc-macro2", "quote", "rustc-hash", + "ryu", "self_cell", + "semver", "serde", "serde_core", "serde_derive_internals", + "serde_json", "sha2", "smallvec", "stable_deref_trait", @@ -57,10 +68,18 @@ pub static CRATES: &[&str] = &[ "unic-langid-impl", "unic-langid-macros", "unicode-ident", + "unicode-xid", "version_check", "wasm-bindgen-macro-support", "wasm-bindgen-shared", + "wasm-encoder", + "wasm-metadata", + "wasmparser", "winnow", + "wit-bindgen-core", + "wit-bindgen-rust", + "wit-component", + "wit-parser", "yoke", "zerofrom", "zerovec", diff --git a/src/tools/test-float-parse/Cargo.toml b/src/tools/test-float-parse/Cargo.toml index e407e322f9e19..5208b1eee9393 100644 --- a/src/tools/test-float-parse/Cargo.toml +++ b/src/tools/test-float-parse/Cargo.toml @@ -5,11 +5,11 @@ edition = "2024" publish = false [dependencies] -indicatif = { version = "0.17.8", default-features = false } +indicatif = { version = "0.18.4", default-features = false } num = "0.4.3" -rand = "0.9.0" -rand_chacha = "0.9.0" -rayon = "1" +rand = "0.10.0" +rand_chacha = "0.10.0" +rayon = "1.11.0" [lib] name = "test_float_parse" diff --git a/src/tools/test-float-parse/src/gen_/fuzz.rs b/src/tools/test-float-parse/src/gen_/fuzz.rs index 1d6c5562a14c8..dc13d688e624e 100644 --- a/src/tools/test-float-parse/src/gen_/fuzz.rs +++ b/src/tools/test-float-parse/src/gen_/fuzz.rs @@ -5,7 +5,7 @@ use std::marker::PhantomData; use std::ops::Range; use std::sync::Mutex; -use rand::Rng; +use rand::RngExt; use rand::distr::{Distribution, StandardUniform}; use rand_chacha::ChaCha8Rng; use rand_chacha::rand_core::SeedableRng; diff --git a/src/tools/test-float-parse/src/gen_/many_digits.rs b/src/tools/test-float-parse/src/gen_/many_digits.rs index 741e11437fe29..7d9f931d42b88 100644 --- a/src/tools/test-float-parse/src/gen_/many_digits.rs +++ b/src/tools/test-float-parse/src/gen_/many_digits.rs @@ -4,7 +4,7 @@ use std::marker::PhantomData; use std::ops::{Range, RangeInclusive}; use rand::distr::{Distribution, Uniform}; -use rand::{Rng, SeedableRng}; +use rand::{RngExt, SeedableRng}; use rand_chacha::ChaCha8Rng; use crate::{Float, Generator, SEED}; From cdcab4c1f2eee74fd9a9163be672c7116c410235 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 13 Feb 2026 18:12:49 -0600 Subject: [PATCH 2/3] test-float-parse: Be more accurate about optimization warning Currently we warn if `debug_assertions` is set, but this isn't always accurate because debug assertions can be on at higher optimization levels. Forward some information from the build script and print it to tell a better story, and update the warning to act on opt-level and profile rather than `debug_assertions`. --- Cargo.toml | 4 ++-- src/tools/test-float-parse/build.rs | 9 +++++++++ src/tools/test-float-parse/src/main.rs | 16 ++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/tools/test-float-parse/build.rs diff --git a/Cargo.toml b/Cargo.toml index 67c7a9d67edc8..dd0d5841441fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,8 @@ strip = true debug = 0 strip = true -# Bigint libraries are slow without optimization, speed up testing +# Bigint libraries are slow without optimization, speed up testing. Note that this doesn't affect +# its dependencies, it should still be run in release mode where possible. [profile.dev.package.test-float-parse] opt-level = 3 @@ -92,4 +93,3 @@ codegen-units = 1 # If you want to use a crate with local modifications, you can set a path or git dependency here. # For git dependencies, also add your source to ALLOWED_SOURCES in src/tools/tidy/src/extdeps.rs. #[patch.crates-io] - diff --git a/src/tools/test-float-parse/build.rs b/src/tools/test-float-parse/build.rs new file mode 100644 index 0000000000000..dbb56dc781b71 --- /dev/null +++ b/src/tools/test-float-parse/build.rs @@ -0,0 +1,9 @@ +use std::env; + +fn main() { + // Forward the opt level so we can warn if the tests are going to be slow. + let opt = env::var("OPT_LEVEL").expect("OPT_LEVEL unset"); + let profile = env::var("PROFILE").expect("PROFILE unset"); + println!("cargo::rustc-env=OPT_LEVEL={opt}"); + println!("cargo::rustc-env=PROFILE={profile}"); +} diff --git a/src/tools/test-float-parse/src/main.rs b/src/tools/test-float-parse/src/main.rs index 9c6cad7324f74..c049c094fe6b4 100644 --- a/src/tools/test-float-parse/src/main.rs +++ b/src/tools/test-float-parse/src/main.rs @@ -39,12 +39,24 @@ enum ArgMode { } fn main() -> ExitCode { - if cfg!(debug_assertions) { + let opt = env!("OPT_LEVEL"); + let profile = env!("PROFILE"); + + println!("Crate config:"); + println!(" opt level: {opt}"); + println!(" profile: {profile}"); + println!(" debug assertions: {}", cfg!(debug_assertions)); + + if !matches!(opt, "2" | "3") || profile != "release" { + // Warn for `profile != release` because optimizations being on for this crate (always, + // via the workspace Cargo.toml) may not mean they are on for dependencies. println!( - "WARNING: running in debug mode. Release mode is recommended to reduce test duration." + "WARNING: test-float-parse may be running unoptimized or with unoptimized \ + dependencies. Release mode is recommended to reduce test duration." ); std::thread::sleep(Duration::from_secs(2)); } + println!("Running with debug assertions={}", cfg!(debug_assertions)); let args: Vec<_> = std::env::args().skip(1).collect(); if args.iter().any(|arg| arg == "--help" || arg == "-h") { From 32a2893ba23c60a7cad7ad2b6fd7102f7c1f463a Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 13 Feb 2026 09:55:47 -0600 Subject: [PATCH 3/3] test-float-parse: Use an overrideable random seed Currently `test-float-parse` is mostly random tests which take a fixed seed, meaning the same set of values get tested for each invocation. This isn't ideal because we don't get the true benefit of randomness, which is to have better coverage over time. Improve this by using a randomly generated seed, which can also be set via env. The seed is printed at the beginning of each run so it is easy to reproduce failures using the same test set, if needed. Typically it isn't great to have fuzzing randomness in tests that get run in CI because it can lead to spurious failures. However, this is a test for which failure should never happen becasue the algorithms are reasonably well proven, so if one does occur it represents a very unexpected bug that needs to be addressed. The error message is updated to strongly recommend reporting before retrying and to include details on how to reproduce. --- src/tools/test-float-parse/src/gen_/fuzz.rs | 2 +- .../test-float-parse/src/gen_/many_digits.rs | 2 +- src/tools/test-float-parse/src/lib.rs | 47 +++++++++++++++++-- src/tools/test-float-parse/src/ui.rs | 12 ++++- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/tools/test-float-parse/src/gen_/fuzz.rs b/src/tools/test-float-parse/src/gen_/fuzz.rs index dc13d688e624e..f5917c081c6e9 100644 --- a/src/tools/test-float-parse/src/gen_/fuzz.rs +++ b/src/tools/test-float-parse/src/gen_/fuzz.rs @@ -62,7 +62,7 @@ where } fn new() -> Self { - let rng = ChaCha8Rng::from_seed(SEED); + let rng = ChaCha8Rng::from_seed(SEED.0); Self { iter: 0..Self::total_tests(), rng, marker: PhantomData } } diff --git a/src/tools/test-float-parse/src/gen_/many_digits.rs b/src/tools/test-float-parse/src/gen_/many_digits.rs index 7d9f931d42b88..bec70f93d001e 100644 --- a/src/tools/test-float-parse/src/gen_/many_digits.rs +++ b/src/tools/test-float-parse/src/gen_/many_digits.rs @@ -39,7 +39,7 @@ impl Generator for RandDigits { } fn new() -> Self { - let rng = ChaCha8Rng::from_seed(SEED); + let rng = ChaCha8Rng::from_seed(SEED.0); let range = Uniform::try_from(0..10).unwrap(); Self { rng, iter: 0..ITERATIONS, uniform: range, marker: PhantomData } diff --git a/src/tools/test-float-parse/src/lib.rs b/src/tools/test-float-parse/src/lib.rs index da83aeea3c132..278396ca4e1dd 100644 --- a/src/tools/test-float-parse/src/lib.rs +++ b/src/tools/test-float-parse/src/lib.rs @@ -10,11 +10,13 @@ use std::any::type_name; use std::cmp::min; use std::ops::RangeInclusive; use std::process::ExitCode; -use std::sync::OnceLock; use std::sync::atomic::{AtomicU64, Ordering}; -use std::{fmt, time}; +use std::sync::{LazyLock, OnceLock}; +use std::{env, fmt, time}; +use rand::TryRng; use rand::distr::{Distribution, StandardUniform}; +use rand::rngs::SysRng; use rayon::prelude::*; use time::{Duration, Instant}; use traits::{Float, Generator, Int}; @@ -44,8 +46,41 @@ const MAX_BITS_FOR_EXHAUUSTIVE: u32 = 32; /// `--skip-huge`. const HUGE_TEST_CUTOFF: u64 = 5_000_000; -/// Seed for tests that use a deterministic RNG. -const SEED: [u8; 32] = *b"3.141592653589793238462643383279"; +const SEED_ENV: &str = "TEST_FLOAT_PARSE_SEED"; + +/// Seed for tests that use a deterministic RNG, and its b64 representation for printing. Taken +/// from env if provided, +static SEED: LazyLock<([u8; 32], Box)> = LazyLock::new(|| { + let seed = match env::var(SEED_ENV) { + Ok(s) => { + seed_from_str(&s).unwrap_or_else(|| panic!("{SEED_ENV} must be 32 bytes, hex encoded")) + } + Err(_) => { + let mut seed = [0u8; 32]; + SysRng.try_fill_bytes(&mut seed).unwrap(); + seed + } + }; + + let lo = u128::from_le_bytes(seed[..16].try_into().unwrap()); + let hi = u128::from_le_bytes(seed[16..].try_into().unwrap()); + let encoded = format!("{hi:032x}{lo:032x}").into_boxed_str(); + + (seed, encoded) +}); + +fn seed_from_str(s: &str) -> Option<[u8; 32]> { + let hi = s.get(..32)?; + let hi = u128::from_str_radix(hi, 16).ok()?; + let lo = s.get(32..)?; + let lo = u128::from_str_radix(lo, 16).ok()?; + + let mut out = [0u8; 32]; + out[..16].copy_from_slice(&lo.to_le_bytes()); + out[16..].copy_from_slice(&hi.to_le_bytes()); + + Some(out) +} /// Global configuration. #[derive(Debug)] @@ -78,8 +113,10 @@ pub fn run(cfg: Config, include: &[String], exclude: &[String]) -> ExitCode { let threads = std::thread::available_parallelism().map(Into::into).unwrap_or(0) * 3 / 2; rayon::ThreadPoolBuilder::new().num_threads(threads).build_global().unwrap(); + println!("Starting test runner"); + println!("Using {SEED_ENV}={}`", SEED.1); let mut tests = register_tests(&cfg); - println!("registered"); + println!("Tests registered"); let initial_tests: Vec<_> = tests.iter().map(|t| t.name.clone()).collect(); let unmatched: Vec<_> = include diff --git a/src/tools/test-float-parse/src/ui.rs b/src/tools/test-float-parse/src/ui.rs index 1a9ba0dc1d99c..420f3f0bacd81 100644 --- a/src/tools/test-float-parse/src/ui.rs +++ b/src/tools/test-float-parse/src/ui.rs @@ -8,7 +8,7 @@ use std::time::Duration; use indicatif::{ProgressBar, ProgressStyle}; -use crate::{Completed, Config, EarlyExit, FinishedAll, TestInfo}; +use crate::{Completed, Config, EarlyExit, FinishedAll, SEED, SEED_ENV, TestInfo}; /// Templates for progress bars. const PB_TEMPLATE: &str = "[{elapsed:3} {percent:3}%] {bar:20.cyan/blue} NAME \ @@ -135,6 +135,16 @@ pub fn finish_all(tests: &[TestInfo], total_elapsed: Duration, cfg: &Config) -> ); if failed_generators > 0 || stopped_generators > 0 { + println!(); + println!( + "ERROR: Some float parsing/printing tests failed.\n\ + \n\ + If you ever encounter this failure when not expected, PLEASE OPEN AN ISSUE!! The \ + failure will likely go away on the next run, but may represent a real bug.\n\ + \n\ + To reproduce, rerun with the same seed: {}={}", + SEED_ENV, SEED.1 + ); ExitCode::FAILURE } else { ExitCode::SUCCESS