From b9a2f64e4081e5f8f66f00ebb376068d4064daee Mon Sep 17 00:00:00 2001 From: Joey Jiao Date: Tue, 13 Jul 2021 08:10:40 +0800 Subject: all: add /modulecover page --- pkg/cover/html.go | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) (limited to 'pkg/cover/html.go') diff --git a/pkg/cover/html.go b/pkg/cover/html.go index 7afe8b54c..639adcf82 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -214,6 +214,7 @@ func (rg *ReportGenerator) DoFilterPCs(w http.ResponseWriter, progs []Prog, cove type fileStats struct { Name string + Module string CoveredLines int TotalLines int CoveredPCs int @@ -272,6 +273,7 @@ func (rg *ReportGenerator) convertToStats(progs []Prog) ([]fileStats, error) { } data = append(data, fileStats{ Name: fname, + Module: file.module, CoveredLines: coveredLines, TotalLines: totalLines, CoveredPCs: file.coveredPCs, @@ -374,7 +376,7 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste } d[subsystem.Name] = map[string]string{ - "subsystem": subsystem.Name, + "name": subsystem.Name, "lines": fmt.Sprintf("%v / %v / %.2f%%", coveredLines, totalLines, percentLines), "PCsInFiles": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFile, totalPCsInFile, percentPCsInFile), "Funcs": fmt.Sprintf("%v / %v / %.2f%%", coveredFuncs, totalFuncs, percentCoveredFunc), @@ -398,6 +400,82 @@ func (rg *ReportGenerator) DoHTMLTable(w io.Writer, progs []Prog, coverFilter ma return coverTableTemplate.Execute(w, d) } +func groupCoverByModule(datas []fileStats) map[string]map[string]string { + d := make(map[string]map[string]string) + + coveredLines := make(map[string]int) + totalLines := make(map[string]int) + coveredPCsInFile := make(map[string]int) + totalPCsInFile := make(map[string]int) + totalFuncs := make(map[string]int) + coveredFuncs := make(map[string]int) + coveredPCsInFuncs := make(map[string]int) + pcsInCoveredFuncs := make(map[string]int) + pcsInFuncs := make(map[string]int) + percentLines := make(map[string]float64) + percentPCsInFile := make(map[string]float64) + percentPCsInFunc := make(map[string]float64) + percentPCsInCoveredFunc := make(map[string]float64) + percentCoveredFunc := make(map[string]float64) + + for _, data := range datas { + coveredLines[data.Module] += data.CoveredLines + totalLines[data.Module] += data.TotalLines + coveredPCsInFile[data.Module] += data.CoveredPCs + totalPCsInFile[data.Module] += data.TotalPCs + totalFuncs[data.Module] += data.TotalFunctions + coveredFuncs[data.Module] += data.CoveredFunctions + coveredPCsInFuncs[data.Module] += data.CoveredPCsInFunctions + pcsInFuncs[data.Module] += data.TotalPCsInFunctions + pcsInCoveredFuncs[data.Module] += data.TotalPCsInCoveredFunctions + } + + for m := range totalLines { + if totalLines[m] != 0 { + percentLines[m] = 100.0 * float64(coveredLines[m]) / float64(totalLines[m]) + } + if totalPCsInFile[m] != 0 { + percentPCsInFile[m] = 100.0 * float64(coveredPCsInFile[m]) / float64(totalPCsInFile[m]) + } + if pcsInFuncs[m] != 0 { + percentPCsInFunc[m] = 100.0 * float64(coveredPCsInFuncs[m]) / float64(pcsInFuncs[m]) + } + if pcsInCoveredFuncs[m] != 0 { + percentPCsInCoveredFunc[m] = 100.0 * float64(coveredPCsInFuncs[m]) / float64(pcsInCoveredFuncs[m]) + } + if totalFuncs[m] != 0 { + percentCoveredFunc[m] = 100.0 * float64(coveredFuncs[m]) / float64(totalFuncs[m]) + } + lines := fmt.Sprintf("%v / %v / %.2f%%", coveredLines[m], totalLines[m], percentLines[m]) + pcsInFiles := fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFile[m], totalPCsInFile[m], percentPCsInFile[m]) + funcs := fmt.Sprintf("%v / %v / %.2f%%", coveredFuncs[m], totalFuncs[m], percentCoveredFunc[m]) + pcsInFuncs := fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFuncs[m], pcsInFuncs[m], percentPCsInFunc[m]) + covedFuncs := fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFuncs[m], pcsInCoveredFuncs[m], percentPCsInCoveredFunc[m]) + d[m] = map[string]string{ + "name": m, + "lines": lines, + "PCsInFiles": pcsInFiles, + "Funcs": funcs, + "PCsInFuncs": pcsInFuncs, + "PCsInCoveredFuncs": covedFuncs, + } + } + + return d +} + +func (rg *ReportGenerator) DoModuleCover(w io.Writer, progs []Prog, coverFilter map[uint32]uint32) error { + progs = fixUpPCs(rg.target.Arch, progs, coverFilter) + data, err := rg.convertToStats(progs) + if err != nil { + return err + } + + d := groupCoverByModule(data) + + return coverTableTemplate.Execute(w, d) +} + var csvHeader = []string{ "Filename", "Function", @@ -898,7 +976,7 @@ var coverTableTemplate = template.Must(template.New("coverTable").Parse(` - + @@ -909,7 +987,7 @@ var coverTableTemplate = template.Must(template.New("coverTable").Parse(` {{range $i, $p := .}} - + -- cgit mrf-deployment
SubsystemName Covered / Total Lines / % Covered / Total PCs in File / % Covered / Total PCs in Function / %
{{$p.subsystem}}{{$p.name}} {{$p.lines}} {{$p.PCsInFiles}} {{$p.PCsInFuncs}}