acgetchell
(Adam Getchell)
July 10, 2021, 4:51pm
1
Using GitHub Actions, I can get build-wrapper and sonar-scanner to analyze my C++ code.
What doesn’t work, so far, is obtaining Code Coverage.
I’m using lcov
in the same way I use it on Travis-CI to generate coverage reports in CodeCov:
https://app.codecov.io/gh/acgetchell/CDT-plusplus/
That is, essentially:
cmake -G Ninja -D CMAKE_BUILD_TYPE=Debut -D ENABLE_COVERAGE:BOOL=TRUE -S . -B build
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build
cd $GITHUB_WORKSPACE/build
ctest ctest --schedule-random -j2
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/usr/include/*' '*/vcpkg_installed/*' --output-file coverage.info
(The test step is set to continue-on-error
, because some random number tests will fail and I don’t want that to abort the run.)
I used sonar-project.properties
to specify the location of the lcov report:
#sonar.projectName=CDT-plusplus
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=src,include
sonar.tests=tests
sonar.cfamily.build-wrapper-output=build_wrapper_output_directory
sonar.cfamily.cache.enabled=true
sonar.cfamily.cache.path=.sonar
sonar.cfamily.threads=2
sonar.cfamily.llvm-cov.reportPath=build/coverage.info
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
If I have to use gcov instead, is there a way to specify the location of all the gcda files, similar to what lcov does?
adam@hapkido ~/projects/CDT-plusplus/build (develop*) $ lcov --capture --directory . --output-file coverage.info
Capturing coverage data from .
Found LLVM gcov version 12.0.5, which emulates gcov version 4.2.0
Using intermediate gcov format
Scanning . for .gcda files ...
Found 21 data files in .
Processing tests/CMakeFiles/CDT_test.dir/Move_always_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/main.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Foliated_triangulation_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Move_tracker_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Apply_move_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Ergodic_moves_3_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Metropolis_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Settings_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Move_command_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Function_ref_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/S3Action_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Tetrahedron_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Geometry_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Torus_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Sphere_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Manifold_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Vertex_test.cpp.gcda
Processing tests/CMakeFiles/CDT_test.dir/Utilities_test.cpp.gcda
Processing src/CMakeFiles/initialize.dir/initialize.cpp.gcda
Processing src/CMakeFiles/cdt-opt.dir/cdt-opt.cpp.gcda
Processing src/CMakeFiles/cdt-gv.dir/cdt-gv.cpp.gcda
Finished .info-file creation
The remaining steps on lcov are useful for filtering out coverage on included libraries, I don’t know how to do that with gcov here.
Thanks for any suggestions.
mpaladin
(Massimo Paladin)
July 15, 2021, 7:32am
2
Hi @acgetchell ,
this is what we do to import gcov reports for our project:
mkdir ${GCOV_DIR_NAME}
pushd ${GCOV_DIR_NAME}
for f in `find ../build/cmake/CMakeFiles/core.dir -name '*.o'`; do
echo "Processing $f file..."
gcov -o ${f} x
done
ls | wc -l
popd
and then we pass -Dsonar.cfamily.gcov.reportsPath=${GCOV_DIR_NAME}
to sonar-scanner
.
Another option, which I haven’t tried myself but should work, is to use gcovr using --sonarqube
option and then passing the output result to sonar.coverageReportPaths
property.
acgetchell
(Adam Getchell)
July 16, 2021, 7:51pm
3
Hi @mpaladin ,
I tried the method suggested above.
The problem is that it generates coverage on 226 files, most of which are libraries installed via vcpkg
. There are only 21 relevant files, and my coverage reports are dramatically affected including everything.
lcov
solves that problem by being able to filter extensively.
For whatever reason, it did not upload to SonarCloud.
https://sonarcloud.io/summary/new_code?id=acgetchell_CDT-plusplus
I believe I set the correct path for the reports:
#sonar.projectName=CDT-plusplus
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=src,include
sonar.tests=tests
sonar.cfamily.build-wrapper-output=build_wrapper_output_directory
sonar.cfamily.cache.enabled=true
sonar.cfamily.cache.path=.sonar
sonar.cfamily.threads=2
sonar.cfamily.gcov.reportPath=build/gcov-reports
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
Amelie
(Amélie Renard)
July 19, 2021, 2:36pm
4
Hello @acgetchell ,
The reason it did not upload to SonarCloud may be that there is a typo in sonar-project.properties
: it should be sonar.cfamily.gcov.reportsPath
, with an “s” in “reports”.
(About the filtering, I don’t know gcov
well enough to guide you, but it may be easier by using gcovr
and the sonar.coverageReportPaths
property that Massimo mentioned)
acgetchell
(Adam Getchell)
July 23, 2021, 1:51am
5
Thank you @Amelie ! That indeed resolved the issue.
system
(system)
Closed
July 30, 2021, 1:52am
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
mpaladin
(Massimo Paladin)
August 2, 2021, 12:33pm
7
Hi @acgetchell ,
what do you mean with dramatically affected ?