C++ test coverage data not loaded

I’m trying to get coverage data loaded into SonarCloud via SonarScanner CLI but something is going wrong and even the debug logs do not contain any hints.

Project structure looks like this:

/path/to/project/
    src/
        lib_a/
            <cpp code>
        lib_b/
            <cpp code>
    .build-dir/
        .builddir-test-unit-coverage/
            compile_commands.json
            <various cmake files>
            lib_a/
                CMakeFiles/
                    /project.dir
                        <cpp code .o + .gcda + gcdo files>
            lib_b/
                CMakeFiles/
                    /project.dir
                        <cpp code .o + .gcda + gcdo files>

SonarScanner CLI command looks like this:

SONAR_SCANNER_OPTS="<opts>" sonar-scanner -X

where <opts> are:

-Dsonar.projectBaseDir=/path/to/project 
-Dsonar.cfamily.compile-commands=/path/to/project/.builddir/.builddir-test-unit-coverage/compile_commands.json 
-Dsonar.cfamily.gcov.reportsPath=/path/to/project/.builddir/.builddir-test-unit-coverage/

and /path/to/project/sonar-project.properties contains following additional options:

sonar.sources=src
sonar.exclusions=**/*.json, **/*.py, **/*.js, **/*.xml
sonar.sourceEncoding=UTF-8

I believe the code analysis completes correctly using above settings based on the following logs:

09:55:44.543 INFO: Sensor CFamily [cpp]
09:55:44.576 INFO: CFamily plugin version: 6.53.0.67215
09:55:44.577 INFO: Using compile commands: /path/to/project/.builddir/.builddir-test-unit-coverage/compile_commands.json
09:55:44.584 INFO: Available processors: 16
09:55:44.587 INFO: Using 16 threads for analysis.
...
10:05:04.674 INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 864 (forceInclude=0,throughHeader=0)
10:05:04.674 INFO: Z3 refutation rate: 0 out of 35
10:05:04.674 INFO: SE: 864 out of 864
10:05:04.886 INFO: Subprocess(es) done in 556093ms

However coverage data is not being detected/analyzed. All I see in the logs is following lines:

10:05:06.908 INFO: ------------- Run sensors on project
10:05:06.913 DEBUG: 'llvm-cov' skipped because one of the required properties is missing
10:05:06.914 DEBUG: 'cppunit' skipped because one of the required properties is missing
10:05:06.914 DEBUG: 'VisualStudioCoverage' skipped because one of the required properties is missing
10:05:06.914 DEBUG: 'bullseye' skipped because one of the required properties is missing
10:05:06.914 DEBUG: 'cobertura' skipped because one of the required properties is missing
10:05:06.915 DEBUG: 'Valgrind' skipped because one of the required properties is missing
10:05:06.915 DEBUG: 'Java CPD Block Indexer' skipped because there is no related file in current project
10:05:06.915 DEBUG: Sensors : gcov -> Zero Coverage Sensor
10:05:06.916 INFO: Sensor gcov [cpp]
10:05:06.998 INFO: Sensor gcov [cpp] (done) | time=82ms
10:05:06.998 INFO: Sensor Zero Coverage Sensor
10:05:07.169 INFO: Sensor Zero Coverage Sensor (done) | time=171ms

Notice this is already with debug enabled, yet there is no indication as to why coverage sensor completed in 171ms and did not detect/process any coverage data.

Any pointers as to what I am missing would be greatly appreciated.

These logs will be the important bit, and there should be logs (either indicating that the directory is not found, that files are parsing, or that files indicated in the gcov files aren’t being analyzed by sonar).

The one thing that strikes me as odd is that your coverage files are in hidden directories (.builddir). Could you try moving them to a normal directory to see if it makes a difference?

The one thing that strikes me as odd is that your coverage files are in hidden directories (.builddir ). Could you try moving them to a normal directory to see if it makes a difference?

Many modern IDEs automatically exclude hidden folders from search results and since build folder lives within project root it could unnecessary pollute search results unless excluded. There is nothing out of ordinary with these folders and their permissions aside from their name starting with a dot. I have tried renaming them by removing leading dot, but got the same issue:

