-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Unify and deduplicate float tests #141726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I prototyped a macro that would let us write tests like this: #[test]
fn test_min() {
float_test!(
for Float in (
#[cfg(target_has_reliable_f16_math)] f16,
f32, f64,
#[cfg(target_has_reliable_f128_math)] #[cfg(not(miri))] f128,
const { f16, f32, f64, f128, },
) {
float_assert!((0.0 as Float).min(0.0), 0.0);
}
);
} See the playground for sources. @tgross35 what do you think? |
Maybe pull the |
Hm yeah that should work: float_test!(min:
for Float in (
#[cfg(target_has_reliable_f16_math)] f16,
f32, f64,
#[cfg(target_has_reliable_f128_math)] #[cfg(not(miri))] f128,
const { f16, f32, f64, f128, },
) {
float_assert!((0.0 as Float).min(0.0), 0.0);
}
); Output:
|
Something like that seems reasonable enough to me. The config is a bit messy to read, but I don't have any better proposals. Instead of Also note that changes here may race with #141669, hopefully that one can get in first. |
Modules and macros interact in funny ways, but this variant seems to work. I made it so that the entire test is put in a const block for the const versions. This has the advantage that if you use a macro that does not have a special const version, it'll still execute at const-time properly. It has the disadvantage that failing const tests fail when the test is being built, not when it is executed.
I intended to wait for some other stuff anyway before making an attempt here -- so I can just wait for that PR as well. |
Turns out we have even more tests in |
As a possible alternative, I prototyped something that always emits tests for all float types so we don't accidentally forget any, but allows adding specific config. #[cfg(test)]
float_test! {
name: min,
attrs: {
f16: [cfg(target_has_reliable_f16_math)],
// no f64 tests for whatever reason
f64: [cfg(false)],
const f64: [cfg(false)],
// Not implemented with miri
f128: [cfg(target_has_reliable_f128_math), cfg(miri)],
const f128: [cfg(target_has_reliable_f128_math), cfg(miri)],
},
tests: {
assert!(!Float::NAN.min(0.0).is_nan(), "unexpected nan");
assert_eq!((0.0 as Float).min(0.0), 0.0, "hi");
},
}
Hopefully more of that will move to core in the future anyway :) |
The way that works, if I use any other test macro those tests will not actually be run at const-time ever. (But that's orthogonal to always emitting all types vs iterating over the list of types.) I figured iterating over the list would be needed to make this handle all cases, but I like your approach with |
coretests: move float tests from num to floats module and use a more flexible macro to generate them This makes some progress on rust-lang#141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough. I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR.
coretests: move float tests from num to floats module and use a more flexible macro to generate them This makes some progress on #141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough. I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR. <!-- homu-ignore:start --> <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> <!-- homu-ignore:end --> try-job: x86_64-gnu-aux
coretests: move float tests from num to floats module and use a more flexible macro to generate them This makes some progress on rust-lang#141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough. I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR. try-job: x86_64-gnu-aux
coretests: move float tests from num to floats module and use a more flexible macro to generate them This makes some progress on rust-lang#141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough. I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR. try-job: x86_64-gnu-aux
Rollup merge of #141857 - RalfJung:coretests-floats, r=tgross35 coretests: move float tests from num to floats module and use a more flexible macro to generate them This makes some progress on #141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough. I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR. try-job: x86_64-gnu-aux
Uh oh!
There was an error while loading. Please reload this page.
We currently have at least two somewhat independent places where float functions are being tested:
coretests/tests/num/mod.rs
coretests/tests/floats/f*.rs
std/tests/floats/f*.rs
Confusing, this also tests things that are actually in
std
. The ones innum
have infrastructure to also run tests inconst
, but do not have infrastructure to e.g. only run f128 tests on targets where that is reliable. For this reason, some tests are duplicated.We should make sure we have one canonical place for all these tests that can serve the needs of all of them, and avoid duplication.
Cc @tgross35
The text was updated successfully, but these errors were encountered: