Sonarqube swift code coverage

Which versions are you using:
SonarQube: Developer Edition v10.6
How is SonarQube deployed:
Zip
what are you trying to achieve:
I would like SonarQube to display the code coverage for the project based on the uploaded xml file. The xml file is created and filled in correctly.

sonar.swift.coverage.reportPaths=sonar-reports/coverage-swift.xml in sonar-project.properties file.
Logs:

INFO: Preprocessing files…
INFO: 3 languages detected in 1074 preprocessed files
INFO: 0 files ignored because of scm ignore settings
INFO: Loading plugins for detected languages
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=55ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=243ms
INFO: Indexing files…
INFO: Project configuration:
INFO: 1074 files indexed
INFO: Quality profile for c: Sonar way
INFO: Quality profile for json: Sonar way
INFO: Quality profile for swift: Sonar way
INFO: ------------- Run sensors on module Vip_Parker_IOS
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=222ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: ‘sonar.coverage.jacoco.xmlReportPaths’ is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=8ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=225ms
INFO: Sensor IaC AzureResourceManager Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC AzureResourceManager Sensor [iac] (done) | time=154ms
INFO: Sensor Java Config Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor Java Config Sensor [iac] (done) | time=28ms
INFO: Sensor Swift Code Quality and Security [swift]
INFO: 312 source files to be analyzed
INFO: 312/312 source files have been analyzed
INFO: Parse coverage report (sonar-reports/coverage-swift.xml)
INFO: Sensor Swift Code Quality and Security [swift] (done) | time=9918ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=90ms
INFO: Sensor Generic Test Executions Report
INFO: Parsing /Users/grzegorzszymanski/Vip_Parker_IOS/VIPParker/sonar-reports/testCoverage-swift.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 20 unknown files, including:
AccountRepositoryTests
DeviceManagerTests
CarsDataRepositoryTests
CreditCardsRepositoryTests
LocationRepository
INFO: Sensor Generic Test Executions Report (done) | time=26ms
INFO: Sensor CFamily [cpp]
INFO: CFamily plugin version: 6.56.0.72172
INFO: CFamily analysis configuration mode: AutoConfig
INFO: AutoConfig mode for C and C++ is enabled
INFO: Objective-C is not supported in AutoConfig mode
INFO: The following rules aren’t available in AutoConfig mode: [S819, S820, S860, S878, S905, S961, S1068, S1235, S2275, S3744, S4263, S5265, S5276, M23_324, S930, S950, S1914, S5536]
INFO: Available processors: 8
INFO: Using 8 threads for analysis.
INFO: Loading cache from: server
INFO: 0 compilation units to be analyzed, 0 C, 0 CPP
INFO: Detected MacOS SDK include directories:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
INFO: Detected MacOS SDK frameworks directories:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
INFO: Detected local system include directories:
/opt/homebrew/include
INFO: AutoConfig detected dependencies: 
INFO: Took 1486 ms to extract 1 dependencies
INFO: 0 directories to be analyzed for macros, 0 C, 0 CPP
INFO: Starting AutoConfig macros computation to configure additional preprocessor predefines for each directory
INFO: Macro computation cache: 0/0 hits
INFO: Macros computation for all directories done in: 3ms
INFO: Analysis done in: 1540ms
INFO: 1/1 files marked as unchanged
INFO: Analysis cache: 0/0 hits, 125 bytes
INFO: SE: 0 out of 0
INFO: PCH: unique=0 use=0 (forceInclude=0,throughHeader=0,firstInclude=0) out of 0 (forceInclude=0,throughHeader=0)
INFO: Z3 refutation rate: 0 out of 0
INFO: Percentage of files indexed with CFamily languages: 0,09% (C: 1, C++: 0, ObjC: 0, Indexed: 1074)
INFO: 0 compilation units were fully analyzed
INFO: 0 compilation units were partially analyzed: 0 stopped on Config, 0 stopped on Parsing, 0 stopped on AST, 0 stopped on SE, and 0 stopped on SE with PE
INFO: 0 compilation units timed out: 0 on analysis and 0 on macros computation
INFO: Sensor CFamily [cpp] (done) | time=5092ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: Available processors: 8
INFO: Using 8 threads for analysis.
INFO: Using git CLI to retrieve untracked files
INFO: Analyzing language associated files and files included via “sonar.text.inclusions” that are tracked by git
INFO: 513 source files to be analyzed
INFO: 513/513 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=2689ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=96ms
INFO: CPD Executor 43 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 270 files
INFO: CPD Executor CPD calculation finished (done) | time=135ms
INFO: SCM revision ID ‘f4d3c118c07bbdc001fddaa2d058ec2768a9d9dd’
INFO: Load New Code definition
INFO: Load New Code definition (done) | time=223ms
INFO: Analysis report generated in 507ms, dir size=1.8 MB
INFO: Analysis report compressed in 842ms, zip size=884.9 kB
INFO: Analysis report uploaded in 247ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://localhost:9000/dashboard?id=TEZ-VipParker-Mobile-iOS
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=449a4dfe-205f-48c4-ad10-93fc38a085f8
INFO: Analysis total time: 45.074 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 48.568s
INFO: Final Memory: 30M/128M
INFO: -----------------

