From 0e6628e0d76d6fd6ccb2f4966e144f13fdc68c5c Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 23 Feb 2023 19:30:35 +0100 Subject: 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. --- pkg/subsystem/entities.go | 22 ++++++++++++++++++++++ pkg/subsystem/entities_test.go | 15 +++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'pkg') 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}) +} -- cgit mrf-deployment