github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/subsystem/linux/names_test.go (about) 1 // Copyright 2023 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package linux 5 6 import ( 7 "testing" 8 9 "github.com/google/syzkaller/pkg/subsystem" 10 ) 11 12 func TestEmailToName(t *testing.T) { 13 tests := map[string]string{ 14 // These are following the general rules. 15 "linux-nilfs@vger.kernel.org": "nilfs", 16 "tomoyo-dev-en@lists.osdn.me": "tomoyo", 17 "tipc-discussion@lists.sourceforge.net": "tipc", 18 "zd1211-devs@lists.sourceforge.net": "zd1211", 19 "chrome-platform@lists.linux.dev": "chrome", 20 "b.a.t.m.a.n@lists.open-mesh.org": "batman", 21 // Test that we can handle exceptions. 22 "virtualization@lists.linux-foundation.org": "virt", 23 } 24 for email, name := range tests { 25 result := emailToName(email) 26 if result != name { 27 t.Fatalf("%#v: expected %#v, got %#v", email, name, result) 28 } 29 } 30 } 31 32 type subsystemTestInput struct { 33 inName string 34 email string 35 outName string 36 } 37 38 func (sti subsystemTestInput) ToSubsystem() *subsystem.Subsystem { 39 s := &subsystem.Subsystem{Name: sti.inName} 40 if sti.email != "" { 41 s.Lists = append(s.Lists, sti.email) 42 } 43 return s 44 } 45 46 func TestSetSubsystemNames(t *testing.T) { 47 tests := []struct { 48 name string 49 inputs []subsystemTestInput 50 mustFail bool 51 }{ 52 { 53 name: "plan test", 54 inputs: []subsystemTestInput{ 55 { 56 email: "linux-ntfs-dev@lists.sourceforge.net", 57 outName: "ntfs", 58 }, 59 { 60 email: "llvm@lists.linux.dev", 61 outName: "llvm", 62 }, 63 }, 64 }, 65 { 66 name: "has dup name", 67 inputs: []subsystemTestInput{ 68 { 69 email: "linux-ntfs-dev@lists.sourceforge.net", 70 outName: "ntfs", 71 }, 72 { 73 email: "ntfs@lists.sourceforge.net", 74 outName: "ntfs", 75 }, 76 }, 77 mustFail: true, 78 }, 79 { 80 name: "has empty list", 81 inputs: []subsystemTestInput{ 82 { 83 email: "linux-ntfs-dev@lists.sourceforge.net", 84 outName: "ntfs", 85 }, 86 { 87 email: "", 88 outName: "", 89 }, 90 }, 91 mustFail: true, 92 }, 93 { 94 name: "has existing names", 95 inputs: []subsystemTestInput{ 96 { 97 inName: "some", 98 email: "some-list@list.com", 99 outName: "some", 100 }, 101 { 102 email: "ntfs@lists.sourceforge.net", 103 outName: "ntfs", 104 }, 105 }, 106 }, 107 { 108 name: "collision with an existing name", 109 inputs: []subsystemTestInput{ 110 { 111 inName: "ntfs", 112 email: "ntfs3@lists.sourceforge.net", 113 outName: "ntfs", 114 }, 115 { 116 email: "ntfs@lists.sourceforge.net", 117 outName: "ntfs", 118 }, 119 }, 120 mustFail: true, 121 }, 122 } 123 for _, test := range tests { 124 curr := test 125 t.Run(curr.name, func(t *testing.T) { 126 list := []*subsystem.Subsystem{} 127 for _, i := range curr.inputs { 128 list = append(list, i.ToSubsystem()) 129 } 130 err := setSubsystemNames(list) 131 if curr.mustFail != (err != nil) { 132 t.Fatalf("expected failure: %v, got: %v", curr.mustFail, err) 133 } 134 if curr.mustFail { 135 return 136 } 137 for i, item := range list { 138 if item.Name != curr.inputs[i].outName { 139 t.Fatalf("invalid name for #%d: expected %#v, got %#v", 140 i+1, curr.inputs[i].outName, item.Name, 141 ) 142 } 143 } 144 }) 145 } 146 }