Skip to content

Commit 679ffb7

Browse files
committed
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" ] }
1 parent d34966d commit 679ffb7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pkg/cover/html.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,12 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste
445445
var percentCoveredFunc float64
446446

447447
for _, path := range subsystem.Paths {
448+
if strings.HasPrefix(path, "-") {
449+
continue
450+
}
451+
excludes := buildExcludePaths(path, subsystem.Paths)
448452
for _, data := range datas {
449-
if !strings.HasPrefix(data.Name, path) {
453+
if !strings.HasPrefix(data.Name, path) || isExcluded(data.Name, excludes) {
450454
continue
451455
}
452456
coveredLines += data.CoveredLines
@@ -490,6 +494,25 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste
490494
return d
491495
}
492496

497+
func buildExcludePaths(prefix string, paths []string) []string {
498+
var excludes []string
499+
for _, path := range paths {
500+
if strings.HasPrefix(path, "-") && strings.HasPrefix(path[1:], prefix) {
501+
excludes = append(excludes, path[1:])
502+
}
503+
}
504+
return excludes
505+
}
506+
507+
func isExcluded(path string, excludes []string) bool {
508+
for _, exclude := range excludes {
509+
if strings.HasPrefix(path, exclude) {
510+
return true
511+
}
512+
}
513+
return false
514+
}
515+
493516
func (rg *ReportGenerator) DoSubsystemCover(w io.Writer, params HandlerParams) error {
494517
var progs = fixUpPCs(params.Progs, params.Filter)
495518
data, err := rg.convertToStats(progs)

pkg/mgrconfig/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ type Config struct {
5151
KernelBuildSrc string `json:"kernel_build_src,omitempty"`
5252
// Is the kernel built separately from the modules? (Specific to Android builds)
5353
AndroidSplitBuild bool `json:"android_split_build"`
54-
// Kernel subsystem with paths to each subsystem
54+
// Kernel subsystem with paths to each subsystem, paths starting with "-" will be excluded
5555
// "kernel_subsystem": [
56-
// { "name": "sound", "path": ["sound", "techpack/audio"]},
56+
// { "name": "sound", "path": ["sound", "techpack/audio", "-techpack/audio/dsp"]},
5757
// { "name": "mydriver": "path": ["mydriver_path"]}
5858
// ]
5959
KernelSubsystem []Subsystem `json:"kernel_subsystem,omitempty"`

0 commit comments

Comments
 (0)