0

我在带有 gcovr 5.0 的 Win10 上使用 Cygwin GCC 11.2.0。我的 C 文件是使用 --coverage 标志编译的,并创建了 .gcno 文件。运行我的程序后,.gcda 文件也存在,如果我在 Eclipse 中使用 GCOV 扩展名打开它们,我会看到有效的覆盖率数据。但是当我使用命令运行 gcovr 时 gcovr -v -r X:/Path/to/my/Project .(此文件夹包含带有我的 .c 和 .h 文件的子文件夹)我看到以下输出

------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: X:/Path/to/my/Project
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
------------------------------------------------------------------------------
TOTAL                                          0       0    --%
------------------------------------------------------------------------------

感谢 -v (详细)选项,我可以看到所有文件都已处理,例如

Processing file: C:\Path\to\my\object\folder\02_obj\filename.gcda
Running gcov: 'gcov C:\Path\to\my\object\folder\02_obj\filename.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory     C:\Path\to\my\object\folder\02_obj' in 'C:\Users\Name\AppData\Local\Temp\tmpncjbaf67'

但它总是以Gathered coveraged data for 0 files. 我也可以让 gcovr 使用该选项生成一个 HTML 输出文件,--html -o output.html但这没有显示任何结果。

我的项目结构如下

.c 文件:X:\Project\Implementation\dev\Source_File_Folder

.o、.gcno、.gcda 文件:X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder

通话

X:\Project\Implementation\dev\Source_File_Folder>gcovr -v X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder -r .

给了我以下结果

Filters for --root: (1)
-re.compile('^X:\\\\Project\\\\Implementation\\\\dev\\\\ProjektGitRepo\\\\Source_File_Folder\\\\')
Filters for --filter: (1)
-DirectoryPrefixFilter(X:\Project\Implementation\dev\Source_File_Folder\)
Filters for --exclude: (0)
Filters for --gcov-filter: (1)
- AlwaysMatchFilter()
Filters for --gcov-exclude: (0)
Filters for --exclude-directories: (0)
Scanning directory     X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder for gcda/gcno files...
Found 21 files (and will process 11)
Pool started with 1 threads
Processing file: X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder\bap_bcl.gcda
Running gcov: 'gcov X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder\bap_bcl.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder' in 'C:\Users\Name\AppData\Local\Temp\tmppd7r7jwv'
Processing file: X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder\bap_bpl.gcda
Running gcov: 'gcov X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder\bap_bpl.gcda --branch-counts --    branch-probabilities --preserve-paths --object-directory X:\Project\Verification\Test\VariantABC\Binaries\Obj_Folder\02_obj' in 'C:\Users\Name\AppData\Local\Temp\tmppd7r7jwv'
Processing file: ... this continues for the remaining 19 files
Gathered coveraged data for 0 files
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
------------------------------------------------------------------------------
TOTAL                                          0       0    --%
------------------------------------------------------------------------------

如何成功运行 gcovr?

编辑 我现在添加了一个名为而不是 gcov 的脚本。它用 gcov 的参数列表中的斜杠替换所有反斜杠,然后调用 gcov。这是实现:

gcov_replace_backslash.bat:
@echo off
set "parameters=%*"
set "parameters=%parameters:\=/%"
gcov %parameters%

通过设置参数将此脚本与 gcovr 一起使用时,--gcov-executable我得到了不同但仍然不是所需的结果:

X:\Implementation\dev\Source>gcovr -v --gcov-executable gcov_replace_backslash.bat X:/Verification/Test/Integration/obj -r .
Filters for --root: (1)
- re.compile('^X:\\\\Implementation\\\\dev\\\\Source\\\\')
Filters for --filter: (1)
- DirectoryPrefixFilter(C:/Users/Name/Projekt/Implementation/dev/Source/)
Filters for --exclude: (0)
Filters for --gcov-filter: (1)
- AlwaysMatchFilter()
Filters for --gcov-exclude: (0)
Filters for --exclude-directories: (0)
Scanning directory X:/Verification/Test/Integration/obj for gcda/gcno files...
Found 21 files (and will process 11)
Pool started with 1 threads
Processing file: C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.gcda
Running gcov: 'gcov_replace_backslash.bat C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory C:\Users\Name\Projekt\Verification\Test\Integration\_obj' in 'C:\Users\Name\AppData\Local\Temp\tmpdlm9xrfx'
Finding source file corresponding to a gcov data file
  currdir      X:\Implementation\dev\Source
  gcov_fname   C:\Users\Name\AppData\Local\Temp\tmpdlm9xrfx\#cygdrive#X#Implementation#dev#Source#file1.c.gcov
               ['        -', '    0', 'Source', '/cygdrive/X/Implementation/dev/Source/file1.c\n']
  source_fname C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.gcda
  root         X:\Implementation\dev\Source
  fname        C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.c
Parsing coverage data for file C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.c
  Filtering coverage data for file C:\Users\Name\Projekt\Verification\Test\Integration\obj\file1.c
Processing file: C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.gcda
Running gcov: 'gcov_replace_backslash.bat C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.gcda --branch-counts --branch-probabilities --preserve-paths --object-directory C:\Users\Name\Projekt\Verification\Test\Integration\_obj' in 'C:\Users\Name\AppData\Local\Temp\tmpdlm9xrfx'
Finding source file corresponding to a gcov data file
  currdir      X:\Implementation\dev\Source
  gcov_fname   C:\Users\Name\AppData\Local\Temp\tmpdlm9xrfx\#cygdrive#X#Implementation#dev#Source#file2.c.gcov
               ['        -', '    0', 'Source', '/cygdrive/X/Implementation/dev/Source/file2.c\n']
  source_fname C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.gcda
  root         X:\Implementation\dev\Source
  fname        C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.c
Parsing coverage data for file C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.c
  Filtering coverage data for file C:\Users\Name\Projekt\Verification\Test\Integration\obj\file2.c
Processing file: ... for the remaining files

Gathered coveraged data for 0 files
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
------------------------------------------------------------------------------
TOTAL                                          0       0    --%
------------------------------------------------------------------------------
4

0 回答 0