Gitlab-ci.yml CPP 覆盖率报告
gitlab-ci.yml cpp coverage report
我正在尝试使用 Gitlab 为 c++ 项目实现 CI。首先,我添加了一个简单的c ++ hello world程序,该程序在我的PC和Gitlab CI中编译和运行。
当我尝试为相同的命令生成覆盖率报告时,它适用于 PC,但不适用于 Gitlab CI。
这是我的gitlab-ci.yml
# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: gcc
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
# before_script:
# - apt update && apt -y install make autoconf
script:
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ls
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- bash runmytests.sh
coverage:
stage: deploy
before_script:
- apt-get -qq update && apt-get -qq install -y gcovr ggcov lcov
script:
- ls
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ./mybinary
- ls
- gcov helloworld.cpp
- lcov --directory . --capture --output-file coverage.info
- lcov --remove coverage.info '/usr/*' --output-file coverage.info
- lcov --list coverage.info
- genhtml -o res coverage.info
这是生成的错误输出
$ g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
$ ./mybinary
Hello, World!$ ls
README.md
helloworld.cpp
helloworld.gcda
helloworld.gcno
mybinary
runmytests.sh
$ gcov helloworld.cpp
File 'helloworld.cpp'
Lines executed:100.00% of 3
Creating 'helloworld.cpp.gcov'
File '/usr/local/include/c++/8.1.0/iostream'
No executable lines
Removing 'iostream.gcov'
$ lcov --directory . --capture --output-file coverage.info
Capturing coverage data from .
Found gcov version: 8.1.0
Scanning . for .gcda files ...
geninfo: WARNING: /builds/ganeshredcobra/gshell/helloworld.gcno: Overlong record at end of file!
Found 1 data files in .
Processing helloworld.gcda
geninfo: WARNING: cannot find an entry for helloworld.cpp.gcov in .gcno file, skipping file!
Finished .info-file creation
$ lcov --list coverage.info
Reading tracefile coverage.info
lcov: ERROR: no valid records found in tracefile coverage.info
ERROR: Job failed: exit code 1
我该如何解决这个问题?
通过将映像名称从 gcc 更改为 ubuntu 16.04 解决了该问题,工作 yml 将如下所示
# use the official gcc image, based on debian
# can use verions as well, like gcc:5.2
# see https://hub.docker.com/_/gcc/
image: ubuntu:16.04
build:
stage: build
# instead of calling g++ directly you can also use some build toolkit like make
# install the necessary build tools when needed
before_script:
- apt update && apt -y install make autoconf gcc g++
script:
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ls
artifacts:
paths:
- mybinary
# depending on your build setup it's most likely a good idea to cache outputs to reduce the build time
# cache:
# paths:
# - "*.o"
# run tests using the binary built before
test:
stage: test
script:
- bash runmytests.sh
coverage:
stage: deploy
before_script:
- apt-get -qq update && apt-get -qq install -y make autoconf gcc g++ gcovr ggcov lcov
script:
- ls
- g++ -Wall --coverage -fprofile-arcs -ftest-coverage helloworld.cpp -o mybinary
- ./mybinary
- ls
- gcov helloworld.cpp
- lcov --directory . --capture --output-file coverage.info
- lcov --list coverage.info
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 如何在 C 中正确使用 libiconv 使其不会报告"Arg list too long"?
- 使用std::source_location报告错误的最佳实践
- xmake总是报告:错误:无法获取cxx的程序,为什么
- 当用户超过按钮点击限制时报告
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么cudaMemGetInfo报告设备内存总量的变化
- 为什么 gcovr 会生成空覆盖率统计信息?
- 为什么瓦尔格林德在不释放恶意内存后没有报告任何问题?
- 内存清理程序报告全局对象构造中未初始化值的使用
- QDataStream 读取和写入的字节数比 QFile::length() 报告要多
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- Valgrind 在 std::string::swap 中报告 SIGILL
- DRD 报告"conflicting load" std::mutex::lock 上的错误
- 柯南,CMake.test()生成XML报告
- 如何构建一个异常类来报告C++中的哪些文件和行号?
- Gitlab-ci.yml CPP 覆盖率报告
- clang++ 总是生成空的 profraw 覆盖率报告
- TeamCity中的Visual Studio企业代码覆盖率报告
- 覆盖率报告含义 - PW.INCLUDE_RECURSION