What have you tried so far to achieve this:
Project analysis are send without errors.

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,

Welcome to the community!

Can you add -Dsonar.log.level=DEBUG to your analysis command line and post the full log, starting from the analysis command itself? Hopefully that will give us more information about how that coverage file is being processed.

 
Ann

Can I send a txt file? When I paste text from the terminal, the browser hangs.

Hi,

Absolutely. You should be able to add it as an attachment.

 
Ann

Logs.txt (333.0 KB)

Hi,

Thanks for the log. It… doesn’t add anything useful. :frowning:

I’m going to flag this for the language experts.

 
Ann

Hello Grzegorz,

What is the format you are sending?

Could you provide us with your coverage report file?

Did you have a look at the docs?

We might expand the docs with the following instructions:

Using xccov (recommended)

The xccov command line tool is the recommended option to view Xcode coverage data and is more straightforward to use than the older llvm-cov tool. With the script xccov-to-sonarqube-generic.sh, you can convert Xcode test results stored in *.xcresult folders to the SonarQube generic test coverage format.

First, locate the Xcode test result folder (*.xcresult). Then use it as a parameter to the script converting the coverage data to the SonarQube format as in the following example:

bash xccov-to-sonarqube-generic.sh Build/Logs/Test/Run-swift-coverage-example-2023.01.27_16-07-44-+0100.xcresult/ >Coverage.xml

Then, use the parameter sonar.coverageReportPaths to reference the generated report:

sonar-scanner -Dsonar.coverageReportPaths=Coverage.xml

This parameter accepts a comma-separated list of files, which means you can also provide multiple coverage reports from multiple test results.

Using llvm-cov

You can also provide code coverage data using the llvm-cov format. The process of generating an llvm-cov report requires several steps to get the coverage for the application executable and the dynamic library binaries.

In the case of the project example, first, locate the Coverage.profdata file under the ProfileData folder. Then, generate an llvm-cov report as in the following example (the located Coverage.profdata file should be the value of -instr-profile parameter):

xcrun --run llvm-cov show -instr-profile=Build/Build/ProfileData/00006000-000428843C29801E/Coverage.profdata \ Build/Build/Products/Debug/swift-coverage-example.app/Contents/MacOS/swift-coverage-example \ >Coverage.report

Finally, use the parameter sonar.swift.coverage.reportPaths to reference the generated report. This parameter also accepts a comma-separated list of files.

sonar-scanner -Dsonar.swift.coverage.reportPaths=Coverage.report

The file is in xml. I changed the file extenstion to send it. To generate raport i used te recommended option.
coverage-swift.txt (705.8 KB)

Any ideas what could be wrong?

Hello,

I have found the following line in the logs that could be relevant:

15:02:02.435 DEBUG: 'Generic Coverage Report' skipped because one of the required properties is missing\

Could you share the sonar properties that you use? Please make sure that you remove any private information.

Could you try providing the coverage report with the following sonar property?

sonar.coverageReportPaths=sonar-reports/coverage-swift.xml