# Collecting llvm code coverage data

**URL:** https://discourse.cmake.org/t/collecting-llvm-code-coverage-data/15875
**Category:** Usage
**Created:** [October 14, 2026, 6:26pm UTC](https://discourse.cmake.org/t/collecting-llvm-code-coverage-data/15875 "2026-10-14T18:26:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![epistax](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/e/eb9ed0/32.png) [@epistax](https://discourse.cmake.org/u/epistax)
#### Post date: [October 14, 2026, 6:26pm UTC](https://discourse.cmake.org/t/collecting-llvm-code-coverage-data/15875/1 "2026-10-14T18:26:42Z")

</div>

Put simply, when running a unit test build with llvm coverage enabled, by default it drops a file called `default.profraw` in the directory of the executable. I am using `gtest_discover_tests` and when I invoke using `ctest`, only the last test ran is reflected in the results.

llvm can be directed by setting an environment variable prior to running a test with the `LLVM_PROFILE_FILE` variable set. Since ctest runs every individual case in a separate execution of the test, I’d need to customize this for each case. I don’t see how to do this though.

Alternatively, if I could have ctest run all the tests in a given executable in a single invocation, I believe my problem goes away.

I would appreciate any suggestion on how to do either of these!

Thank you!

Edit:  
As a workaround I am doing this:  
“LLVM\_PROFILE\_FILE=${CMAKE\_BINARY\_DIR}/prof/test-%m-%p.profraw”  
in the PROPERTIES ENVIRONMENT of the gtest\_discover\_tests. This will produce a set of profraw files which are highly unlikely to collide. I don’t like the lack of predictability or ability to easily tell what generated them but if I only consider the data as a whole then it’s not a bad solution.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [October 14, 2026, 8:51pm UTC](https://discourse.cmake.org/t/collecting-llvm-code-coverage-data/15875/2 "2026-10-14T20:51:25Z")

</div>

> [@epistax](#):
>
> Alternatively, if I could have ctest run all the tests in a given executable in a single invocation, I believe my problem goes away.

In that case, don’t use `gtest_discover_tests()`, use plain `add_test()` to add the executable’s set of gtest tests as one ctest test.
