Collecting llvm code coverage data

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.

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.