From be33eb87dac5034d23fd143a57732c239034fa56 Mon Sep 17 00:00:00 2001 From: Bram Stolk Date: Sun, 29 Sep 2024 18:24:01 -0700 Subject: [PATCH] [test] Add switch to imageinout_test for enabling floating point exceptions. Running imageinout_test --enable-fpe will run the test with FPEs enabled. Currently it is catching a FP overflow in libjxl. Once that is fixed, it may find other FPEs. For now, this is a Linux-only feature. Signed-off-by: Bram Stolk --- src/libOpenImageIO/imageinout_test.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libOpenImageIO/imageinout_test.cpp b/src/libOpenImageIO/imageinout_test.cpp index 0baff48b4d..a33602647b 100644 --- a/src/libOpenImageIO/imageinout_test.cpp +++ b/src/libOpenImageIO/imageinout_test.cpp @@ -8,6 +8,10 @@ #include +#if defined(__linux__) +# include // For feenableexcept() +#endif + #include #include #include @@ -21,6 +25,7 @@ using namespace OIIO; static std::string onlyformat = Sysutil::getenv("IMAGEINOUTTEST_ONLY_FORMAT"); static bool nodelete = false; // Don't delete the test files +static bool enable_fpe = false; // Throw exceptions on FP errors. @@ -35,6 +40,8 @@ getargs(int argc, char* argv[]) ap.arg("--no-delete", &nodelete) .help("Don't delete temporary test files"); + ap.arg("--enable-fpe", &enable_fpe) + .help("Enable floating point exceptions."); ap.arg("--onlyformat %s:FORMAT", &onlyformat) .help("Test only one format"); @@ -529,6 +536,17 @@ main(int argc, char* argv[]) { getargs(argc, argv); + if (enable_fpe) { +#if defined(__linux__) + fprintf(stderr, "Enable floating point exceptions.\n"); + feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#else + fprintf( + stderr, + "Warning - floating point exceptions not yet implemented for this platorm.\n"); +#endif + } + test_all_formats(); test_read_tricky_sizes();