testing: Fix brittle behavior of tests that need to cmake - #5359
Conversation
Some tests (like cmake-consumer, but also the newly added imagebufalgo-opencv and openexr-partialtile) build their own executable, and so have their own CMakeLists.txt that needs to find_package(OpenImageIO). This only works in our CI because it sets OpenImageIO_ROOT (and, as it turns out, locally for me it works because I habitually have that set as well). But it can fail for users who don't have OpenImageIO_ROOT set to the place where the build being tested has installed itself. Fix it by setting this environment variable for all tests. This makes it work if the person running the tests has failed to set the variable, and it also ensure that things will work right if it IS set, but to the wrong place (like a different install than the build we're trying to test). Also make failed tests echo build.txt to the main log, if it exists, so that these in-test build failures can be more easily discerned from viewing the main CI log. Fixes 5358 Signed-off-by: Larry Gritz <lg@larrygritz.com>
|
@darix would love for you to test this and give an approval if it works for you |
|
does not work. would it work with that layout? that buildroot directory is passed in via DESTDIR |
|
I'm not sure why the layout would matter. In the patch, it just sets OpenImageIO_ROOT to Though it does depend on having the "install" target build BEFORE running all the tests. They layout of our "build" directory (pre-install) is not quite the same as a full install. |
|
yeah but it isnt installed to |
|
I don't understand. Isn't the way it gets installed to invoke with something like and then that same CMAKE_INSTALL_PREFIX definition provides both the install destination, and via this patch, also the path that OpenImageIO_ROOT will be set to when running the test? |
|
@darix, any update or thoughts on my last comment here? |
|
@darix Thoughts? To summarize: |
There was a problem hiding this comment.
Pull request overview
This PR improves robustness and debuggability of the CTest-driven testsuite, especially for tests that spawn a nested CMake build and need find_package(OpenImageIO) to resolve against the build-under-test.
Changes:
- Set
OpenImageIO_ROOTin the environment for all tests so nested CMake projects can reliably locate OpenImageIO. - When a test command fails, print
build.txt(if present) into the main test log to make nested build failures easier to diagnose.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| testsuite/runtest.py | Adds logic to emit build.txt content on command failure for easier CI/local debugging. |
| src/cmake/testing.cmake | Extends the default per-test environment with OpenImageIO_ROOT to stabilize nested find_package(OpenImageIO) behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if os.path.isfile("build.txt") : | ||
| print ("--- BUILD LOG ---\n") | ||
| with open("build.txt", "r") as fbuild : | ||
| print (fbuild.read()) | ||
| print ("--- END BUILD LOG ---\n") |
There was a problem hiding this comment.
I'm going to ignore this suggestion because for these couple of isolated tests, the build logs are short and the failures should be rare, and if they happen, we probably do want to see the full log.
Some tests (like cmake-consumer, but also the newly added imagebufalgo-opencv and openexr-partialtile) build their own executable, and so have their own CMakeLists.txt that needs to find_package(OpenImageIO).
This only works in our CI because it sets OpenImageIO_ROOT (and, as it turns out, locally for me it works because I habitually have that set as well). But it can fail for users who don't have OpenImageIO_ROOT set to the place where the build being tested has installed itself.
Fix it by setting this environment variable for all tests. This makes it work if the person running the tests has failed to set the variable, and it also ensure that things will work right if it IS set, but to the wrong place (like a different install than the build we're trying to test).
Also make failed tests echo build.txt to the main log, if it exists, so that these in-test build failures can be more easily discerned from viewing the main CI log.
Fixes #5358