<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/135186>135186</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [llvm-cov] Add support for 'llvm-cov show' and 'llvm-cov report' to optionally accept input from (modified) JSON produced by 'llvm-cov export'
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bartlettroscoe
      </td>
    </tr>
</table>

<pre>
    ## 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` and binary 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 arguments `-instr-profile PROFILE [BIN] [-object BIN] ...`.

This would allow r unning different test suites, exporting coverage as JSON from `llvm-cov export` for each test suite (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.  For example, 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](https://www.browserstack.com/guide/test-case-reduction-and-techniques) 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 or are 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](https://bssw.io/items/working-effectively-with-legacy-code) 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 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`.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V01v4zjS_jXypWDBlu3YOfjgdCb99oue6Ua2gcUeKbEkcZoiNSRljf79ooqSLCfZPiywQIBY_KjPp54qCu9VZRDPyeEpOTyvRBdq6865cEFjCM76wuIqt3I4J9kuyXbwjL5wqg3KmmRzSTaXLwF622kJOcIV3QASvXIi1wildRBqhMI2jTDSQ_Kw0frarAt7BYetdSF52IAw8m7H17an9WDBsiKh9QCiKLAN4EQPhb2iExWCFEGA8PD___j2ByTZqbFSlQoliDKggxyVqaBCg04ElJAPd3rw79GCJHuEJPsEyviAQoItwRo9QOlsww7wmUvaOluSysnoXBnhBiiVRp8C_KgxWnJvX6OqOlB0lGm7QOaSSIM9CFd1DZpA8tdk0povJLtPk4Rk91v6p7eGNBZCa5Sg1U9MdpcYfDIs_m0ud_GDX8uD5PBkQ41ujLAfzRpAOARj--Tw_EZ8srkII3-hNib0f6X4vwxahGYQP5EFtFoUSPmlj0kS43JNyXdrSrHSCN9fv718-fobmfv05Y_k8Ey_1jb_E4sA40qapsnDJo0m_qiVH7UJrW0PDjpjCH9SlSU6sjigD-A7FdAT3CL-6MgMmAnLjLwPscpFhaKoF9II-vTFH1uG5vyZEbhpRVrSFGplKv8GRNkFLlLytq2QsxPLdrRqroPQ26UTpFelm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