如何正确设置SonarQube cfamil.gcov?

时间:2018-05-14 14:30:02

标签: c++ sonarqube static-analysis sonarqube-scan gcov

我无法在SonarQube中使用报道报告。我有一个C ++项目,我正在使用build-wrapper-linux-x86-64以及声纳扫描器。源代码的基本静态分析似乎有效,但SonarQube中没有关于测试代码覆盖率的报告。

作为相同工作流程的一部分,我使用lcov和genhtml制作单元测试覆盖率报告,因此我确信大多数代码覆盖步骤都正确执行。当我手动查看.gcov文件时,我可以看到第一列中的运行计数,因此那里有数据。

我将我的代码组织成模块。 sonar-project.properties文件包括以下内容:

# List of the module identifiers
sonar.modules=Module1,Module2

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=./Sources,./Tests
HeliosEmulator.sonar.sources=./Application,./Sources,./Tests
sonar.cfamily.build-wrapper-output=build_output

# Existing reports
sonar.cfamily.build-wrapper-output=build_output
#sonar.cfamily.cppunit.reportsPath=junit
sonar.cfamily.gcov.reportsPath=.
#sonar.cxx.cppcheck.reportPath=cppcheck-result-1.xml
#sonar.cxx.xunit.reportPath=cpputest_*.xml
sonar.junit.reportPaths=junit

我还希望在Sonar工具下显示单元测试结果。因为我正在使用CppUTest框架,所以目前我没有xunit或junit测试输出。这可以作为一个单独的问题处理,但由于我无法找到有关如何在线使用cfamily扫描仪的大量文档,我不知道未列出的测试是否相关。

1 个答案:

答案 0 :(得分:0)

我忘了正确设置我的CI系统。运行声纳扫描仪的作业不存在.gcov文件。它们仅存在于生成覆盖率报告的测试作业中。扫描仪作业中没有文件意味着它无法进行报道。

当我设置GitLab CI系统时,我用来将.gcov文件保存为人工制品,覆盖报告突然开始工作。

.gcov文件由测试作业生成,需要通过artefact商店转移到声纳扫描仪作业。这是因为GitLab CI不在共享作业之间共享工作区,您必须明确说明必须复制哪些文件。