Skip to content

Commit

Permalink
testing: Add switch to imageinout_test for enabling floating point ex…
Browse files Browse the repository at this point in the history
…ceptions. (AcademySoftwareFoundation#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 <[email protected]>
  • Loading branch information
stolk authored Oct 3, 2024
1 parent 1be693b commit 3f4285b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libOpenImageIO/imageinout_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#include <iostream>

#if defined(__linux__)
# include <fenv.h> // For feenableexcept()
#endif

#include <OpenImageIO/argparse.h>
#include <OpenImageIO/benchmark.h>
#include <OpenImageIO/filesystem.h>
Expand All @@ -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.



Expand All @@ -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");

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 3f4285b

Please sign in to comment.