0

I am trying to merge coverage data from specific files from multiple runs into a single "report". In each project I generate test coverage for different files, each in a separate project folder and then at the end I pick and choose what files to include in my final project. If I use the following command line where I select each file with a --filter [complete path and filename], it works perfectly and I get a combined report with just these files. I also see it pick the files up in the log since I have -v option enabled shown below.

gcovr -g -k -s --html --html-details -o code_coverage_summary2.html -r . --filter firmware/crc32/crc_unit_tests.X/mcc_generated_files/boot/boot_verify_crc32.c --filter firmware/sha256/sha_unit_tests.X/mcc_generated_files/boot/boot_verify_sha256.c --filter firmware/checksum/checksum_unit_tests.X/mcc_generated_files/boot/boot_verify_checksum16.c --filter firmware/command_processor/bootloader_pic_tb.X/mcc_generated_files/boot/boot_process.c -v > log4.txt

Log File From above run (many many lines before)

  currdir      C:\Users\murphy\Downloads\archive (5)\archive\src\test
  gcov_fname   C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\sha256\sha_unit_tests.X\mcc_generated_files\boot\boot_verify_sha256.c.gcov
               ['        -', '    0', 'Source', 'boot_verify_sha256.c\n']
  source_fname None
  root         C:\Users\murphy\Downloads\archive (5)\archive\src\test
  fname        C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\sha256\sha_unit_tests.X\mcc_generated_files\boot\boot_verify_sha256.c
Parsing coverage data for file C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\sha256\sha_unit_tests.X\mcc_generated_files\boot\boot_verify_sha256.c
uncovered: {122}
covered:   {49: 1, 54: 1, 55: 1, 57: 1, 59: 1, 60: 1, 61: 1, 64: 1, 65: 1, 70: 1, 75: 1, 80: 1, 81: 1, 83: 1, 85: 1, 88: 1, 90: 1, 92: 1, 95: 1, 97: 1, 100: 1, 102: 1, 105: 1, 107: 1, 110: 1, 112: 1, 115: 1, 117: 1, 120: 1, 125: 1, 127: 1, 132: 1}
branches:  {}
noncode:   {128, 129, 3, 131, 133, 6, 134, 9, 12, 23, 27, 30, 31, 33, 35, 37, 39, 44, 46, 48, 50, 51, 53, 56, 58, 62, 63, 66, 67, 69, 71, 72, 74, 76, 77, 79, 82, 84, 86, 87, 89, 91, 93, 94, 96, 98, 99, 101, 103, 104, 106, 108, 109, 111, 113, 114, 116, 118, 119, 121, 123, 124, 126}
Finding source file corresponding to a gcov data file
  currdir      C:\Users\murphy\Downloads\archive (5)\archive\src\test
  gcov_fname   C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\crc32\crc_unit_tests.X\mcc_generated_files\boot\boot_verify_crc32.c.gcov
               ['        -', '    0', 'Source', 'boot_verify_crc32.c\n']
  source_fname None
  root         C:\Users\murphy\Downloads\archive (5)\archive\src\test
  fname        C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\crc32\crc_unit_tests.X\mcc_generated_files\boot\boot_verify_crc32.c
Parsing coverage data for file C:\Users\murphy\Downloads\archive (5)\archive\src\test\firmware\crc32\crc_unit_tests.X\mcc_generated_files\boot\boot_verify_crc32.c
uncovered: set()
covered:   {50: 1, 55: 1, 56: 1, 57: 1, 62: 1, 63: 1, 65: 1, 67: 1, 70: 1, 72: 1, 74: 1, 77: 1, 79: 1, 82: 1, 84: 1, 87: 1, 89: 1, 92: 1, 94: 1, 97: 1, 99: 1, 102: 1, 104: 1, 108: 1, 109: 1, 110: 1, 112: 1, 114: 1, 120: 1, 121: 1, 123: 1, 128: 1, 129: 1, 131: 1, 134: 1, 139: 1}
branches:  {}
noncode:   {3, 132, 133, 6, 135, 136, 9, 138, 12, 140, 141, 23, 28, 31, 33, 35, 38, 40, 45, 47, 49, 51, 52, 54, 58, 59, 61, 64, 66, 68, 69, 71, 73, 75, 76, 78, 80, 81, 83, 85, 86, 88, 90, 91, 93, 95, 96, 98, 100, 101, 103, 105, 106, 111, 113, 115, 122, 124}
Finding source file corresponding to a gcov data file

(many many lines after)

I have many more files to add and I really do not want to have a specific filter for each unique path & filename. What I want is a filter for all of the files that have the pattern boot_verify*.c in them. I have tried different regex expressions shown below but they all return no files selected.

--filter '(.+/)?boot_verify(.*)\.c$' 
--filter '(.+/)?boot_verify_([a-z][A-Z][0-9]+)\.c$'
--filter '(.+/)?boot_verify_([a-z][A-Z][0-9]*)\.c$'

To force the issue I tried a regex with just a single file name below and even that did not work.

--filter '(.+/)?boot_verify_crc32\.c$' 

I would really like to get the wild card pattern and the specific filename pattern working. What am I doing wrong?

Ken

Ken 99
  • 19
  • 3
  • Which version of gcovr are you using? Version 5 contains relevant fixes. You are running Windows. Which shell/command line are you using to run the gcovr command? Bash? Cmd.exe? Different command lines have different escaping rules. – amon Dec 03 '21 at 10:52
  • I am using 4.1 and will see about upgrading. I am also running on windows and cmd. After reading your post and re-reading the user guide, I switched my command from using ticks around my filter to quotes and it's now processing the regex command correctly. Thank you for the suggestions. – Ken 99 Dec 03 '21 at 16:45

1 Answers1

1

When using regexes in command line arguments, they must be properly escaped.

  • When using Bash or another POSIX shell on Linux or other Unix-like operating systems including MacOS, surround the regex with single quotes. For example:

    gcovr --filter '(.+/)?boot_verify_crc32\.c$'
    

    See the Quoting section in the Bash Reference Manual or in the POSIX spec. In particular, escaping/quoting is necessary if the regex contains any of the following characters, or space characters:

    | & ; < > ( ) $ ` \ " ' * ? [ # ˜ = %
    
  • When using cmd.exe on Windows, surround the regex with double quotes:

    gcovr --filter "(.+/)?boot_verify_crc32\.c$"
    

    I cannot find a good reference for this, though Parsing C Command-Line Arguments seems to contain the relevant rules.

  • When using PowerShell on Windows, surround the regex with single quotes:

    gcovr --filter '(.+/)?boot_verify_crc32\.c$'
    

    See the sections about Quoting Rules and about Parsing in the PowerShell documentation. In particular, escaping/quoting is necessary if the regex contains any of the following characters, or space characters:

    ' " ` , ; ( ) { } | & < > @ #
    

Additionally, please note that gcovr 4.1 is from 2018. Since then, some fixes relating to Windows support and filter matching have been implemented. Assuming that you installed gcovr as pip3 install gcovr, you can upgrade to the latest stable release with:

pip3 install -U gcovr
amon
  • 57,091
  • 2
  • 89
  • 149