No coverage report is displayed on SonarCloud dashboard. [Zero C++ files were analysed]

Hello guys,

I have a general question on the SonarCloud coverage report.

On my local machine, I normally generate the html coverage report using gcovr and view it on the browser. The gcovr uses gcov and lcov under the hood to generate this html coverage report. And, an xml is also possible. For this, I have to pass some special compiler flags like: -g -O0 -coverage -fprofile-arcs -ftest-coverage before creating the targets. Up to here no confusion.

However, when I it comes to integration with SonarCloud, I’m not clear. I want to supply these coverage report to the SonarCloud, so that it will analyse the report further and displays the matrices on dashboard.

For C/C++ projects, I found a concept of build-wrapper and this makes me completely confused. So I have following questions:

  1. If I am already generating the coverage matrices and want to supply to SonarCloud then why do I need this build-wrapper?
  2. Does this build-wrapper generate the coverage report and feed it to the SonarCloud? If that is the case then I think I don’t need this gcovr report generation part in my project set up.
  3. Finally, what is the difference between Test coverage and Test execution in the SonarCloud world?

Because, I am already using the following variables in sonar-project.properites file:

sonar.cfamily.build-wrapper-output=build/bw-output
sonar.cfamily.gcov.reportsPath=

And, I saw the following as well and seems like an important one to set up so don’t want to ignore it.

sonar.cfamily.cppunit.reportsPath=
But, what’s the purpose of it?

