diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-07-20 11:04:47 -0500 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-07-20 11:39:34 -0500 |
| commit | 59429e67f91e9db38ea2dca8f2a99ec42aea68d7 (patch) | |
| tree | 2dd41d8672abf3ee0fd0cdcfc2d2debeb21f04bc /src/etc/test-float-parse/README.md | |
| parent | 2e6fc425411280c658d852813de01c5157255088 (diff) | |
| download | rust-59429e67f91e9db38ea2dca8f2a99ec42aea68d7.tar.gz rust-59429e67f91e9db38ea2dca8f2a99ec42aea68d7.zip | |
Rewrite `test-float-parse` in Rust
The existing implementation uses Python to launch a set of Rust-written binaries. Unfortunately, this is currently broken; it seems that some updates meant it no longer compiles. There is also a problem that support for more float types (`f16`, `f128`) would be difficult to add since this is very specialized to `f32` and `f64`. Because of these sortcomings, migrate to a version written in Rust. This version should be significantly faster; test generators can execute in parallel, and test cases are chunked and parallelized. This should also resolve the preexisting "... the worker processes are leaked and stick around forever" comment. This change also introduces genericism over float types and properties, meaning it will be much easier to extend support to newly added types. `num::BigRational` is used in place of Python's fractions for infinite-precision calculations.
Diffstat (limited to 'src/etc/test-float-parse/README.md')
| -rw-r--r-- | src/etc/test-float-parse/README.md | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/etc/test-float-parse/README.md b/src/etc/test-float-parse/README.md new file mode 100644 index 00000000000..21b20d0a072 --- /dev/null +++ b/src/etc/test-float-parse/README.md @@ -0,0 +1,55 @@ +# Float Parsing Tests + +These are tests designed to test decimal to float conversions (`dec2flt`) used +by the standard library. + +It consistes of a collection of test generators that each generate a set of +patterns intended to test a specific property. In addition, there are exhaustive +tests (for <= `f32`) and fuzzers (for anything that can't be run exhaustively). + +The generators work as follows: + +- Each generator is a struct that lives somewhere in the `gen` module. Usually + it is generic over a float type. +- These generators must implement `Iterator`, which should return a context type + that can be used to construct a test string (but usually not the string + itself). +- They must also implement the `Generator` trait, which provides a method to + write test context to a string as a test case, as well as some extra metadata. + + The split between context generation and string construction is so that we can + reuse string allocations. +- Each generator gets registered once for each float type. Each of these + generators then get their iterator called, and each test case checked against + the float type's parse implementation. + +Some generators produce decimal strings, others create bit patterns that need to +be bitcasted to the float type, which then uses its `Display` implementation to +write to a string. For these, float to decimal (`flt2dec`) conversions also get +tested, if unintentionally. + +For each test case, the following is done: + +- The test string is parsed to the float type using the standard library's + implementation. +- The test string is parsed separately to a `BigRational`, which acts as a + representation with infinite precision. +- The rational value then gets checked that it is within the float's + representable values (absolute value greater than the smallest number to round + to zero, but less less than the first value to round to infinity). If these + limits are exceeded, check that the parsed float reflects that. +- For real nonzero numbers, the parsed float is converted into a rational using + `significand * 2^exponent`. It is then checked against the actual rational + value, and verified to be within half a bit's precision of the parsed value. + Also it is checked that ties round to even. + +This is all highly parallelized with `rayon`; test generators can run in +parallel, and their tests get chunked and run in parallel. + +There is a simple command line that allows filtering which tests are run, +setting the number of iterations for fuzzing tests, limiting failures, setting +timeouts, etc. See `main.rs` or run with `--help` for options. + +Note that when running via `./x`, only tests that take less than a few minutes +are run by default. Navigate to the crate (or pass `-C` to Cargo) and run it +directly to run all tests or pass specific arguments. |
