How to solve the problem of sonar's C++ code coverage check rate being 0.0%

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
    GitHub
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI
    GitHub actions
  • Scanner command used when applicable (private details masked)
    /home/runner/work/PSS_ASIO/PSS_ASIO/sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
  • Languages of the repository
    C++
  • Only if the SonarCloud project is public, the URL
    https://github.com/OpenArkStudio/PSS_ASIO/blob/master/.github/workflows/PSS_ASIO.yml
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
    I used gcovr to generate a code inspection report. The program ran normally and the corresponding coverage.xml was generated.
    like this:
<coverage version="1">
<file path="Common/ISessionService.h">
<lineToCover lineNumber="16" covered="true"/>
</file>
<file path="Common/LoadLibrary.hpp">
<lineToCover lineNumber="27" covered="true"/>
<lineToCover lineNumber="40" covered="true"/>
<lineToCover lineNumber="44" covered="true"/>
<lineToCover lineNumber="49" covered="true"/>
<lineToCover lineNumber="53" covered="true"/>
<lineToCover lineNumber="67" covered="true"/>
<lineToCover lineNumber="71" covered="true"/>
<lineToCover lineNumber="76" covered="true"/>
<lineToCover lineNumber="78" covered="true"/>
...

Then I set the location reported by gcovr.
like this:

sonar.projectKey=ArkNX_PSS_ASIO
sonar.organization=openark
sonar.projectName=PSS_ASIO
sonar.projectVersion=3.0

sonar.sources=./
sonar.cfamily.build-wrapper-output=../bw-output
sonar.cfamily.threads=2
sonar.cfamily.cache.enabled=false
sonar.coverageReportPaths=../coverage.xml

sonar.exclusions=**TTySession/**,**Common/**,**TcpSession/TcpClientSession.cpp**,**UdpSession/UdpClientSession.cpp**,**UdpSession/KcpServer.cpp**,**Message/IotoIo.cpp**,**TcpSession/TcpSSLServer.cpp**,**TcpSession/TcpSSLSession.cpp**,**TcpSession/TcpSSLServer.h**,**TcpSession/TcpSSLSession.h**,**TcpSession/TcpSSLClientSession.h**,**TcpSession/TcpSSLClientSession.cpp**

When I run sonar for code scanning and report submission.
I got this:

INFO: Sensor Generic Coverage Report
INFO: Parsing /home/runner/work/PSS_ASIO/PSS_ASIO/coverage.xml
INFO: Imported coverage data for 0 files
INFO: Coverage data ignored for 230 unknown files, including:
Common/ISessionService.h
Common/LoadLibrary.hpp
Common/SessionBuffer.hpp
Common/ThreadQueue.h
Common/TimeStamp.hpp
INFO: Sensor Generic Coverage Report (done) | time=88ms

and then my sonar cloud show me,

Please tell me how to pass the complete code coverage report into sonar?
thanks.

Hey there.

When I look at your repo (specifically the /Common/ folder)… I dont’ see any of these files that seemed to be mentioned in the coverage report.

As I missing them? Does the coverage report actually contain files that are in your repo?