1

lcov and gcovr -r . not generating the code coverage report for *.cpp files.

I am new to googletest framework. I have written a UT to test the code functionality and compiled the code with options -fprofile-arcs -ftest-coverage --coverage and lgcov in Makefiles. After executing the test-cases, I am able to see the *.gcno and .gcda files. But not getting the proper code coverage report.

Step 1: update the Makefile --> -fprofile-arcs -ftest-coverage --coverage
Step 2: build the code.
Step 3: running the test cases.
Step 4: gcovr -r .

Observed: Not getting *.cpp file coverage for which test cases are execute.

1 Answer 1

1

I had some troubles getting my test coverage set up, but I finally got it working. Although I'm not use the tools you are using.

I'm using clang++ and the LLVM tools. And I'm using my own barebones unit testing framework, which is similar to Catch2 (but not nearly as fully featured as Catch2).

Here are the commands I run, in case this is of help to you:

clang++ -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Wno-c99-compat -pedantic -fsanitize=undefined,null -std=c++17 -O0 -g -fprofile-instr-generate -fcoverage-mapping Experiment.cpp

./a.out --test-noisy --test-only

llvm-profdata merge -sparse default.profraw -o default.profdata

llvm-cov show -format=html -tab-size=4 ./a.out -instr-profile=default.profdata Experiment.cpp > default.html

echo '<style>pre { font-family: Monaco, Consolas, monospace; }</style>' >> default.html

I'd like to have responded in a comment, but this response is too long and needed the formatting for legibility. If deemed inappropriate (via downvotes) I'll delete it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.