aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/linux/names_test.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-01-17 19:20:37 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-10 14:34:44 +0100
commitba1c7407eaa0c09e93d8f319c9e7e65bdf0187d3 (patch)
treef7348e12a2c86a7e1858412c4b206882d15b2003 /pkg/subsystem/linux/names_test.go
parent4c1f201b6fc2cc30625d3c706b1f45cc68ef0223 (diff)
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.
Diffstat (limited to 'pkg/subsystem/linux/names_test.go')
-rw-r--r--pkg/subsystem/linux/names_test.go115
1 files changed, 115 insertions, 0 deletions
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,
+ )
+ }
+ }
+ })
+ }
+}