1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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,
)
}
}
})
}
}
|