How to import llvm-cov data

After reading this I cannot figure out what I need to do to have llvm-cov report appear in SonarQube.
In this example -Dsonar.cfamily.llvm-cov.reportPath=…/coverage.txt property is used.
How would I generate this coverage.txt?
My project runs multiple tests and generates json files for each test:
llvm-cov export /Test --instr-profile=merged.profdata --format=text
This generates Test.json for each test.

Can I specify the directory where these json files are in sonar.cfamily.llvm-cov.reportPath?

I tried also :
llvm-cov show -object Test1 -object Test2 … --instr-profile=merged.profdata --format=text >coverage.txt
for a small number of tests. In reality I have thousands of tests and I probably cannot put all of them into a single command.
For this limited number of tests this seem to create a single coverage.txt. The file looks ok.
I specified path to this coverage.txt
and do not see any coverage info in SonarQube.

Should this coverage.txt be a text file, or json or lcov trace format?

Hi @Dmitriy_Kumshayev,

yes, you should get a single *.txt file with all report.

Could you please share coverage.txt file and the sonar-scanner output log?

@mpaladin Thank you for your reply.

Yes the command below generates a single file

I can do that for a couple of files (Test1,Test2).

    1|       |#include "coo.hpp"
    2|     20|#define BAR(x) ((x) || (x))
    . . .
    1|       |template <typename T>
    2|      4|void coo(T& x) { ++x; }
  | _Z3cooIiEvRT_:
  |    2|      2|void coo(T& x) { ++x; }
. . .
    1|       |#include "coo.hpp"
    2|     20|#define BAR(x) ((x) || (x))
. . . 
    1|       |#include "coo.hpp"
. . .

In my case I cannot generate a single file as I have thousands of test binaries and I cannot put them into a single command, as the command line is going to be too long.

To workaround this problem I tried to process binaries individually, so that afterwards I could concatenate the resulting files into a single file:

I got many txt files. In most txt files I see the same format, i.e. first line is path to the source file and then follows coverage information with the source code, then another source file path, and then again coverage info, etc. However if there is only one source file in the txt file, then it omits source file path in the first line.
If I exclude the files which do not have source file path in the first line, I can concatenate the remaining files and the resulting file would be very similar to coverage.txt obtained with the single command. With some differences, that code used in multiple tests will be repeated, and code from the excluded files will be missing.

I wonder is this a proper format expected by Sonar?

In Sonar log I see these lines:

It does not seem that Sonar does not like the file, however I do not see any report in sonarqube page.

Hi @Dmitriy_Kumshayev,

would you be able to share the entire test report and the entire sonar-scanner log privately? I can send you a PM.

Hi Massimo,
Thanks for trying to help me!
Unfortunately I am not able to provide the real life example as it would expose my company proprietary code which is against it’s policy. I will try to provide as much information as I can. There is nothing really special in the coverage.txt or in the log. It looks exactly like the test example I generated.
The format is that first goes the source file full path, and then content of the file, with 2 columns before each line : line number and call counter. The columns are pipe (’|’) separated.
This continues for each source file involved in the build.
The build process runse on a node in the cloud.
For the sake of this experiment I configured the build so that compilation, linkage and test execution as well as llvm-cov commands all run on the same node. The path to the final result of the build coverage.txt file is provided to Sonar via sonarArgs property:

Sonar is using sonar-scanner-cli-
When sonar is running I see messages like this for some of the source files:

10:34:11 INFO: CPD calculation finished
10:34:33 INFO: Analysis report generated in 17323ms, dir size=224 MB
10:35:05 INFO: Analysis reports compressed in 28908ms, zip size=62 MB
10:35:31 INFO: Analysis report uploaded in 29978ms
10:35:31 INFO: ANALYSIS SUCCESSFUL, you can browse
10:35:31 INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
10:35:31 INFO: More about the report processing at
10:35:31 INFO: Executing post-job Wait for CE activity to complete & then perform source code access management if CE phase is successful, else fail the build.
. . . waiting for sonar CE activity to complete . . .
10:52:54 INFO: {“response_message”:“Sonar source code access management completed successfully. Access has been provided to: [ … ]”,“status”:200}
10:52:58 INFO: Task total time: 20:16.009 s
10:52:58 INFO: ------------------------------------------------------------------------

Do you know what format of the file for coverageReport property is expected?
Documentation does not say anything about it, so I tried to follow examples from this forum.
llvm-cov tool can generate at least 4 different file formats: text, json, trace file and html

On sonarqube dashboard page in coverage section it mentions some python files it found in the code tree, but nothing about c++.

Hi @Dmitriy_Kumshayev,

if you cannot provide the sonar-scanner output and the coverage (as a private message) I am sorry but I cannot help you.

It is a MUST requirement to have build, test execution and sonar-scanner analysis on the same node.