From f2eee6b3351e8cecbbd53e27c4f690a78b9ec2a2 Mon Sep 17 00:00:00 2001 From: Kevin Ding Date: Mon, 24 Feb 2025 10:23:57 +0800 Subject: pkg/cover: allow paths to be excluded from stats Some sub paths may not be covered due to hardware configuration, or lack of interest. This patch allows them to be excluded from the stats. This can be convenient if the excluded paths are deep in the hierarchy: { "name": "sound", "path": [ "techpack/audio", "-techpack/audio/asoc/aaa/bbb" "-techpack/audio/asoc/aaa/ccc" ] } --- pkg/cover/html.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'pkg/cover/html.go') diff --git a/pkg/cover/html.go b/pkg/cover/html.go index ae4aa6c4b..042d28b40 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -537,8 +537,12 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste var percentCoveredFunc float64 for _, path := range subsystem.Paths { + if strings.HasPrefix(path, "-") { + continue + } + excludes := buildExcludePaths(path, subsystem.Paths) for _, data := range datas { - if !strings.HasPrefix(data.Name, path) { + if !strings.HasPrefix(data.Name, path) || isExcluded(data.Name, excludes) { continue } coveredLines += data.CoveredLines @@ -582,6 +586,25 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste return d } +func buildExcludePaths(prefix string, paths []string) []string { + var excludes []string + for _, path := range paths { + if strings.HasPrefix(path, "-") && strings.HasPrefix(path[1:], prefix) { + excludes = append(excludes, path[1:]) + } + } + return excludes +} + +func isExcluded(path string, excludes []string) bool { + for _, exclude := range excludes { + if strings.HasPrefix(path, exclude) { + return true + } + } + return false +} + func (rg *ReportGenerator) DoSubsystemCover(w io.Writer, params HandlerParams) error { var progs = fixUpPCs(params.Progs, params.Filter) data, err := rg.convertToStats(progs) -- cgit mrf-deployment