aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem/linux/maintainers_test.go
blob: f69485eaebdd12238da80f98b76dfdec745efdec (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// 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 (
	"strings"
	"testing"

	"github.com/google/go-cmp/cmp"
	"github.com/google/syzkaller/pkg/subsystem"
)

func TestRecordToPathRule(t *testing.T) {
	tests := []struct {
		name    string
		record  maintainersRecord
		match   []string
		noMatch []string
	}{
		{
			name: `general test`,
			record: maintainersRecord{
				includePatterns: []string{
					`drivers/gpio/gpio-*wm*.c`,
					`drivers/hwmon/wm83??-hwmon.c`,
					`include/linux/mfd/arizona/`,
					`include/linux/wm97xx.h`,
				},
			},
			match: []string{
				`drivers/gpio/gpio-wm831x.c`,
				`drivers/gpio/gpio-abcdwm831x.c`,
				`drivers/hwmon/wm8355-hwmon.c`,
				`include/linux/mfd/arizona/file.c`,
				`include/linux/mfd/arizona/subfolder/file.c`,
				`include/linux/wm97xx.h`,
			},
			noMatch: []string{
				`drivers/gpio/gpio-w831x.c`,
				`drivers/hwmon/wm83556-hwmon.c`,
				`drivers/hwmon/wm831-hwmon.c`,
				`include/linux/mfd`,
				`include`,
				`random-file`,
			},
		},
		{
			name: `include patterns and regexp`,
			record: maintainersRecord{
				includePatterns: []string{`drivers/rtc/rtc-opal.c`},
				regexps:         []string{`[^a-z0-9]ps3`},
			},
			match: []string{
				`drivers/rtc/rtc-opal.c`,
				`drivers/ps3/a.c`,
				`drivers/sub/ps3/a.c`,
				`drivers/sub/sub/ps3.c`,
			},
			noMatch: []string{
				`drivers/aps3/a.c`,
				`drivers/abc/aps3.c`,
			},
		},
		{
			name: `exclude patterns`,
			record: maintainersRecord{
				includePatterns: []string{`security/`},
				excludePatterns: []string{`security/selinux/`},
			},
			match: []string{
				`security/apparmor/abcd.c`,
				`security/abcd.c`,
			},
			noMatch: []string{
				`security/selinux/abcd.c`,
			},
		},
		{
			name: `handle / at the end`,
			record: maintainersRecord{
				includePatterns: []string{
					`with-subfolders/`,
					`dir/only-one`,
					`also-with-subfolders/*`,
				},
			},
			match: []string{
				`with-subfolders/a`,
				`with-subfolders/a/b`,
				`dir/only-one`,
				`also-with-subfolders/a.c`,
				`also-with-subfolders/b/a.c`,
			},
			noMatch: []string{
				`dir/only-one/a.c`,
				`dir/only-one/a/b.c`,
			},
		},
		{
			name: `wildcards are well escaped`,
			record: maintainersRecord{
				includePatterns: []string{`drivers/net/ethernet/smsc/smc91x.*`},
			},
			match: []string{
				`drivers/net/ethernet/smsc/smc91x.c`,
				`drivers/net/ethernet/smsc/smc91x.h`,
			},
			noMatch: []string{
				`drivers/net/ethernet/smsc/smc91xAh`,
			},
		},
		{
			name: `match everything`,
			record: maintainersRecord{
				includePatterns: []string{`*`, `*/`},
			},
			match: []string{
				`a`,
				`a/b`,
				`a/b/c`,
			},
		},
	}

	for _, loopTest := range tests {
		test := loopTest
		t.Run(test.name, func(t *testing.T) {
			pm := subsystem.MakePathMatcher([]*subsystem.Subsystem{
				{PathRules: []subsystem.PathRule{test.record.ToPathRule()}},
			})
			for _, path := range test.match {
				if len(pm.Match(path)) != 1 {
					t.Fatalf("did not match %#v", path)
				}
			}
			for _, path := range test.noMatch {
				if len(pm.Match(path)) > 0 {
					t.Fatalf("matched %#v", path)
				}
			}
		})
	}
}

