Skip to content

[llvm-cov] Add support for 'llvm-cov show' and 'llvm-cov report' to optionally accept coverage counts from (modified) JSON produced by 'llvm-cov export' #135186

@bartlettroscoe

Description

@bartlettroscoe

Description

It would be very desirable for the commands llvm-cov report and llvm-cov show to optionally accept raw coverage data as JSON (modified after being generated by llvm-cov export) , instead of only from the *.profdata files. The JSON coverage data might be input as the new argument --cov-data <coverage>.json called like:

llvm-cov show --cov-data <coverage>.json [other options as they are now]

and

llvm-cov report --cov-data <coverage>.json [other options as they are now]

and the new argument --cov-data <coverage>.json would take the place of the argument -instr-profile PROFILE and perhaps even the [BIN] [-object BIN] ... binary arguments?

This would allow running different test suites for the same library code, exporting coverage as JSON from llvm-cov export for each test suite (e.g., testsuite1 and testsuite2) and doing things like:

  • Adding together the coverage from the two test suites (i.e. taking the union)
  • Diffing the coverage between the two test suites (i.e. what coverage is only in testsuite1, only in testsuite2, or in both test suites)

Then you could produce different outputs of coverage files for each of these use cases. For example, you could call llvm-cov show with the input JSON that contains the coverage in testsuite2 that is not provided in testsuite1. In this scenario, testsuite1 might be a fast running unit-test suite while testsuite2 might be a much more expensive set of system-level tests. This would show you where you might be able to add some fast unit tests to provide the missing coverage. Also, this data would be needed for doing things like test suite/case reduction or in replacing one set of tests with another set of tests.

Another important use case is diffing the coverage before and after changes to the code in a GitHub PR or GitLab MR. You could highlight the lines of code that are newly covered and/or lost coverage after the proposed set of Git commits. Also, you might require the PR/MR to only add coverage and not loose any coverage in region or branch coverage and that any regions (or branches) that are touched must be covered with tests. The latter would force the usage of the Legacy Code Change Algorithm for all code in the repo with every change. That way, the coverage will only improve (or stay the same) with every commit to the repo. (And for legacy code, the coverage would necessarily go up as development continues.)

These are incredibly important use cases to make coverage information useful and the basic tools should support these use cases. That is, absolute coverage is not very compelling or motivating for most people and project stakeholders. But targeted differences in coverage like described above can be very compelling and can be enforced by reasonable development and integration processes in an incremental way.

Workarounds

One could diff the generated *.html files produced by llvm-cov show for testsuite1 and testsuite2 (e.g. using a tool like html-differ) and produce new *.html files for the difference or the union. But that would be more expensive and fragile and require more custom user code to implement compared to working with the data in the JSON files produced by llvm-cov export.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving things as opposed to bug fixing, e.g. new or missing featuretools:llvm-cov

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions