Help with ctest and jobs


Per my last attempt at presets, I now have CMake 3.21.0 installed and am trying it out again. I think the configure and build stages are doing what I expect, but the test presets seem slow and I think that it’s due to an assumption my brain is making.

Namely, it looks like this:

ctest -j6

only does the tests in parallel, right? It doesn’t do the build of the tests in parallel? I think my brain was thinking it’d do both.

If not, is there a way via ctest to say I want to build and run my tests in parallel? (And if so, a way to express that in the presets?)


CTest doesn’t build tests, it only runs them (at least with that command line signature). What do you mean by CTest “do[ing] the build of the tests in parallel”?

@ben.boeckel Ahhh. Interesting. I didn’t set up the tests in this library. According to our test guru, there is some “CMake Magic” in our codebase that “forces” ctest to rebuild our tests. Apparently at the time, the issue was that ctest wouldn’t see that some test code changed, so you could run ctest and it would be like nothing happened. So there are some fancy custom targets that apparently do…something to rebuild the tests (if needed) when we do our unit tests.

My guess is we could probably rewrite all the code now that we know CMake a bit better. These were first set up in the days of “we are learning CMake” and once we got something to work, we tended to leave it alone. So adding new tests is now a “copy-paste” of what you see in other parts of the codebase. (Maybe it’s time to look at the fancy FIXTURES bits of CMake/CTest!)

Sorry for my confusion!

There is a ctest -S scripting mode that configures, builds and tests from a .cmake script, if so configured. Example does from scratch configure, build, test by:

ctest -S ci.cmake

That script could have about half the lines removed as it’s doing CDash stuff that isn’t strictly necessary.

CTest doesn’t reconfigure/regenerate except in script mode as above, or some clever tricks perhaps. Normally if I make a change that affects a test I just cmake --build build even if there’s nothing to rebuild, as CMake via the generator detects the change and reconfigures + regenerates, then I run ctest

1 Like