linux-test-project / lcov

LCOV
GNU General Public License v2.0
866 stars 234 forks source link

Lcov -list does not show the correct code coverage #267

Closed Wayonb closed 5 months ago

Wayonb commented 5 months ago

I have a gcc 13.2 code coverage build where lcov -list does not show the correct information.

Below is the part of the output of lcov --list client_coverage.info Some files show 2000% coverage but the overall coverage is smaller than excepted.

utils/Logging.h                                |26.1%    23| 0.0%   6|    -    0
utils/MacroBasedEnum.h                         | 390%    10| 0.0%  33|    -    0
utils/MemoryUtils.h                            | 800%    12| 0.0%  92|    -    0
utils/ModificationSafeIterableContainer.h      |44.4%    18| 0.0%   8|    -    0
utils/NamedObject.h                            |53.3%    15| 0.0%   8|    -    0
utils/NetworkTime.cpp                          |30.8%    13| 0.0%   4|    -    0
utils/PathUtils.h                              |15.8%    19| 0.0%   3|    -    0
utils/RandomGenerator.cpp                      |43.5%    23| 0.0%  10|    -    0
utils/RandomGenerator.h                        | 0.0%     1|    -   0|    -    0
utils/RawBuffer.cpp                            |50.0%     4| 0.0%   2|    -    0
utils/RawBuffer.h                              |16.7%     6| 0.0%   1|    -    0
utils/ReentrancyCheckReaderNotificationPolicy.h|21.4%    14| 0.0%   3|    -    0
utils/ShortHash.h                              | 0.0%     2|    -   0|    -    0
utils/SpinLock.h                               |20.0%     5| 0.0%   1|    -    0
utils/SpinReaderWriterLock.h                   |16.7%    66| 0.0%  11|    -    0
utils/StackLogger.h                            |16.7%    24| 0.0%   4|    -    0
utils/StackTimer.h                             | 0.0%     3|    -   0|    -    0
utils/StreamFormatGuard.h                      |22.2%     9| 0.0%   2|    -    0
utils/ThrottleLogger.h                         |12.5%     8| 0.0%   1|    -    0
utils/TimeSpan.cpp                             |14.3%     7| 0.0%   1|    -    0
utils/TimeSpan.h                               |26.7%    15| 0.0%   4|    -    0
utils/WeakContainer.h                          |88.9%    18| 0.0%  16|    -    0
utils/WrappedWithOwnerDecorator.h              | 100%    13| 0.0%  13|    -    0
validators/AggregateValidationResult.cpp       |27.3%    11| 0.0%   3|    -    0
validators/AggregateValidatorBuilder.h         |68.2%    22| 0.0%  15|    -    0
validators/DemuxValidatorBuilder.h             |2000%    16| 0.0% 297|    -    0
validators/FunctionalNotificationValidator.h   |3000%     8| 0.0% 236|    -    0
validators/NotificationValidator.h             |    -     0|    -   0|    -    0
validators/NotificationValidatorAdapter.cpp    |30.8%    13| 0.0%   4|    -    0
validators/ParallelValidationPolicy.cpp        |31.6%    38| 0.0%  12|    -    0
validators/ParallelValidationPolicy.h          | 0.0%     1|    -   0|    -    0
validators/ValidatingNotificationSubscriber.h  | 8.3%    12| 0.0%   1|    -    0
validators/ValidationResult.cpp                |18.2%    11| 0.0%   2|    -    0
validators/ValidationResult.h                  | 0.0%     4|    -   0|    -    0
validators/ValidatorContext.h                  |20.0%     5| 0.0%   1|    -    0
validators/ValidatorUtils.h                    | 0.0%     1|    -   0|    -    0
version/version.cpp                            |25.0%     4| 0.0%   1|    -    0
================================================================================
                                         Total:|57.0% 25054| 0.0% 12k|    -    0

If I ran lcov --summary client_coverage.info it shows the correct overall coverage.

lcov --summary client_coverage.info
Summary coverage rate:
  lines......: 97.7% (25054 of 25638 lines)
  functions..: 88.1% (12581 of 14284 functions)
  branches...: no data found
Wayonb commented 5 months ago

My environment is Gcc 13.2 Ubuntu 24.04 Lcov 2.0-4

henry2cox commented 5 months ago

I fear that I don't know what lcov/2.0-4 is. There is a tarball release for lcov/2.0 (from last May), and there is the github repo...but no such ID. Probably doesn't matter.

Two steps:

I guess that the data you see in the genhtml --flat ... output matches your expectation (i.e., the HTML data looks correct) - which would tend to indicate that the data is correctly parsed, just incorrectly reported by the --list option.

Thanks Henry

Wayonb commented 5 months ago