09:50:18.949 INFO: SONAR_SCANNER_OPTS=-Dsonar.projectBaseDir=/path/to/project -Dsonar.cfamily.compile-commands=/path/to/project/builddir/builddir-test-unit-coverage/compile_commands.json -Dsonar.cfamily.gcov.reportsPath=/path/to/project/builddir/builddir-test-unit-coverage/
...
10:01:03.685 DEBUG: Sensors : gcov -> Zero Coverage Sensor
10:01:03.685 INFO: Sensor gcov [cpp]
10:01:03.715 INFO: Sensor gcov [cpp] (done) | time=30ms
10:01:03.716 INFO: Sensor Zero Coverage Sensor
10:01:03.906 INFO: Sensor Zero Coverage Sensor (done) | time=190ms
10:01:04.152 INFO: CPD Executor 283 files had no CPD blocks
10:01:04.152 INFO: CPD Executor Calculating CPD for 1382 files
...

Hi @Ivan_Ribakov ,

sonar.cfamily.gcov.reportsPath
Path to the directory containing native *.gcov reports (not the XML reports generated by gcovr).

Does/path/to/project/builddir/builddir-test-unit-coverage/ contains .gcov reports ? They aren’t mentioned in your project structure.

Thanks,

Does/path/to/project/builddir/builddir-test-unit-coverage/ contains .gcov reports ?

You mean .gcda/.gcno files (so called “gcov data files”)? Yes, those are contained in the mentioned path.
If you mean some other files, can you please clarify what you mean by “.gcov reports”? Gcov man page does not mention generating reports, it talks about

logfile called sourcefile.gcov

Is that what SonarScanner is looking for?

They aren’t mentioned in your project structure.

That’s because @Colin asked me to remove the leading dots in the previous comment. See the project folder layout from the initial comment:

/path/to/project/
    src/
        lib_a/
            <cpp code>
        lib_b/
            <cpp code>
    .build-dir/
        .builddir-test-unit-coverage/
            compile_commands.json
            <various cmake files>
            lib_a/
                CMakeFiles/
                    /project.dir
                        <cpp code .o + .gcda + gcdo files>
            lib_b/
                CMakeFiles/
                    /project.dir
                        <cpp code .o + .gcda + gcdo files>
  • builddir == .builddir
  • builddir-test-unit-coverage == .builddir-test-unit-coverage

Here’s sample ls utility output:

$ ls -la builddir/builddir-test-unit-coverage/lib_a/CMakeFiles/project.dir/
total 1496
drwxr-xr-x 11 devenv devenv   4096 Mar 25 09:38 .
drwxr-xr-x  3 devenv devenv   4096 Mar 25 09:37 ..
drwxr-xr-x 21 devenv devenv   4096 Mar 25 09:38 api
drwxr-xr-x  2 devenv devenv   4096 Mar 25 09:38 binding
-rw-r--r--  1 devenv devenv   5776 Mar 25 09:37 config.cpp.gcda
-rw-r--r--  1 devenv devenv 147608 Mar 25 09:37 config.cpp.gcno
-rw-r--r--  1 devenv devenv 238064 Mar 25 09:37 config.cpp.o
drwxr-xr-x 10 devenv devenv   4096 Mar 25 09:38 controller
-rw-r--r--  1 devenv devenv  15736 Mar 25 09:37 core.cpp.gcda
-rw-r--r--  1 devenv devenv 255156 Mar 25 09:37 core.cpp.gcno
-rw-r--r--  1 devenv devenv 498224 Mar 25 09:37 core.cpp.o
drwxr-xr-x  2 devenv devenv   4096 Mar 25 09:38 exceptions
...

I can confirm that generating .gcov log files enabled SonarScanner to pick up and load coverage data.

Thanks for setting me on the right track. While evaluating various supported coverage tools/formats I lost track of what was actually expected by the gcov integation.

1 Like

Thanks for the follow-up @Ivan_Ribakov! We’re going to improve the logging here. CPP-5169

1 Like

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