Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Disable tests for reproducible FP on non-SSE2 x86 targets

Without SSE2 enabled, x86 targets will use x87 FPU, which breaks
the tests checking for reproducible results from our random
floating point number generators. The output is still reproducible,
at least between binaries targetting x87, but the tests hardcode
results for the whole pipeline being done in 32/64bit precision.

Closes #2796
Commit
d937427f1f8ae5c61f4c4849a6f860764f2f82b7
Author
Martin Hořeňovský ·
Parents
2a5de4e4476b

Files · Download .tar.gz

Changes

 .../IntrospectiveTests/RandomNumberGeneration.tests.cpp | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
index 03be6c9c..8517d617 100644
--- a/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
+++ b/tests/SelfTest/IntrospectiveTests/RandomNumberGeneration.tests.cpp
@@ -493,7 +493,6 @@ TEMPLATE_TEST_CASE( "uniform_integer_distribution is reproducible",
     REQUIRE_THAT(generated, Catch::Matchers::RangeEquals(uniform_integer_test_params<TestType>::expected));
 }
 
-
 namespace {
     template <typename T>
     struct uniform_fp_test_params;
@@ -551,6 +550,20 @@ namespace {
 #endif
 } // namespace
 
+// The reproducibility tests assume that operations on `float`/`double`
+// happen in the same precision as the operated-upon type. This is
+// generally true, unless the code is compiled for 32 bit targets without
+// SSE2 enabled, in which case the operations are done in the x87 FPU,
+// which usually implies doing math in 80 bit floats, and then rounding
+// into smaller type when the type is saved into memory. This obviously
+// leads to a different answer, than doing the math in the correct precision.
+#if ( defined( _MSC_VER ) && _M_IX86_FP < 2 ) || \
+    ( defined( __GNUC__ ) && !defined( __SSE2_MATH__ ) )
+#    define CATCH_TEST_CONFIG_DISABLE_FLOAT_REPRODUCIBILITY_TESTS
+#endif
+
+#if !defined( CATCH_TEST_CONFIG_DISABLE_FLOAT_REPRODUCIBILITY_TESTS )
+
 TEMPLATE_TEST_CASE( "uniform_floating_point_distribution is reproducible",
                     "[rng][distribution][floating-point][approvals]",
                     float,
@@ -570,6 +583,8 @@ TEMPLATE_TEST_CASE( "uniform_floating_point_distribution is reproducible",
     REQUIRE_THAT( generated, Catch::Matchers::RangeEquals( uniform_fp_test_params<TestType>::expected ) );
 }
 
+#endif // ^^ float reproducibility tests are enabled
+
 TEMPLATE_TEST_CASE( "uniform_floating_point_distribution can handle unitary ranges",
                     "[rng][distribution][floating-point][approvals]",
                     float,