aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-02-23 19:30:35 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-24 10:29:40 +0100
commit0e6628e0d76d6fd6ccb2f4966e144f13fdc68c5c (patch)
treef9345f4e0dfb3a0e927f1bb456afb1feaaad25b8 /pkg
parenta1ab4f01d34b4a7858d84bd662b511f55b4b65c4 (diff)
tools/syz-query-subsystems: add filtering functionality
Two more flags: - filter: allows to choose only a subset of the possible subsystems. - emails: allows to force empty Lists and Maintainers.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/subsystem/entities.go22
-rw-r--r--pkg/subsystem/entities_test.go15
2 files changed, 37 insertions, 0 deletions
diff --git a/pkg/subsystem/entities.go b/pkg/subsystem/entities.go
index 1f7456e84..457e57a3e 100644
--- a/pkg/subsystem/entities.go
+++ b/pkg/subsystem/entities.go
@@ -44,6 +44,28 @@ func (subsystem *Subsystem) Emails() []string {
return ret
}
+func FilterList(list []*Subsystem, filter func(*Subsystem) bool) []*Subsystem {
+ keep := map[*Subsystem]bool{}
+ for _, item := range list {
+ keep[item] = filter(item)
+ }
+ newList := []*Subsystem{}
+ for _, item := range list {
+ if !keep[item] {
+ continue
+ }
+ newParents := []*Subsystem{}
+ for _, p := range item.Parents {
+ if keep[p] {
+ newParents = append(newParents, p)
+ }
+ }
+ item.Parents = newParents
+ newList = append(newList, item)
+ }
+ return newList
+}
+
// PathRule describes the part of the directory tree belonging to a single subsystem.
type PathRule struct {
IncludeRegexp string
diff --git a/pkg/subsystem/entities_test.go b/pkg/subsystem/entities_test.go
index 58166b91b..81c970b65 100644
--- a/pkg/subsystem/entities_test.go
+++ b/pkg/subsystem/entities_test.go
@@ -39,3 +39,18 @@ func TestSubsystemEmails(t *testing.T) {
"a@list.com", "b@list.com", "c@list.com", "d@list.com", "d@person.com",
})
}
+
+func TestFilterList(t *testing.T) {
+ parentParent := &Subsystem{}
+ parentA := &Subsystem{Parents: []*Subsystem{parentParent}}
+ parentB := &Subsystem{Parents: []*Subsystem{parentParent}}
+ entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}}
+
+ newList := FilterList([]*Subsystem{parentA, parentB, parentParent, entity},
+ func(s *Subsystem) bool {
+ return s != parentB
+ },
+ )
+ assert.Len(t, newList, 3)
+ assert.ElementsMatch(t, entity.Parents, []*Subsystem{parentA})
+}