Step 1: modify the Makefile for the source codes
To use the tool of gcov, one must add flags to generate reports flags to be added as follows:
For the .cpp file, one need to add flags: -fprofile-arcs -ftest-coverage
For the .cu files, one need to add flags: -Xcompiler -fprofile-arcs -Xcompiler -ftest-coverage
Link with “-lgcov” .
After compiling the source code with the newly added gcov flags, corresponding .gcno files will be generated for each source code file (in src/ folder).
Step 2: run the tests
After this step, *.gcda files will be created (in src/ folder).
Step 3: use gcovr to generate HTML output
Under the directory of the library, create a new folder(say gcov/) and copy the *gcno and *gcda files to this folder.
In the root directory, use the following command line to generate the HTML file:
gcovr gcov/ -e ".stub.|.hxx|..h|.iostream|.include.*" --html --html-details -o coverage.html
Here gcovr provides a utility for managing the use of the GNU gcov utility and generating summarized code coverage results.
'-e' means to exclude data files that match this regular expression.