Skip to content

Commit 3f4285b

Browse files
authored
testing: Add switch to imageinout_test for enabling floating point exceptions. (#4463)
Adds new feature: floating point exceptions, to imageinout_test binary. 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. ``` $ ./imageinout_test --enable-fpe ``` Signed-off-by: Bram Stolk <b.stolk@gmail.com>
1 parent 1be693b commit 3f4285b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libOpenImageIO/imageinout_test.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include <iostream>
1010

11+
#if defined(__linux__)
12+
# include <fenv.h> // For feenableexcept()
13+
#endif
14+
1115
#include <OpenImageIO/argparse.h>
1216
#include <OpenImageIO/benchmark.h>
1317
#include <OpenImageIO/filesystem.h>
@@ -21,6 +25,7 @@ using namespace OIIO;
2125

2226
static std::string onlyformat = Sysutil::getenv("IMAGEINOUTTEST_ONLY_FORMAT");
2327
static bool nodelete = false; // Don't delete the test files
28+
static bool enable_fpe = false; // Throw exceptions on FP errors.
2429

2530

2631

@@ -35,6 +40,8 @@ getargs(int argc, char* argv[])
3540

3641
ap.arg("--no-delete", &nodelete)
3742
.help("Don't delete temporary test files");
43+
ap.arg("--enable-fpe", &enable_fpe)
44+
.help("Enable floating point exceptions.");
3845
ap.arg("--onlyformat %s:FORMAT", &onlyformat)
3946
.help("Test only one format");
4047

@@ -529,6 +536,17 @@ main(int argc, char* argv[])
529536
{
530537
getargs(argc, argv);
531538

539+
if (enable_fpe) {
540+
#if defined(__linux__)
541+
fprintf(stderr, "Enable floating point exceptions.\n");
542+
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
543+
#else
544+
fprintf(
545+
stderr,
546+
"Warning - floating point exceptions not yet implemented for this platorm.\n");
547+
#endif
548+
}
549+
532550
test_all_formats();
533551
test_read_tricky_sizes();
534552

0 commit comments

Comments
 (0)