Hi @henry2cox

Thanks for the quick reply.

I installed lcov from the repo and the --list now matches the --summary option. 👍🏾 It seems the issue with Ubuntu package so I will reach out to them.

/usr/local/bin/lcov --version
lcov: LCOV version 2.0-123.gd981242
utils/Logging.h                                | 100%    23| 100%   6|    -    0
utils/MacroBasedEnum.h                         | 100%    10|84.6%  39|    -    0
utils/MemoryUtils.h                            | 100%    12|95.8%  96|    -    0
utils/ModificationSafeIterableContainer.h      |94.7%    19| 100%   8|    -    0
utils/NamedObject.h                            |93.8%    16| 100%   8|    -    0
utils/NetworkTime.cpp                          | 100%    13| 100%   4|    -    0
utils/PathUtils.h                              | 100%    19| 100%   3|    -    0
utils/RandomGenerator.cpp                      | 100%    23| 100%  10|    -    0
utils/RandomGenerator.h                        | 100%     1|    -   0|    -    0
utils/RawBuffer.cpp                            | 100%     4| 100%   2|    -    0
utils/RawBuffer.h                              | 100%     6| 100%   1|    -    0
utils/ReentrancyCheckReaderNotificationPolicy.h| 100%    14| 100%   3|    -    0
utils/ShortHash.h                              | 100%     2|    -   0|    -    0
utils/SpinLock.h                               | 100%     5| 100%   1|    -    0
utils/SpinReaderWriterLock.h                   | 100%    66| 100%  11|    -    0
utils/StackLogger.h                            | 100%    24| 100%   4|    -    0
utils/StackTimer.h                             | 100%     3|    -   0|    -    0
utils/StreamFormatGuard.h                      | 100%     9| 100%   2|    -    0
utils/ThrottleLogger.h                         | 100%     8| 100%   1|    -    0
utils/TimeSpan.cpp                             | 100%     7| 100%   1|    -    0
utils/TimeSpan.h                               | 100%    15| 100%   4|    -    0
utils/WeakContainer.h                          | 100%    18| 100%  16|    -    0
utils/WrappedWithOwnerDecorator.h              | 100%    13| 100%  13|    -    0
validators/AggregateValidationResult.cpp       | 100%    11| 100%   3|    -    0
validators/AggregateValidatorBuilder.h         | 100%    22| 100%  15|    -    0
validators/DemuxValidatorBuilder.h             | 100%    16|92.8% 320|    -    0
validators/FunctionalNotificationValidator.h   | 100%     8|98.3% 240|    -    0
validators/NotificationValidator.h             | 0.0%     1|    -   0|    -    0
validators/NotificationValidatorAdapter.cpp    | 100%    13| 100%   4|    -    0
validators/ParallelValidationPolicy.cpp        |95.0%    40| 100%  12|    -    0
validators/ParallelValidationPolicy.h          | 100%     1|    -   0|    -    0
validators/ValidatingNotificationSubscriber.h  | 100%    12| 100%   1|    -    0
validators/ValidationResult.cpp                | 100%    11| 100%   2|    -    0
validators/ValidationResult.h                  | 100%     4|    -   0|    -    0
validators/ValidatorContext.h                  | 100%     5| 100%   1|    -    0
validators/ValidatorUtils.h                    | 100%     1|    -   0|    -    0
version/version.cpp                            | 100%     4| 100%   1|    -    0
================================================================================
                                         Total:|97.7% 25638|88.1% 14k|    -    0
Message summary:
  no messages were reported
root@71435316da35:/catapult-src# /usr/local/bin/lcov --summary client_coverage.info 
Reading tracefile client_coverage.info.
Summary coverage rate:
  source files: 1280
  lines.......: 97.7% (25054 of 25638 lines)
  functions...: 88.1% (12581 of 14284 functions)
Message summary:
  no messages were reported
henry2cox commented 5 months ago

Incidentally: your coverage numbers look quite good and your project size is probably on the edge of what people can remember from one release to the next. You might want to look into implementing a differential coverage methodology. That enables a couple of useful capabilities. primarily that your jenkins/regression system can analyze the coverage data for you - then notify you if something bad happens (e.g., somebody checks in code which is not exercised, or some new commit results in lost coverage elsewhere). This can be entirely automated, with no manual effort/nobody has to look at the reports - until and unless something fails. This makes coverage just like any other regression criteria. You might also want to enable branch coverage - just to see what happens:-). Actually working to increase it (and to mark unreachable branches) may or may not be worth the effort - and will depend on your QOS targets and observed defect rate.

Glad to see that the tool is working.

Henry

Wayonb commented 5 months ago

Thanks.

I saw that differential coverage was a new feature in lcov 2 so will take a look.