Finally, SonarCloud dashboard is not showing the coverage matrices for my project (https://github.com/MrPoudel/ParticleExplosion)
(https://sonarcloud.io/dashboard?id=MrPoudel_ParticleExplosion)

  • ALM used (GitHub)
  • CI system used (Travis CI)
  • Scanner command used when applicable (sonar-scanner)
  • Languages of the repository: cpp
  • Only if the SonarCloud project is public, the URL (https://github.com/MrPoudel/ParticleExplosion)

The build on TravisCI's virtual machine has the following errors:

15:52:10.567 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
  * you are using the latest version of the build-wrapper and the CFamily analyzer
  * you are correctly invoking the scanner with correct configuration
  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * you are providing the path to the correct build-wrapper output directory
  * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps

The contents of .travis.yml

dist: trusty
sudo: required
language: c++
  
cache:
  directories:
  - '$HOME/.sonar/cache'

addons:
  apt:
    packages:
      - cmake
      - valgrind
      - libgles2-mesa-dev 
      - libegl1-mesa-dev 
      - libsdl2-dev
      - gcovr
      - tree
  sonarcloud:
    organization: "mrpoudel"
    token:
       secure: "eOchtfqlF6Kx8fN2eEuZ7zahEvyvwmossuvNGC/eEKF8zapsF+O4UehiPw1FJnPKFmtky+PwV6iSAEjvIb8udGCicrKLuEQXrgiSDWYeQ3DLlOP7tbtGOhdiQfnjYLfQtQFbKbjFTmPHGI0sTMatzt7BvK40xZ5yFeDSol8Do+kp1X4DEiPaNM5T4Jnpxp/XnotVY7zbbEiMdzHfd2dWl65CoVeYbgjua3oO8TNb4HyysHOadL+8LvPJn7mrv+Lq0XSpRHgztiK8nu9PkjG7bJwCILemYR9WbIYpyMoPnSDUGK46rKFU1t9UoiNbTMyIpKschFIBUGBmWetLOH8ZrNgmCiI97Bd7z/9D6anxDlmm2fi4vgYcqEskcqlJtV2TDiWnuhIlivraa2bYCMoOlZm2kV2MwJy/N495O7P2WJuIG9ePIQORwyYvRR1mDn2kIkTd+LD7muGVnzMi5iIPZzyWqDQTUwDNa/3L05yQBoeFTu+h3kfTxwwS1/n6o3jmzKCbXtMg5ylt8hZLO4PWR9hWIo/LDNe3yjxRB+7OQV53XsLC3eJgp3q7YGBW8hW34uakh5poH3oPm0s7cwFMwROoethBRUjbIDcxtiA3PzbQiXo7yr4WaLI6uPtMNNTW8+TNEHkRdd4eq42sApiXbKe9v9dhowo0/GzFfhprK2c="
       #secure: "Zh0ob4SvguSFnmYyy0kyHCNat5FxZLX81hqYqYQqC/VxjeR0xzrRHttSqKGmfD6IDcHf2KxBXz9kmm03m7z24Mfpr2vGbRTyN8Sz//vpmJAUo+6AK59NOYLeYt5yK8rnQEcwbUQ6UqU9RMc/L7AtFF9CFX6PEmraoA3Z8jDFp3lqSh1UPMT9J1ip2Dn+hMBiBJnh53MeU44qv7nQ+XcPT0fV3jqm86oQ37hw1Z8wy7u0UbaX8/jY9yL7Zy5xUaPKKQLR7ZtryaoladLP9a2iICx/E1p5eHxxwN7JnHz5myAN5wYCI3Ag3kQBj2/tw1R+7zkPWNx2vXIZj7ndj2InpGr5u18t7qWu9J1qSySZv5HEnIZd5c9+1vS0YOMhEr0i4AFThA6XjxjKEeZGG0Va11rIZDzHQsIAc6e9uvWQTq9cLEdfTmpsD8kPkp4M8jg6cVVR4H3SHh9O2t8wLs9WQUoLY0YwdP76Xf6SBN76S3EUjtBvI0BVqP/Rntx01SIucMPJeltx7kTmrgbbKt53e7GtVzCOE6S8tDMSWMr/1gxycebIYyo99DLjkiNQVUJbLO5KYEw6GES+GvzRT83oBuODFBtOu8aF4zTy/FR4Smz+LWB3IymVfhZivt7qlpkyEpH+D03ItM5mPwOydROpsQDrVPLomYfgFvp6C5oCpR0="
env:
  - SONAR=true

# disable git fetch depth limit to 0, otherwise you are git cloning twice.
git:
  depth: false  
  quite: true
  
# before_install:
#   - sudo apt-get update -qq # make the output less noisy
# #   - sudo apt-get upgrade
#   - sudo apt-get install cmake
#   - sudo apt-get install valgrind
#   - sudo apt-get install libgles2-mesa-dev  
#   - sudo apt-get install libegl1-mesa-dev  
#   - sudo apt-get install libsdl2-dev
#   - sudo pip install --upgrade pip
#   - sudo pip install gcovr
       
script:
 #- sudo apt install tree
 - rm -rf build
 - mkdir build
 - cd build
 # Wraps the compilation with the Build Wrapper to generate configuration (used
 # later by the SonarQube Scanner) into the "bw-output" folder
 - build-wrapper-linux-x86-64 --out-dir bw-output cmake .. && make clean all && make coverage && ./test/ParticleTest
 #- mkdir gcov && cd gcov && gcov $(find .. -name '*.gcov')
 #- tree -L 2
 - cat bw-output/build-wrapper-dump.json
 - cat bw-output/build-wrapper.log
 - ls
 - cd ..
 - sonar-scanner  -X -Dsonar.projectKey=MrPoudel_ParticleExplosion -Dsonar.cfamily.build-wrapper-output=build/bw-output #-Dsonar.cfamily.gcov.reportsPath=build/gcov #-Dsonar.testExecutionReportPaths=build/coverage.xml

The contents of sonar-project.propreties:

sonar.projectKey=MrPoudel_ParticleExplosion
sonar.organization=mrpoudel

#this is generated form the sonar token
sonar.login=ee5834afd5a8d022dc0d6db0c7ea87b47ce285e3
#sonar.password=

# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=ParticleExplosion
sonar.projectVersion=1.0

# =====================================================
#   Meta-data for the project
# =====================================================

sonar.links.homepage=https://github.com/MrPoudel/ParticleExplosion
sonar.links.ci=https://travis-ci.org/github/MrPoudel/ParticleExplosion
sonar.links.scm=https://github.com/MrPoudel/ParticleExplosion
sonar.links.issue=https://github.com/MrPoudel/ParticleExplosion/issues

# =====================================================
#   Properties that will be shared amongst all modules
# =====================================================

#sonar.sources=Libraries, test 
#sonar.tests=./test/

# =====================================================
#  Languages that are used in the project
# =====================================================
sonar.language=c++

# directories that should be excluded from the analysis
#sonar.exclusions=./build/**/* 
#./bw-output/**/* , \
#  extern/,\
#  test/

# Maximum time to wait for the response of a Web Service call (in seconds)
sonar.ws.timeout=60

#path to the Build Wrapper output directory relative to the project directory
sonar.cfamily.build-wrapper-output=build/bw-output

# cpp test execution report location
#sonar.cfamily.cppunit.reportPath=.
#sonar.cxx.coverage.reportPath=build/coverage.xml
sonar.cfamily.gcov.reportsPath=build/coverage.xml
#specify the number of threads
sonar.cfamily.threads=1

# explicitly disable cache for your analysis
sonar.cfamily.cache.enabled=false

#Encoding files
sonar.sourceEncoding=UTF-8

The complete log including the contents of build-wrapper-dump.json and build-wrapper.log is here : https://travis-ci.org/github/MrPoudel/ParticleExplosion/builds/717963318

Any support on these issues would be great. Thank you.

Hello @MrPoudel,

build-wrapper is needed to perform static analysis for c/c++/obj-c. It should be generated with a clean build command. it contains information on how your source files are built. It doesn’t generate any coverage report. Official documentation.
So it should be build-wrapper-linux-x86-64 --out-dir bw-output **build command**

If you look at the log file you are passing cmake .. to build-wrapper, which is not a build command so the analysis will not work.

Fri Aug 14 15:51:33 2020: command line received: <cmake …>

Try to replace:

- build-wrapper-linux-x86-64 --out-dir bw-output cmake … && make clean all && make coverage && ./test/ParticleTest

by

- cmake …
- build-wrapper-linux-x86-64 --out-dir bw-output make clean all
- make coverage
- make ./test/ParticleTest

Test Coverage & Execution

Note: be careful not to mix the two settings. sonar.cxx is a different product, It isn’t by SonarSource, and it isn’t supported on this channel.

Thanks,

1 Like

Hello @Abbas_Sabra,
Thank you for the detail explanation. The command build-wrapper-linux-x86-64 --out-dir bw-output make clean all did the trick for static analysis. Now, I can see the static analysis report on the SonarCloud dashboard.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.