From ba1c7407eaa0c09e93d8f319c9e7e65bdf0187d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 17 Jan 2023 19:20:37 +0100 Subject: pkg/subsystem/linux: extract names for subsystems Extract the short subsystem name from the mailing list email. Stip the common prefixes and suffixes and make sure there are no duplicates. As a fallback, assign the whole list email address as a subsystem name. --- pkg/subsystem/linux/names_test.go | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 pkg/subsystem/linux/names_test.go (limited to 'pkg/subsystem/linux/names_test.go') diff --git a/pkg/subsystem/linux/names_test.go b/pkg/subsystem/linux/names_test.go new file mode 100644 index 000000000..0b2352411 --- /dev/null +++ b/pkg/subsystem/linux/names_test.go @@ -0,0 +1,115 @@ +// Copyright 2023 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package linux + +import ( + "testing" + + "github.com/google/syzkaller/pkg/subsystem/entity" +) + +func TestEmailToName(t *testing.T) { + tests := map[string]string{ + // These are following the general rules. + "linux-nilfs@vger.kernel.org": "nilfs", + "tomoyo-dev-en@lists.osdn.me": "tomoyo", + "tipc-discussion@lists.sourceforge.net": "tipc", + "v9fs-developer@lists.sourceforge.net": "v9fs", + "zd1211-devs@lists.sourceforge.net": "zd1211", + // Test that we can handle exceptions. + "virtualization@lists.linux-foundation.org": "virt", + } + for email, name := range tests { + result := emailToName(email) + if result != name { + t.Fatalf("%#v: expected %#v, got %#v", email, name, result) + } + } +} + +type subsystemTestInput struct { + email string + outName string +} + +func (sti subsystemTestInput) ToSubsystem() *entity.Subsystem { + s := &entity.Subsystem{} + if sti.email != "" { + s.Lists = append(s.Lists, sti.email) + } + return s +} + +func TestSetSubsystemNames(t *testing.T) { + tests := []struct { + name string + inputs []subsystemTestInput + mustFail bool + }{ + { + name: "plan test", + inputs: []subsystemTestInput{ + { + email: "linux-ntfs-dev@lists.sourceforge.net", + outName: "ntfs", + }, + { + email: "llvm@lists.linux.dev", + outName: "llvm", + }, + }, + }, + { + name: "has dup name", + inputs: []subsystemTestInput{ + { + email: "linux-ntfs-dev@lists.sourceforge.net", + outName: "ntfs", + }, + { + email: "ntfs@lists.sourceforge.net", + outName: "ntfs", + }, + }, + mustFail: true, + }, + { + name: "has empty list", + inputs: []subsystemTestInput{ + { + email: "linux-ntfs-dev@lists.sourceforge.net", + outName: "ntfs", + }, + { + email: "", + outName: "", + }, + }, + mustFail: true, + }, + } + for _, test := range tests { + curr := test + t.Run(curr.name, func(t *testing.T) { + list := []*entity.Subsystem{} + for _, i := range curr.inputs { + list = append(list, i.ToSubsystem()) + } + err := setSubsystemNames(list) + if curr.mustFail != (err != nil) { + t.Fatalf("expected failure: %v, got: %v", curr.mustFail, err) + } + if curr.mustFail { + return + } + for i, item := range list { + if item.Name != curr.inputs[i].outName { + t.Fatalf("invalid name for #%d: expected %#v, got %#v", + i+1, curr.inputs[i].outName, item.Name, + ) + } + } + }) + } +} -- cgit mrf-deployment