func TestLinuxMaintainers(t *testing.T) {
	result, err := parseLinuxMaintainers(
		strings.NewReader(maintainersSample),
	)
	if err != nil {
		t.Fatal(err)
	}
	targetResult := []*maintainersRecord{
		{
			name: "3C59X NETWORK DRIVER",
			includePatterns: []string{
				"Documentation/networking/device_drivers/ethernet/3com/vortex.rst",
				"drivers/net/ethernet/3com/3c59x.c",
			},
			lists:       []string{"netdev@vger.kernel.org"},
			maintainers: []string{"email1@kernel.org"},
		},
		{
			name: "ABI/API",
			includePatterns: []string{
				"include/linux/syscalls.h",
				"kernel/sys_ni.c",
			},
			excludePatterns: []string{
				"include/uapi/",
				"arch/*/include/uapi/",
			},
			lists: []string{"linux-api@vger.kernel.org"},
		},
		{
			name:            "AD1889 ALSA SOUND DRIVER",
			includePatterns: []string{"sound/pci/ad1889.*"},
			lists:           []string{"linux-parisc@vger.kernel.org"},
		},
		{
			name: "PVRUSB2 VIDEO4LINUX DRIVER",
			includePatterns: []string{
				"Documentation/driver-api/media/drivers/pvrusb2*",
				"drivers/media/usb/pvrusb2/",
			},
			lists: []string{
				"pvrusb2@isely.net",
				"linux-media@vger.kernel.org",
			},
			maintainers: []string{"email2@kernel.org"},
			trees:       []string{"git git://linuxtv.org/media_tree.git"},
		},
		{
			name:            "RISC-V ARCHITECTURE",
			includePatterns: []string{"arch/riscv/"},
			regexps:         []string{"riscv"},
			lists:           []string{"linux-riscv@lists.infradead.org"},
			maintainers: []string{
				"email3@kernel.org",
				"email4@kernel.org",
				"email5@kernel.org",
			},
			trees: []string{"git git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git"},
		},
		{
			name:            "THE REST",
			includePatterns: []string{"*", "*/"},
			lists:           []string{"linux-kernel@vger.kernel.org"},
			maintainers:     []string{"email6@kernel.org"},
			trees:           []string{"git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git"},
		},
	}
	if diff := cmp.Diff(targetResult, result,
		cmp.AllowUnexported(maintainersRecord{})); diff != "" {
		t.Fatal(diff)
	}
}

const maintainersSample = `
List of maintainers and how to submit kernel changes
====================================================

Please try to follow the guidelines below.  This will make things
easier on the maintainers.  Not all of these guidelines matter for every
trivial patch so apply some common sense.

Tips for patch submitters
-------------------------

1.	Always *test* your changes, however small, on at least 4 or
	5 people, preferably many more.

< ... >

8.	Happy hacking.

Descriptions of section entries and preferred order
---------------------------------------------------

	M: *Mail* patches to: FullName <address@domain>
	R: Designated *Reviewer*: FullName <address@domain>
	   These reviewers should be CCed on patches.
< ... >
	K: *Content regex* (perl extended) pattern match in a patch or file.
	   For instance:
	   K: of_get_profile
	      matches patches or files that contain "of_get_profile"
	   K: \b(printk|pr_(info|err))\b
	      matches patches or files that contain one or more of the words
	      printk, pr_info or pr_err
	   One regex pattern per line.  Multiple K: lines acceptable.

Maintainers List
----------------

.. note:: When reading this list, please look for the most precise areas
          first. When adding to this list, please keep the entries in
          alphabetical order.

3C59X NETWORK DRIVER
M:	Name1 Surname <email1@kernel.org>
L:	netdev@vger.kernel.org
S:	Odd Fixes
F:	Documentation/networking/device_drivers/ethernet/3com/vortex.rst
F:	drivers/net/ethernet/3com/3c59x.c

ABI/API
L:	linux-api@vger.kernel.org
F:	include/linux/syscalls.h
F:	kernel/sys_ni.c
X:	include/uapi/
X:	arch/*/include/uapi/

AD1889 ALSA SOUND DRIVER
L:	linux-parisc@vger.kernel.org
S:	Maintained
W:	https://parisc.wiki.kernel.org/index.php/AD1889
F:	sound/pci/ad1889.*

PVRUSB2 VIDEO4LINUX DRIVER
M:	Name2 <email2@kernel.org>
L:	pvrusb2@isely.net	(subscribers-only)
L:	linux-media@vger.kernel.org
S:	Maintained
W:	http://www.isely.net/pvrusb2/
T:	git git://linuxtv.org/media_tree.git
F:	Documentation/driver-api/media/drivers/pvrusb2*
F:	drivers/media/usb/pvrusb2/

RISC-V ARCHITECTURE
M:	Name3 <email3@kernel.org>
M:	Name4 <email4@kernel.org>
M:	Name5 <email5@kernel.org>
L:	linux-riscv@lists.infradead.org
S:	Supported
Q:	https://patchwork.kernel.org/project/linux-riscv/list/
P:	Documentation/riscv/patch-acceptance.rst
T:	git git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux.git
F:	arch/riscv/
N:	riscv
K:	riscv

THE REST
M:	Name6 <email6@kernel.org>
L:	linux-kernel@vger.kernel.org
S:	Buried alive in reporters
T:	git git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
F:	*
F:	*/
`