aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/cover/report.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2024-04-09 08:46:39 +0200
committerTaras Madan <tarasmadan@google.com>2024-04-09 12:16:53 +0000
commit171ec3714ee4886a3f5ecbfe71f63c8f81c7fd7c (patch)
tree93f2d371ed75752275467bbce73d6387460b3eda /pkg/cover/report.go
parentb3198cd94cc221153d34443bc657c799ec47a2ed (diff)
pkg/cover: fix jsonl hit count calculation
prepareFileMap does more work than we need and leads to incorrect hit counts. prepareFileMap produces hit counts per source line (for source reports), but jsonl exports data based on coverage callbacks, not source lines. So if we have 2 callbacks on the same line, we will double count them (both will have hit count 2). If we calculate total percent later based on that data, it will be wrong. Use simpler calculation based on PCs.
Diffstat (limited to 'pkg/cover/report.go')
-rw-r--r--pkg/cover/report.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/cover/report.go b/pkg/cover/report.go
index 7b291874b..400ffdc02 100644
--- a/pkg/cover/report.go
+++ b/pkg/cover/report.go
@@ -106,7 +106,7 @@ func (rg *ReportGenerator) prepareFileMap(progs []Prog, debug bool) (fileMap, er
}
matchedPC := false
for _, frame := range rg.Frames {
- f := FileByFrame(files, &frame)
+ f := fileByFrame(files, &frame)
ln := f.lines[frame.StartLine]
coveredBy := progPCs[frame.PC]
if len(coveredBy) == 0 {
@@ -222,7 +222,7 @@ func (rg *ReportGenerator) symbolizePCs(PCs []uint64) error {
return nil
}
-func FileByFrame(files map[string]*file, frame *backend.Frame) *file {
+func fileByFrame(files map[string]*file, frame *backend.Frame) *file {
f := files[frame.Name]
if f == nil {
f = &file{