Skip to content

Commit 1f53a76

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 c390174 commit 1f53a76

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

pkg/cover/html.go

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

537537
for _, path := range subsystem.Paths {
538+
if strings.HasPrefix(path, "-") {
539+
continue
540+
}
541+
excludes := buildExcludePaths(path, subsystem.Paths)
538542
for _, data := range datas {
539-
if !strings.HasPrefix(data.Name, path) {
543+
if !strings.HasPrefix(data.Name, path) || isExcluded(data.Name, excludes) {
540544
continue
541545
}
542546
coveredLines += data.CoveredLines
@@ -580,6 +584,25 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste
580584
return d
581585
}
582586

587+
func buildExcludePaths(prefix string, paths []string) []string {
588+
var excludes []string
589+
for _, path := range paths {
590+
if strings.HasPrefix(path, "-") && strings.HasPrefix(path[1:], prefix) {
591+
excludes = append(excludes, path[1:])
592+
}
593+
}
594+
return excludes
595+
}
596+
597+
func isExcluded(path string, excludes []string) bool {
598+
for _, exclude := range excludes {
599+
if strings.HasPrefix(path, exclude) {
600+
return true
601+
}
602+
}
603+
return false
604+
}
605+
583606
func (rg *ReportGenerator) DoSubsystemCover(w io.Writer, params HandlerParams) error {
584607
var progs = fixUpPCs(params.Progs, params.Filter)
585608
data, err := rg.convertToStats(progs)

pkg/cover/report_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,46 @@ var sampleJSONLlProgs = []byte(`{
460460
}
461461
]
462462
}`)
463+
464+
func makeFileStat(name string) fileStats {
465+
return fileStats{
466+
Name: name,
467+
CoveredLines: 1,
468+
TotalLines: 8,
469+
CoveredPCs: 1,
470+
TotalPCs: 4,
471+
TotalFunctions: 2,
472+
CoveredFunctions: 1,
473+
CoveredPCsInFunctions: 1,
474+
TotalPCsInCoveredFunctions: 2,
475+
TotalPCsInFunctions: 2,
476+
}
477+
}
478+
479+
func TestCoverByFilePrefixes(t *testing.T) {
480+
datas := []fileStats{
481+
makeFileStat("a"),
482+
makeFileStat("a/1"),
483+
makeFileStat("a/2"),
484+
makeFileStat("a/2/A"),
485+
makeFileStat("a/3"),
486+
}
487+
subsystems := []mgrconfig.Subsystem{
488+
{
489+
Name: "test",
490+
Paths: []string{
491+
"a",
492+
"-a/2",
493+
},
494+
},
495+
}
496+
d := groupCoverByFilePrefixes(datas, subsystems)
497+
assert.Equal(t, d["test"], map[string]string{
498+
"name": "test",
499+
"lines": "3 / 24 / 12.50%",
500+
"PCsInFiles": "3 / 12 / 25.00%",
501+
"Funcs": "3 / 6 / 50.00%",
502+
"PCsInFuncs": "3 / 6 / 50.00%",
503+
"PCsInCoveredFuncs": "3 / 6 / 50.00%",
504+
})
505+
}

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)