# Help with ctest and jobs

**URL:** https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765
**Category:** Usage
**Created:** [July 15, 2021, 4:13pm UTC](https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765 "2021-07-15T16:13:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [July 15, 2021, 4:13pm UTC](https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765/1 "2021-07-15T16:13:37Z")

</div>

All,

Per [my last attempt at presets](https://discourse.cmake.org/t/help-with-presets-invalid-preset/3483), 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:

```auto
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?)

Thanks,  
Matt

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 15, 2021, 4:45pm UTC](https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765/2 "2021-07-15T16:45:07Z")

</div>

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”?

---

<div class="post-metadata">

### Author: ![mathomp4](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mathomp4/32/176_2.png) [@mathomp4](https://discourse.cmake.org/u/mathomp4)
#### Post date: [July 15, 2021, 5:40pm UTC](https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765/3 "2021-07-15T17:40:59Z")

</div>

@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!

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [July 15, 2021, 7:18pm UTC](https://discourse.cmake.org/t/help-with-ctest-and-jobs/3765/4 "2021-07-15T19:18:43Z")

</div>

There is a `ctest -S` scripting mode that configures, builds and tests from a .cmake script, if so configured. [Example](https://github.com/geospace-code/h5fortran/blob/main/ci.cmake) does from scratch configure, build, test by:

```auto
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`
