]>
Commit | Line | Data |
---|---|---|
a367f04e GKH |
1 | #!/usr/bin/perl |
2 | ||
3 | # udev-test | |
4 | # | |
5 | # Provides automated testing of the udev binary. | |
6 | # The whole test is self contained in this file, except the matching sysfs tree. | |
7 | # Simply extend the @tests array, to add a new test variant. | |
8 | # | |
9 | # Every test is driven by its own temporary config file. | |
10 | # This program prepares the environment, creates the config and calls udev. | |
11 | # | |
12 | # udev reads the config, looks at the provided sysfs and | |
13 | # first creates and then removes the device node. | |
14 | # After creation and removal the result is checked against the | |
15 | # expected value and the result is printed. | |
16 | # | |
17 | # happy testing, | |
18 | # Kay Sievers <kay.sievers@vrfy.org>, 2003 | |
b8669191 GKH |
19 | # |
20 | # Modified April 9, 2004 by Leann Ogasawara <ogasawara@osdl.org> | |
21 | # - expanded @tests array to add more symlinks and permissions tests | |
22 | # - some of the symlinks tests also test lack of node creation | |
23 | # - added symlink_test() function | |
24 | # - moved permissions and major_minor tests into their own functions | |
a367f04e GKH |
25 | |
26 | use warnings; | |
27 | use strict; | |
28 | ||
f8f00338 | 29 | my $PWD = $ENV{PWD}; |
a367f04e GKH |
30 | my $sysfs = "sys/"; |
31 | my $udev_bin = "../udev"; | |
32 | my $udev_root = "udev-root/"; # !!! directory will be removed !!! | |
2b41e68a | 33 | my $udev_db = ".udevdb"; |
72ffa78d GKH |
34 | my $main_conf = "udev-test.conf"; |
35 | my $conf_tmp = "udev-test.rules"; | |
a367f04e | 36 | |
18ebc430 GKH |
37 | # uncomment following line to run udev with valgrind. |
38 | # Should make this a runtime option to the script someday... | |
39 | #my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev"; | |
a367f04e GKH |
40 | |
41 | my @tests = ( | |
42 | { | |
fa19f181 KS |
43 | desc => "label test of scsi disc", |
44 | subsys => "block", | |
f61d732a | 45 | devpath => "/block/sda", |
c013b034 | 46 | exp_name => "boot_disk" , |
fa19f181 | 47 | conf => <<EOF |
16378373 | 48 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
ac28b86d | 49 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
50 | EOF |
51 | }, | |
52 | { | |
fa19f181 KS |
53 | desc => "label test of scsi partition", |
54 | subsys => "block", | |
f61d732a | 55 | devpath => "/block/sda/sda1", |
c013b034 | 56 | exp_name => "boot_disk1" , |
fa19f181 | 57 | conf => <<EOF |
16378373 | 58 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n" |
83be97ba KS |
59 | EOF |
60 | }, | |
61 | { | |
fa19f181 KS |
62 | desc => "label test of pattern match", |
63 | subsys => "block", | |
f61d732a | 64 | devpath => "/block/sda/sda1", |
c013b034 | 65 | exp_name => "boot_disk1" , |
fa19f181 | 66 | conf => <<EOF |
16378373 KS |
67 | BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1" |
68 | BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2" | |
69 | BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n" | |
70 | BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3" | |
358c8c20 GKH |
71 | EOF |
72 | }, | |
73 | { | |
fa19f181 KS |
74 | desc => "label test of multiple sysfs files", |
75 | subsys => "block", | |
f61d732a | 76 | devpath => "/block/sda/sda1", |
fa19f181 KS |
77 | exp_name => "boot_disk1" , |
78 | conf => <<EOF | |
16378373 KS |
79 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_diskX%n" |
80 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_disk%n" | |
358c8c20 GKH |
81 | EOF |
82 | }, | |
83 | { | |
fa19f181 KS |
84 | desc => "label test of max sysfs files", |
85 | subsys => "block", | |
f61d732a | 86 | devpath => "/block/sda/sda1", |
fa19f181 KS |
87 | exp_name => "boot_disk1" , |
88 | conf => <<EOF | |
16378373 KS |
89 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="2", SYSFS{queue_depth}="32", NAME="boot_diskXX%n" |
90 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="0", NAME="boot_disk%n" | |
0db6d4cc KS |
91 | EOF |
92 | }, | |
93 | { | |
fa19f181 KS |
94 | desc => "catch device by *", |
95 | subsys => "tty", | |
f61d732a | 96 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
97 | exp_name => "visor/0" , |
98 | conf => <<EOF | |
ac28b86d | 99 | KERNEL="ttyUSB*", NAME="visor/%n" |
2e317184 GKH |
100 | EOF |
101 | }, | |
102 | { | |
fa19f181 KS |
103 | desc => "catch device by * - take 2", |
104 | subsys => "tty", | |
f61d732a | 105 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
106 | exp_name => "visor/0" , |
107 | conf => <<EOF | |
2e317184 GKH |
108 | KERNEL="*USB1", NAME="bad" |
109 | KERNEL="*USB0", NAME="visor/%n" | |
9f1da361 KS |
110 | EOF |
111 | }, | |
112 | { | |
fa19f181 KS |
113 | desc => "catch device by ?", |
114 | subsys => "tty", | |
f61d732a | 115 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
116 | exp_name => "visor/0" , |
117 | conf => <<EOF | |
ac28b86d KS |
118 | KERNEL="ttyUSB??*", NAME="visor/%n-1" |
119 | KERNEL="ttyUSB??", NAME="visor/%n-2" | |
120 | KERNEL="ttyUSB?", NAME="visor/%n" | |
9f1da361 KS |
121 | EOF |
122 | }, | |
123 | { | |
fa19f181 KS |
124 | desc => "catch device by character class", |
125 | subsys => "tty", | |
f61d732a | 126 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
127 | exp_name => "visor/0" , |
128 | conf => <<EOF | |
ac28b86d KS |
129 | KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1" |
130 | KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2" | |
131 | KERNEL="ttyUSB[0-9]*", NAME="visor/%n" | |
a367f04e GKH |
132 | EOF |
133 | }, | |
134 | { | |
fa19f181 KS |
135 | desc => "replace kernel name", |
136 | subsys => "tty", | |
f61d732a | 137 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
138 | exp_name => "visor" , |
139 | conf => <<EOF | |
ac28b86d | 140 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
141 | EOF |
142 | }, | |
143 | { | |
fa19f181 KS |
144 | desc => "Handle comment lines in config file (and replace kernel name)", |
145 | subsys => "tty", | |
f61d732a | 146 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
147 | exp_name => "visor" , |
148 | conf => <<EOF | |
281ff00a | 149 | # this is a comment |
ac28b86d | 150 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a GKH |
151 | |
152 | EOF | |
153 | }, | |
154 | { | |
fa19f181 KS |
155 | desc => "Handle comment lines in config file with whitespace (and replace kernel name)", |
156 | subsys => "tty", | |
f61d732a | 157 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
158 | exp_name => "visor" , |
159 | conf => <<EOF | |
281ff00a | 160 | # this is a comment with whitespace before the comment |
ac28b86d | 161 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a | 162 | |
3db7fa27 KS |
163 | EOF |
164 | }, | |
165 | { | |
166 | desc => "Handle whitespace only lines (and replace kernel name)", | |
167 | subsys => "tty", | |
168 | devpath => "/class/tty/ttyUSB0", | |
169 | exp_name => "whitespace" , | |
170 | conf => <<EOF | |
171 | ||
172 | ||
173 | ||
174 | # this is a comment with whitespace before the comment | |
175 | KERNEL="ttyUSB0", NAME="whitespace" | |
176 | ||
177 | ||
178 | ||
281ff00a GKH |
179 | EOF |
180 | }, | |
181 | { | |
fa19f181 KS |
182 | desc => "Handle empty lines in config file (and replace kernel name)", |
183 | subsys => "tty", | |
f61d732a | 184 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
185 | exp_name => "visor" , |
186 | conf => <<EOF | |
281ff00a | 187 | |
ac28b86d | 188 | KERNEL="ttyUSB0", NAME="visor" |
281ff00a | 189 | |
9f8dfa19 KS |
190 | EOF |
191 | }, | |
192 | { | |
193 | desc => "Handle backslashed multi lines in config file (and replace kernel name)", | |
194 | subsys => "tty", | |
195 | devpath => "/class/tty/ttyUSB0", | |
196 | exp_name => "visor" , | |
197 | conf => <<EOF | |
198 | KERNEL="ttyUSB0", \\ | |
199 | NAME="visor" | |
200 | ||
201 | EOF | |
202 | }, | |
203 | { | |
204 | desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)", | |
205 | subsys => "tty", | |
206 | devpath => "/class/tty/ttyUSB0", | |
207 | exp_name => "visor" , | |
208 | conf => <<EOF | |
209 | ||
210 | # | |
211 | \\ | |
212 | ||
213 | \\\\ | |
214 | ||
215 | #\\ | |
216 | ||
217 | KERNEL="ttyUSB0", \\ | |
87da5b2c | 218 | NAME="visor" |
9f8dfa19 | 219 | |
5499d319 KS |
220 | EOF |
221 | }, | |
222 | { | |
fa19f181 KS |
223 | desc => "subdirectory handling", |
224 | subsys => "tty", | |
f61d732a | 225 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
226 | exp_name => "sub/direct/ory/visor" , |
227 | conf => <<EOF | |
ac28b86d | 228 | KERNEL="ttyUSB0", NAME="sub/direct/ory/visor" |
a367f04e GKH |
229 | EOF |
230 | }, | |
231 | { | |
fa19f181 KS |
232 | desc => "place on bus of scsi partition", |
233 | subsys => "block", | |
f61d732a | 234 | devpath => "/block/sda/sda3", |
fa19f181 KS |
235 | exp_name => "first_disk3" , |
236 | conf => <<EOF | |
ac28b86d | 237 | BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n" |
a367f04e GKH |
238 | EOF |
239 | }, | |
240 | { | |
fa19f181 KS |
241 | desc => "test NAME substitution chars", |
242 | subsys => "block", | |
f61d732a | 243 | devpath => "/block/sda/sda3", |
fa19f181 KS |
244 | exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , |
245 | conf => <<EOF | |
ac28b86d | 246 | BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" |
63ead27c KS |
247 | EOF |
248 | }, | |
249 | { | |
fa19f181 KS |
250 | desc => "test NAME substitution chars (with length limit)", |
251 | subsys => "block", | |
f61d732a | 252 | devpath => "/block/sda/sda3", |
fa19f181 KS |
253 | exp_name => "M8-m3-n3-b0:0-sIBM" , |
254 | conf => <<EOF | |
63ead27c | 255 | BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}" |
59525115 GKH |
256 | EOF |
257 | }, | |
258 | { | |
fa19f181 KS |
259 | desc => "old style SYSFS_ attribute", |
260 | subsys => "block", | |
f61d732a | 261 | devpath => "/block/sda", |
fa19f181 KS |
262 | exp_name => "good" , |
263 | conf => <<EOF | |
59525115 | 264 | BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good" |
a27cd06c KS |
265 | EOF |
266 | }, | |
267 | { | |
fa19f181 KS |
268 | desc => "sustitution of sysfs value (%s{file})", |
269 | subsys => "block", | |
f61d732a | 270 | devpath => "/block/sda", |
fa19f181 KS |
271 | exp_name => "disk-IBM-ESXS-sda" , |
272 | conf => <<EOF | |
16378373 | 273 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k" |
a27cd06c | 274 | KERNEL="ttyUSB0", NAME="visor" |
a367f04e GKH |
275 | EOF |
276 | }, | |
277 | { | |
fa19f181 KS |
278 | desc => "program result substitution", |
279 | subsys => "block", | |
f61d732a | 280 | devpath => "/block/sda/sda3", |
fa19f181 KS |
281 | exp_name => "special-device-3" , |
282 | conf => <<EOF | |
ac28b86d KS |
283 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n" |
284 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n" | |
285 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n" | |
286 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n" | |
287 | BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n" | |
f608f8ac KS |
288 | EOF |
289 | }, | |
290 | { | |
291 | desc => "program result substitution (no argument should be subsystem)", | |
292 | subsys => "block", | |
293 | devpath => "/block/sda/sda3", | |
294 | exp_name => "subsys_block" , | |
295 | conf => <<EOF | |
296 | BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block" | |
bbbe503e KS |
297 | EOF |
298 | }, | |
299 | { | |
300 | desc => "program result substitution (newline removal)", | |
301 | subsys => "block", | |
302 | devpath => "/block/sda/sda3", | |
303 | exp_name => "newline_removed" , | |
304 | conf => <<EOF | |
305 | BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed" | |
f3b04a2e GKH |
306 | EOF |
307 | }, | |
308 | { | |
fa19f181 KS |
309 | desc => "program result substitution", |
310 | subsys => "block", | |
f61d732a | 311 | devpath => "/block/sda/sda3", |
fa19f181 KS |
312 | exp_name => "test-0:0:0:0" , |
313 | conf => <<EOF | |
ac28b86d | 314 | BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c" |
8ffb636f KS |
315 | EOF |
316 | }, | |
317 | { | |
fa19f181 KS |
318 | desc => "program with escaped format char (tricky: callout returns format char!)", |
319 | subsys => "block", | |
f61d732a | 320 | devpath => "/block/sda/sda3", |
fa19f181 KS |
321 | exp_name => "escape-3" , |
322 | conf => <<EOF | |
8ffb636f | 323 | BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c" |
dde05ccb GKH |
324 | EOF |
325 | }, | |
326 | { | |
fa19f181 KS |
327 | desc => "program with lots of arguments", |
328 | subsys => "block", | |
f61d732a | 329 | devpath => "/block/sda/sda3", |
fa19f181 KS |
330 | exp_name => "foo9" , |
331 | conf => <<EOF | |
dde05ccb | 332 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}" |
35b38379 KS |
333 | EOF |
334 | }, | |
335 | { | |
fa19f181 KS |
336 | desc => "program with subshell", |
337 | subsys => "block", | |
f61d732a | 338 | devpath => "/block/sda/sda3", |
fa19f181 KS |
339 | exp_name => "bar9" , |
340 | conf => <<EOF | |
35b38379 KS |
341 | BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}" |
342 | EOF | |
343 | }, | |
344 | { | |
fa19f181 KS |
345 | desc => "program arguments combined with apostrophes", |
346 | subsys => "block", | |
f61d732a | 347 | devpath => "/block/sda/sda3", |
fa19f181 KS |
348 | exp_name => "foo7" , |
349 | conf => <<EOF | |
35b38379 | 350 | BUS="scsi", PROGRAM="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL="sda3", NAME="%c{5}" |
56c963dc PM |
351 | EOF |
352 | }, | |
353 | { | |
fa19f181 KS |
354 | desc => "characters before the %c{N} substitution", |
355 | subsys => "block", | |
f61d732a | 356 | devpath => "/block/sda/sda3", |
fa19f181 KS |
357 | exp_name => "my-foo9" , |
358 | conf => <<EOF | |
56c963dc PM |
359 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}" |
360 | EOF | |
361 | }, | |
362 | { | |
fa19f181 KS |
363 | desc => "substitute the second to last argument", |
364 | subsys => "block", | |
f61d732a | 365 | devpath => "/block/sda/sda3", |
fa19f181 KS |
366 | exp_name => "my-foo8" , |
367 | conf => <<EOF | |
56c963dc | 368 | BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}" |
8ff8bbba GKH |
369 | EOF |
370 | }, | |
371 | { | |
fa19f181 KS |
372 | desc => "invalid program for device with no bus", |
373 | subsys => "tty", | |
f61d732a | 374 | devpath => "/class/tty/console", |
fa19f181 KS |
375 | exp_name => "TTY" , |
376 | conf => <<EOF | |
ac28b86d KS |
377 | BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
378 | KERNEL="console", NAME="TTY" | |
1d936fbc GKH |
379 | EOF |
380 | }, | |
381 | { | |
fa19f181 KS |
382 | desc => "valid program for device with no bus", |
383 | subsys => "tty", | |
f61d732a | 384 | devpath => "/class/tty/console", |
fa19f181 KS |
385 | exp_name => "foo" , |
386 | conf => <<EOF | |
ac28b86d KS |
387 | PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo" |
388 | KERNEL="console", NAME="TTY" | |
64682333 GKH |
389 | EOF |
390 | }, | |
391 | { | |
fa19f181 KS |
392 | desc => "invalid label for device with no bus", |
393 | subsys => "tty", | |
f61d732a | 394 | devpath => "/class/tty/console", |
fa19f181 KS |
395 | exp_name => "TTY" , |
396 | conf => <<EOF | |
16378373 | 397 | BUS="foo", SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 398 | KERNEL="console", NAME="TTY" |
64682333 GKH |
399 | EOF |
400 | }, | |
401 | { | |
fa19f181 KS |
402 | desc => "valid label for device with no bus", |
403 | subsys => "tty", | |
f61d732a | 404 | devpath => "/class/tty/console", |
fa19f181 KS |
405 | exp_name => "foo" , |
406 | conf => <<EOF | |
16378373 | 407 | SYSFS{dev}="5:1", NAME="foo" |
ac28b86d | 408 | KERNEL="console", NAME="TTY" |
772558f4 GKH |
409 | EOF |
410 | }, | |
411 | { | |
fa19f181 KS |
412 | desc => "program and bus type match", |
413 | subsys => "block", | |
f61d732a | 414 | devpath => "/block/sda", |
fa19f181 KS |
415 | exp_name => "scsi-0:0:0:0" , |
416 | conf => <<EOF | |
ac28b86d KS |
417 | BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c" |
418 | BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c" | |
419 | BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c" | |
724257d9 GKH |
420 | EOF |
421 | }, | |
422 | { | |
fa19f181 KS |
423 | desc => "create all possible partitions", |
424 | subsys => "block", | |
f61d732a | 425 | devpath => "/block/sda", |
fa19f181 KS |
426 | exp_name => "boot_disk15" , |
427 | conf => <<EOF | |
16378373 | 428 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk" |
50e5de03 KS |
429 | EOF |
430 | }, | |
431 | { | |
fa19f181 KS |
432 | desc => "sysfs parent hierarchy", |
433 | subsys => "tty", | |
f61d732a | 434 | devpath => "/class/tty/ttyUSB0", |
fa19f181 KS |
435 | exp_name => "visor" , |
436 | conf => <<EOF | |
16378373 | 437 | SYSFS{idProduct}="2008", NAME="visor" |
f0142622 GKH |
438 | EOF |
439 | }, | |
440 | { | |
fa19f181 KS |
441 | desc => "name test with ! in the name", |
442 | subsys => "block", | |
f61d732a | 443 | devpath => "/block/rd!c0d0", |
fa19f181 KS |
444 | exp_name => "rd/c0d0" , |
445 | conf => <<EOF | |
f0142622 GKH |
446 | BUS="scsi", NAME="%k" |
447 | KERNEL="ttyUSB0", NAME="visor" | |
b9fc973b GKH |
448 | EOF |
449 | }, | |
450 | { | |
fa19f181 KS |
451 | desc => "name test with ! in the name, but no matching rule", |
452 | subsys => "block", | |
f61d732a | 453 | devpath => "/block/rd!c0d0", |
fa19f181 KS |
454 | exp_name => "rd/c0d0" , |
455 | conf => <<EOF | |
b9fc973b | 456 | KERNEL="ttyUSB0", NAME="visor" |
0f36e68e GKH |
457 | EOF |
458 | }, | |
459 | { | |
460 | desc => "name test with ! in the name for a partition", | |
461 | subsys => "block", | |
462 | devpath => "/block/cciss!c0d0/cciss!c0d0p1", | |
463 | exp_name => "cciss/c0d0p1" , | |
464 | conf => <<EOF | |
465 | BUS="scsi", NAME="%k" | |
466 | KERNEL="ttyUSB0", NAME="visor" | |
93656247 PM |
467 | EOF |
468 | }, | |
469 | { | |
fa19f181 KS |
470 | desc => "ID rule", |
471 | subsys => "block", | |
f61d732a | 472 | devpath => "/block/sda", |
fa19f181 KS |
473 | exp_name => "scsi-0:0:0:0", |
474 | conf => <<EOF | |
93656247 PM |
475 | BUS="usb", ID="0:0:0:0", NAME="not-scsi" |
476 | BUS="scsi", ID="0:0:0:1", NAME="no-match" | |
477 | BUS="scsi", ID=":0", NAME="short-id" | |
478 | BUS="scsi", ID="/0:0:0:0", NAME="no-match" | |
479 | BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0" | |
480 | EOF | |
481 | }, | |
482 | { | |
fa19f181 KS |
483 | desc => "ID wildcard all", |
484 | subsys => "block", | |
f61d732a | 485 | devpath => "/block/sda", |
fa19f181 KS |
486 | exp_name => "scsi-0:0:0:0", |
487 | conf => <<EOF | |
93656247 PM |
488 | BUS="scsi", ID="*:1", NAME="no-match" |
489 | BUS="scsi", ID="*:0:1", NAME="no-match" | |
490 | BUS="scsi", ID="*:0:0:1", NAME="no-match" | |
491 | BUS="scsi", ID="*", NAME="scsi-0:0:0:0" | |
492 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
493 | EOF | |
494 | }, | |
495 | { | |
fa19f181 KS |
496 | desc => "ID wildcard partial", |
497 | subsys => "block", | |
f61d732a | 498 | devpath => "/block/sda", |
fa19f181 KS |
499 | exp_name => "scsi-0:0:0:0", |
500 | conf => <<EOF | |
93656247 PM |
501 | BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0" |
502 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
503 | EOF | |
504 | }, | |
505 | { | |
fa19f181 KS |
506 | desc => "ID wildcard partial 2", |
507 | subsys => "block", | |
f61d732a | 508 | devpath => "/block/sda", |
fa19f181 KS |
509 | exp_name => "scsi-0:0:0:0", |
510 | conf => <<EOF | |
93656247 PM |
511 | BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0" |
512 | BUS="scsi", ID="0:0:0:0", NAME="bad" | |
d5f91372 KS |
513 | EOF |
514 | }, | |
515 | { | |
fa19f181 KS |
516 | desc => "ignore SYSFS attribute whitespace", |
517 | subsys => "block", | |
f61d732a | 518 | devpath => "/block/sda", |
fa19f181 KS |
519 | exp_name => "ignored", |
520 | conf => <<EOF | |
d5f91372 KS |
521 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored" |
522 | EOF | |
523 | }, | |
524 | { | |
fa19f181 KS |
525 | desc => "do not ignore SYSFS attribute whitespace", |
526 | subsys => "block", | |
f61d732a | 527 | devpath => "/block/sda", |
fa19f181 KS |
528 | exp_name => "matched-with-space", |
529 | conf => <<EOF | |
d5f91372 KS |
530 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore" |
531 | BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space" | |
0a5417a0 KS |
532 | EOF |
533 | }, | |
534 | { | |
8b36cc0f | 535 | desc => "permissions USER=bad GROUP=name", |
b8669191 GKH |
536 | subsys => "tty", |
537 | devpath => "/class/tty/tty33", | |
538 | exp_name => "tty33", | |
4ae6d03f | 539 | exp_perms => "0:0:0660", |
b8669191 | 540 | conf => <<EOF |
8b36cc0f | 541 | KERNEL="tty33", NAME="tty33", OWNER="bad", GROUP="name" |
b8669191 GKH |
542 | EOF |
543 | }, | |
544 | { | |
8b36cc0f | 545 | desc => "permissions OWNER=5000", |
fa19f181 | 546 | subsys => "block", |
f61d732a | 547 | devpath => "/block/sda", |
fa19f181 | 548 | exp_name => "node", |
4ae6d03f | 549 | exp_perms => "5000::0660", |
fa19f181 | 550 | conf => <<EOF |
b8669191 GKH |
551 | BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000" |
552 | EOF | |
553 | }, | |
554 | { | |
8b36cc0f | 555 | desc => "permissions GROUP=100", |
b8669191 GKH |
556 | subsys => "block", |
557 | devpath => "/block/sda", | |
558 | exp_name => "node", | |
4ae6d03f | 559 | exp_perms => ":100:0660", |
b8669191 GKH |
560 | conf => <<EOF |
561 | BUS="scsi", KERNEL="sda", NAME="node", GROUP="100" | |
562 | EOF | |
563 | }, | |
564 | { | |
8b36cc0f | 565 | desc => "permissions MODE=0777", |
b8669191 GKH |
566 | subsys => "block", |
567 | devpath => "/block/sda", | |
568 | exp_name => "node", | |
569 | exp_perms => "::0777", | |
570 | conf => <<EOF | |
571 | BUS="scsi", KERNEL="sda", NAME="node", MODE="0777" | |
572 | EOF | |
573 | }, | |
574 | { | |
8b36cc0f | 575 | desc => "permissions OWNER=5000 GROUP=100 MODE=0777", |
b8669191 GKH |
576 | subsys => "block", |
577 | devpath => "/block/sda", | |
578 | exp_name => "node", | |
579 | exp_perms => "5000:100:0777", | |
580 | conf => <<EOF | |
581 | BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777" | |
582 | EOF | |
583 | }, | |
584 | { | |
8b36cc0f | 585 | desc => "permissions OWNER to 5000", |
b8669191 GKH |
586 | subsys => "tty", |
587 | devpath => "/class/tty/ttyUSB0", | |
588 | exp_name => "ttyUSB0", | |
8b36cc0f | 589 | exp_perms => "5000::", |
b8669191 GKH |
590 | conf => <<EOF |
591 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000" | |
592 | EOF | |
593 | }, | |
594 | { | |
8b36cc0f | 595 | desc => "permissions GROUP to 100", |
b8669191 GKH |
596 | subsys => "tty", |
597 | devpath => "/class/tty/ttyUSB0", | |
598 | exp_name => "ttyUSB0", | |
4ae6d03f | 599 | exp_perms => ":100:0660", |
b8669191 GKH |
600 | conf => <<EOF |
601 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100" | |
602 | EOF | |
603 | }, | |
604 | { | |
8b36cc0f | 605 | desc => "permissions MODE to 0060", |
b8669191 GKH |
606 | subsys => "tty", |
607 | devpath => "/class/tty/ttyUSB0", | |
608 | exp_name => "ttyUSB0", | |
8b36cc0f | 609 | exp_perms => "::0060", |
b8669191 GKH |
610 | conf => <<EOF |
611 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060" | |
612 | EOF | |
613 | }, | |
614 | { | |
8b36cc0f | 615 | desc => "permissions OWNER, GROUP, MODE", |
b8669191 GKH |
616 | subsys => "tty", |
617 | devpath => "/class/tty/ttyUSB0", | |
618 | exp_name => "ttyUSB0", | |
619 | exp_perms => "5000:100:0777", | |
620 | conf => <<EOF | |
621 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777" | |
e9390146 KS |
622 | EOF |
623 | }, | |
624 | { | |
625 | desc => "permissions only rule", | |
626 | subsys => "tty", | |
627 | devpath => "/class/tty/ttyUSB0", | |
628 | exp_name => "ttyUSB0", | |
629 | exp_perms => "5000:100:0777", | |
630 | conf => <<EOF | |
631 | KERNEL="ttyUSB[0-9]*", OWNER="5000", GROUP="100", MODE="0777" | |
632 | KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
633 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
eb870090 KS |
634 | EOF |
635 | }, | |
636 | { | |
637 | desc => "multiple permissions only rule", | |
638 | subsys => "tty", | |
639 | devpath => "/class/tty/ttyUSB0", | |
640 | exp_name => "ttyUSB0", | |
641 | exp_perms => "3000:4000:0777", | |
642 | conf => <<EOF | |
643 | SUBSYSTEM="tty", OWNER="3000" | |
644 | SUBSYSTEM="tty", GROUP="4000" | |
645 | SUBSYSTEM="tty", MODE="0777" | |
646 | KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
647 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
648 | EOF | |
649 | }, | |
650 | { | |
651 | desc => "permissions only rule with override at NAME rule", | |
652 | subsys => "tty", | |
653 | devpath => "/class/tty/ttyUSB0", | |
654 | exp_name => "ttyUSB0", | |
655 | exp_perms => "3000:8000:0777", | |
656 | conf => <<EOF | |
657 | SUBSYSTEM="tty", OWNER="3000" | |
658 | SUBSYSTEM="tty", GROUP="4000" | |
659 | SUBSYSTEM="tty", MODE="0777" | |
660 | KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
661 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="8000" | |
fa19f181 KS |
662 | EOF |
663 | }, | |
664 | { | |
665 | desc => "major/minor number test", | |
666 | subsys => "block", | |
f61d732a | 667 | devpath => "/block/sda", |
fa19f181 | 668 | exp_name => "node", |
fa19f181 KS |
669 | exp_majorminor => "8:0", |
670 | conf => <<EOF | |
7ddb6f47 | 671 | BUS="scsi", KERNEL="sda", NAME="node" |
a5e8d2b4 GKH |
672 | EOF |
673 | }, | |
674 | { | |
675 | desc => "big minor number test", | |
676 | subsys => "i2c-dev", | |
f61d732a | 677 | devpath => "/class/i2c-dev/i2c-300", |
a5e8d2b4 GKH |
678 | exp_name => "node", |
679 | exp_majorminor => "89:300", | |
680 | conf => <<EOF | |
681 | KERNEL="i2c-300", NAME="node" | |
7d12d4e1 GKH |
682 | EOF |
683 | }, | |
684 | { | |
685 | desc => "big major number test", | |
686 | subsys => "i2c-dev", | |
f61d732a | 687 | devpath => "/class/i2c-dev/i2c-fake1", |
7d12d4e1 GKH |
688 | exp_name => "node", |
689 | exp_majorminor => "4095:1", | |
690 | conf => <<EOF | |
691 | KERNEL="i2c-fake1", NAME="node" | |
692 | EOF | |
693 | }, | |
694 | { | |
695 | desc => "big major and big minor number test", | |
696 | subsys => "i2c-dev", | |
f61d732a | 697 | devpath => "/class/i2c-dev/i2c-fake2", |
7d12d4e1 GKH |
698 | exp_name => "node", |
699 | exp_majorminor => "4094:89999", | |
700 | conf => <<EOF | |
701 | KERNEL="i2c-fake2", NAME="node" | |
2b0f835c KS |
702 | EOF |
703 | }, | |
704 | { | |
705 | desc => "multiple symlinks with format char", | |
706 | subsys => "tty", | |
707 | devpath => "/class/tty/ttyUSB0", | |
708 | exp_name => "symlink2-ttyUSB0", | |
709 | exp_target => "ttyUSB0", | |
710 | conf => <<EOF | |
711 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b" | |
b8669191 GKH |
712 | EOF |
713 | }, | |
714 | { | |
715 | desc => "symlink creation (same directory)", | |
716 | subsys => "tty", | |
717 | devpath => "/class/tty/ttyUSB0", | |
718 | exp_name => "visor0", | |
719 | exp_target => "ttyUSB0", | |
720 | conf => <<EOF | |
721 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n" | |
722 | EOF | |
723 | }, | |
724 | { | |
725 | desc => "symlink creation (relative link forward)", | |
726 | subsys => "block", | |
727 | devpath => "/block/sda/sda2", | |
728 | exp_name => "1/2/symlink" , | |
729 | exp_target => "a/b/node", | |
730 | conf => <<EOF | |
731 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink" | |
732 | EOF | |
733 | }, | |
734 | { | |
735 | desc => "symlink creation (relative link back and forward)", | |
736 | subsys => "block", | |
737 | devpath => "/block/sda/sda2", | |
738 | exp_name => "1/2/c/d/symlink" , | |
739 | exp_target => "../../a/b/node", | |
740 | conf => <<EOF | |
741 | BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink" | |
742 | EOF | |
743 | }, | |
744 | { | |
745 | desc => "multiple symlinks", | |
746 | subsys => "tty", | |
747 | devpath => "/class/tty/ttyUSB0", | |
748 | exp_name => "second-0" , | |
749 | exp_target => "visor" , | |
750 | conf => <<EOF | |
751 | KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" | |
752 | EOF | |
753 | }, | |
754 | { | |
755 | desc => "symlink only rule", | |
756 | subsys => "block", | |
757 | devpath => "/block/sda", | |
758 | exp_name => "symlink-only2", | |
759 | exp_target => "link", | |
760 | conf => <<EOF | |
761 | BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1" | |
762 | BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2" | |
763 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0" | |
764 | EOF | |
765 | }, | |
766 | { | |
767 | desc => "symlink name empty", | |
768 | subsys => "block", | |
769 | devpath => "/block/sda", | |
770 | exp_name => "", | |
771 | exp_target => "link", | |
772 | exp_error => "yes", | |
773 | conf => <<EOF | |
774 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="" | |
775 | EOF | |
776 | }, | |
777 | { | |
778 | desc => "symlink name '.'", | |
779 | subsys => "block", | |
780 | devpath => "/block/sda", | |
781 | exp_name => ".", | |
782 | exp_target => "link", | |
783 | exp_error => "yes", | |
784 | conf => <<EOF | |
785 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="." | |
786 | EOF | |
787 | }, | |
788 | { | |
789 | desc => "symlink to empty name", | |
790 | subsys => "block", | |
791 | devpath => "/block/sda", | |
792 | exp_name => "symlink", | |
793 | exp_target => "", | |
794 | exp_error => "yes", | |
795 | conf => <<EOF | |
796 | BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink" | |
797 | EOF | |
798 | }, | |
799 | { | |
800 | desc => "symlink and name empty", | |
801 | subsys => "block", | |
802 | devpath => "/block/sda", | |
803 | exp_name => "", | |
804 | exp_target => "", | |
805 | exp_error => "yes", | |
806 | conf => <<EOF | |
807 | BUS="scsi", KERNEL="sda", NAME="", SYMLINK="" | |
808 | EOF | |
809 | }, | |
810 | { | |
811 | desc => "symlink node to itself", | |
812 | subsys => "tty", | |
813 | devpath => "/class/tty/tty0", | |
814 | exp_name => "link", | |
815 | exp_target => "link", | |
816 | conf => <<EOF | |
817 | KERNEL="tty0", NAME="link", SYMLINK="link" | |
818 | EOF | |
819 | }, | |
820 | { | |
821 | desc => "symlink %n substitution", | |
822 | subsys => "tty", | |
823 | devpath => "/class/tty/ttyUSB0", | |
824 | exp_name => "symlink0", | |
825 | exp_target => "ttyUSB0", | |
826 | conf => <<EOF | |
827 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink%n" | |
828 | EOF | |
829 | }, | |
830 | { | |
831 | desc => "symlink %k substitution", | |
832 | subsys => "tty", | |
833 | devpath => "/class/tty/ttyUSB0", | |
834 | exp_name => "symlink-ttyUSB0", | |
835 | exp_target => "ttyUSB0", | |
836 | conf => <<EOF | |
837 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink-%k" | |
838 | EOF | |
839 | }, | |
840 | { | |
841 | desc => "symlink %M:%m substitution", | |
842 | subsys => "tty", | |
843 | devpath => "/class/tty/ttyUSB0", | |
844 | exp_name => "major-188:0", | |
845 | exp_target => "ttyUSB0", | |
846 | conf => <<EOF | |
847 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="major-%M:%m" | |
848 | EOF | |
849 | }, | |
850 | { | |
851 | desc => "symlink %b substitution", | |
852 | subsys => "block", | |
853 | devpath => "/block/sda", | |
854 | exp_name => "symlink-0:0:0:0", | |
855 | exp_target => "node", | |
856 | conf => <<EOF | |
857 | BUS="scsi", KERNEL="sda", NAME="node", SYMLINK="symlink-%b" | |
858 | EOF | |
859 | }, | |
860 | { | |
861 | desc => "symlink %c substitution", | |
862 | subsys => "tty", | |
863 | devpath => "/class/tty/ttyUSB0", | |
864 | exp_name => "test", | |
865 | exp_target => "ttyUSB0", | |
866 | conf => <<EOF | |
867 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo test" NAME="ttyUSB%n", SYMLINK="%c" | |
868 | EOF | |
869 | }, | |
870 | { | |
871 | desc => "symlink %c{N} substitution", | |
872 | subsys => "tty", | |
873 | devpath => "/class/tty/ttyUSB0", | |
874 | exp_name => "test", | |
875 | exp_target => "ttyUSB0", | |
876 | conf => <<EOF | |
877 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2}" | |
878 | EOF | |
879 | }, | |
880 | { | |
881 | desc => "symlink %c{N+} substitution", | |
882 | subsys => "tty", | |
883 | devpath => "/class/tty/ttyUSB0", | |
884 | exp_name => "this", | |
885 | exp_target => "ttyUSB0", | |
886 | conf => <<EOF | |
887 | KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2+}" | |
888 | EOF | |
889 | }, | |
890 | { | |
891 | desc => "symlink only rule with %c{N+}", | |
892 | subsys => "block", | |
893 | devpath => "/block/sda", | |
894 | exp_name => "test", | |
895 | exp_target => "link", | |
896 | conf => <<EOF | |
897 | BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo link test this" SYMLINK="%c{2+}" | |
898 | BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0" | |
899 | EOF | |
900 | }, | |
901 | { | |
902 | desc => "symlink %s{filename} substitution", | |
903 | subsys => "tty", | |
904 | devpath => "/class/tty/ttyUSB0", | |
905 | exp_name => "188:0", | |
906 | exp_target => "ttyUSB0", | |
907 | conf => <<EOF | |
908 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%s{dev}" | |
909 | EOF | |
910 | }, | |
911 | { | |
912 | desc => "symlink %Ns{filename} substitution", | |
913 | subsys => "tty", | |
914 | devpath => "/class/tty/ttyUSB0", | |
915 | exp_name => "188", | |
916 | exp_target => "ttyUSB0", | |
917 | conf => <<EOF | |
918 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%3s{dev}" | |
919 | EOF | |
920 | }, | |
921 | { | |
922 | desc => "symlink with '%' in name", | |
923 | subsys => "tty", | |
924 | devpath => "/class/tty/ttyUSB0", | |
925 | exp_name => "percent%sign", | |
926 | exp_target => "ttyUSB0", | |
927 | conf => <<EOF | |
928 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="percent%%sign" | |
929 | EOF | |
930 | }, | |
931 | { | |
932 | desc => "symlink with '%' in name", | |
933 | subsys => "tty", | |
934 | devpath => "/class/tty/ttyUSB0", | |
935 | exp_name => "%ttyUSB0_name", | |
936 | exp_target => "ttyUSB0", | |
937 | conf => <<EOF | |
938 | KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%%%k_name" | |
939 | EOF | |
940 | }, | |
941 | { | |
942 | desc => "program result substitution (numbered part of)", | |
943 | subsys => "block", | |
944 | devpath => "/block/sda/sda3", | |
945 | exp_name => "link1", | |
946 | exp_target => "node", | |
947 | conf => <<EOF | |
948 | BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}" | |
949 | EOF | |
950 | }, | |
951 | { | |
952 | desc => "program result substitution (numbered part of+)", | |
953 | subsys => "block", | |
954 | devpath => "/block/sda/sda3", | |
955 | exp_name => "link4", | |
956 | exp_target => "node", | |
957 | conf => <<EOF | |
958 | BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}" | |
0345b862 KS |
959 | EOF |
960 | }, | |
961 | { | |
962 | desc => "enumeration char test (single test)", | |
963 | subsys => "block", | |
964 | devpath => "/block/sda", | |
965 | exp_name => "cdrom", | |
966 | conf => <<EOF | |
967 | KERNEL="sda", NAME="cdrom%e" | |
968 | EOF | |
969 | }, | |
970 | { | |
971 | desc => "enumeration char test sequence (1/5 keep)", | |
972 | subsys => "block", | |
973 | devpath => "/block/sda", | |
974 | exp_name => "cdrom", | |
975 | option => "keep", | |
976 | conf => <<EOF | |
977 | KERNEL="sda", NAME="cdrom%e" | |
978 | EOF | |
979 | }, | |
980 | { | |
981 | desc => "enumeration char test sequence 2/5 (keep)", | |
982 | subsys => "block", | |
983 | devpath => "/block/sda/sda1", | |
984 | exp_name => "enum", | |
985 | option => "keep", | |
986 | conf => <<EOF | |
987 | KERNEL="sda1", NAME="enum%e" | |
988 | EOF | |
989 | }, | |
990 | { | |
991 | desc => "enumeration char test sequence 3/5 (keep)", | |
992 | subsys => "block", | |
993 | devpath => "/block/sda/sda2", | |
994 | exp_name => "cdrom1", | |
995 | option => "keep", | |
996 | conf => <<EOF | |
997 | KERNEL="sda2", NAME="cdrom%e" | |
998 | EOF | |
999 | }, | |
1000 | { | |
1001 | desc => "enumeration char test sequence 4/5 (keep)", | |
1002 | subsys => "block", | |
1003 | devpath => "/block/sda/sda3", | |
1004 | exp_name => "enum1", | |
1005 | option => "keep", | |
1006 | conf => <<EOF | |
1007 | KERNEL="sda3", NAME="enum%e" | |
1008 | EOF | |
1009 | }, | |
1010 | { | |
1011 | desc => "enumeration char test sequence 5/5 (clean)", | |
1012 | subsys => "block", | |
1013 | devpath => "/block/sda/sda4", | |
1014 | exp_name => "cdrom2", | |
1015 | option => "clear", | |
1016 | conf => <<EOF | |
1017 | KERNEL="sda4", NAME="cdrom%e" | |
1018 | EOF | |
1019 | }, | |
1020 | { | |
1021 | desc => "enumeration char test after cleanup (single test)", | |
1022 | subsys => "block", | |
1023 | devpath => "/block/sda", | |
1024 | exp_name => "cdrom", | |
1025 | conf => <<EOF | |
1026 | KERNEL="sda", NAME="cdrom%e" | |
6818c51d KS |
1027 | EOF |
1028 | }, | |
1029 | { | |
7efa217d KS |
1030 | desc => "ignore remove event test", |
1031 | subsys => "block", | |
1032 | devpath => "/block/sda", | |
1033 | exp_name => "node", | |
1034 | exp_error => "yes", | |
1035 | conf => <<EOF | |
1036 | BUS="scsi", KERNEL="sda", NAME{ignore_remove}="node" | |
1037 | EOF | |
1038 | }, | |
1039 | { | |
1040 | desc => "ignore remove event test (with all partitions)", | |
1041 | subsys => "block", | |
1042 | devpath => "/block/sda", | |
1043 | exp_name => "node14", | |
1044 | exp_error => "yes", | |
1045 | option => "clear", | |
1046 | conf => <<EOF | |
1047 | BUS="scsi", KERNEL="sda", NAME{ignore_remove, all_partitions}="node" | |
1048 | EOF | |
1049 | }, | |
1050 | { | |
1051 | desc => "SUBSYSTEM match test", | |
6818c51d KS |
1052 | subsys => "block", |
1053 | devpath => "/block/sda", | |
1054 | exp_name => "node", | |
1055 | conf => <<EOF | |
1056 | BUS="scsi", KERNEL="sda", NAME="should_not_match", SUBSYSTEM="vc" | |
1057 | BUS="scsi", KERNEL="sda", NAME="node", SUBSYSTEM="block" | |
1058 | BUS="scsi", KERNEL="sda", NAME="should_not_match2", SUBSYSTEM="vc" | |
2092fbcd KS |
1059 | EOF |
1060 | }, | |
1061 | { | |
7efa217d | 1062 | desc => "DRIVER match test", |
2092fbcd KS |
1063 | subsys => "block", |
1064 | devpath => "/block/sda", | |
1065 | exp_name => "node", | |
1066 | conf => <<EOF | |
1067 | BUS="scsi", KERNEL="sda", NAME="should_not_match", DRIVER="sd-wrong" | |
1068 | BUS="scsi", KERNEL="sda", NAME="node", DRIVER="sd" | |
c1ab0461 KS |
1069 | EOF |
1070 | }, | |
1071 | { | |
1072 | desc => "temporary node creation test", | |
1073 | subsys => "block", | |
1074 | devpath => "/block/sda", | |
1075 | exp_name => "sda", | |
1076 | conf => <<EOF | |
1077 | BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test -b %N" NAME="%N" | |
1078 | EOF | |
1079 | }, | |
1080 | { | |
1081 | desc => "devpath substitution test", | |
1082 | subsys => "block", | |
1083 | devpath => "/block/sda", | |
1084 | exp_name => "sda", | |
1085 | conf => <<EOF | |
1086 | BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo %p", RESULT="/block/sda" NAME="%k" | |
a367f04e GKH |
1087 | EOF |
1088 | }, | |
1089 | ); | |
1090 | ||
1091 | # set env | |
1092 | $ENV{UDEV_TEST} = "yes"; | |
1093 | $ENV{SYSFS_PATH} = $sysfs; | |
72ffa78d | 1094 | $ENV{UDEV_CONFIG_FILE} = $main_conf; |
bbbe503e | 1095 | $ENV{UDEV_NO_DEVD} = "yes"; |
16ac31aa | 1096 | $ENV{UDEV_NO_HOTPLUGD} = "yes"; |
a367f04e GKH |
1097 | |
1098 | ||
1099 | sub udev { | |
1100 | my ($action, $subsys, $devpath, $config) = @_; | |
1101 | ||
1102 | $ENV{DEVPATH} = $devpath; | |
a367f04e GKH |
1103 | |
1104 | # create temporary config | |
1105 | open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp"; | |
1106 | print CONF $$config; | |
1107 | close CONF; | |
1108 | ||
1109 | $ENV{ACTION} = $action; | |
1110 | system("$udev_bin $subsys"); | |
1111 | } | |
1112 | ||
e5fbfe0a | 1113 | my $error = 0; |
72ffa78d | 1114 | |
b8669191 GKH |
1115 | sub permissions_test { |
1116 | my($config, $uid, $gid, $mode) = @_; | |
1117 | ||
1118 | my $wrong = 0; | |
1119 | $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/; | |
1120 | if ($1 ne "") { | |
1121 | if ($uid != $1) { $wrong = 1; }; | |
1122 | } | |
1123 | if ($2 ne "") { | |
1124 | if ($gid != $2) { $wrong = 1; }; | |
1125 | } | |
1126 | if ($3 ne "") { | |
1127 | if (($mode & 07777) != oct($3)) { $wrong = 1; }; | |
1128 | } | |
1129 | if ($wrong == 0) { | |
1130 | print "permissions: ok "; | |
1131 | } else { | |
1132 | printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3); | |
1133 | printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; | |
1134 | $error++; | |
1135 | } | |
1136 | } | |
1137 | ||
1138 | sub major_minor_test { | |
1139 | my($config, $rdev) = @_; | |
1140 | ||
1141 | my $major = ($rdev >> 8) & 0xfff; | |
1142 | my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); | |
1143 | my $wrong = 0; | |
1144 | ||
1145 | $config->{exp_majorminor} =~ m/^(.*):(.*)$/; | |
1146 | if ($1 ne "") { | |
1147 | if ($major != $1) { $wrong = 1; }; | |
1148 | } | |
1149 | if ($2 ne "") { | |
1150 | if ($minor != $2) { $wrong = 1; }; | |
1151 | } | |
1152 | if ($wrong == 0) { | |
1153 | print "major:minor: ok "; | |
1154 | } else { | |
1155 | printf "expected major:minor is: %i:%i\n", $1, $2; | |
1156 | printf "created major:minor is : %i:%i\n", $major, $minor; | |
1157 | print "major:minor: error "; | |
1158 | $error++; | |
1159 | } | |
1160 | } | |
1161 | ||
1162 | sub symlink_test { | |
1163 | my ($config) = @_; | |
1164 | ||
1165 | my $output = `ls -l $PWD/$udev_root$config->{exp_name}`; | |
1166 | ||
1167 | if ($output =~ m/(.*)-> (.*)/) { | |
1168 | if ($2 eq $config->{exp_target}) { | |
1169 | print "symlink: ok "; | |
1170 | } else { | |
1171 | print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; | |
1172 | print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n"; | |
1173 | if ($config->{exp_error}) { | |
1174 | print "as expected "; | |
1175 | } else { | |
1176 | $error++; | |
1177 | } | |
1178 | } | |
1179 | } else { | |
1180 | print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; | |
1181 | print "symlink: not created "; | |
1182 | if ($config->{exp_error}) { | |
1183 | print "as expected "; | |
1184 | } else { | |
1185 | $error++; | |
1186 | } | |
1187 | } | |
1188 | } | |
1189 | ||
2e317184 GKH |
1190 | sub run_test { |
1191 | my ($config, $number) = @_; | |
fa19f181 | 1192 | |
2e317184 | 1193 | print "TEST $number: $config->{desc}\n"; |
b8669191 GKH |
1194 | |
1195 | if ($config->{exp_target}) { | |
1196 | print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n"; | |
1197 | } else { | |
1198 | print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n"; | |
1199 | } | |
1200 | ||
a367f04e GKH |
1201 | |
1202 | udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf}); | |
b8669191 GKH |
1203 | if ((-e "$PWD/$udev_root$config->{exp_name}") || |
1204 | (-l "$PWD/$udev_root$config->{exp_name}")) { | |
fa19f181 KS |
1205 | |
1206 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
1207 | $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}"); | |
1208 | ||
c013b034 | 1209 | if (defined($config->{exp_perms})) { |
b8669191 | 1210 | permissions_test($config, $uid, $gid, $mode); |
c612a0ac | 1211 | } |
fa19f181 | 1212 | if (defined($config->{exp_majorminor})) { |
b8669191 GKH |
1213 | major_minor_test($config, $rdev); |
1214 | } | |
1215 | if (defined($config->{exp_target})) { | |
1216 | symlink_test($config); | |
fa19f181 | 1217 | } |
a367f04e GKH |
1218 | print "add: ok "; |
1219 | } else { | |
b8669191 GKH |
1220 | print "add: error "; |
1221 | if ($config->{exp_error}) { | |
1222 | print "as expected "; | |
1223 | } else { | |
1224 | print "\n\n"; | |
1225 | system("tree $udev_root"); | |
1226 | print "\n"; | |
1227 | $error++; | |
1228 | } | |
a367f04e GKH |
1229 | } |
1230 | ||
0345b862 KS |
1231 | if (defined($config->{option}) && $config->{option} eq "keep") { |
1232 | print "\n\n"; | |
1233 | return; | |
1234 | } | |
1235 | ||
a367f04e | 1236 | udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); |
fa19f181 KS |
1237 | if ((-e "$PWD/$udev_root$config->{exp_name}") || |
1238 | (-l "$PWD/$udev_root$config->{exp_name}")) { | |
b8669191 GKH |
1239 | print "remove: error "; |
1240 | if ($config->{exp_error}) { | |
1241 | print "as expected\n\n"; | |
1242 | } else { | |
1243 | print "\n\n"; | |
1244 | system("tree $udev_root"); | |
1245 | print "\n"; | |
1246 | $error++; | |
1247 | } | |
a367f04e GKH |
1248 | } else { |
1249 | print "remove: ok\n\n"; | |
1250 | } | |
0345b862 KS |
1251 | |
1252 | if (defined($config->{option}) && $config->{option} eq "clear") { | |
2b41e68a | 1253 | system("rm -rf $udev_db"); |
0345b862 KS |
1254 | system("rm -rf $udev_root"); |
1255 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1256 | } | |
1257 | ||
a367f04e GKH |
1258 | } |
1259 | ||
800ab95b GKH |
1260 | # only run if we have root permissions |
1261 | # due to mknod restrictions | |
1262 | if (!($<==0)) { | |
1263 | print "Must have root permissions to run properly.\n"; | |
1264 | exit; | |
1265 | } | |
1266 | ||
2e317184 GKH |
1267 | # prepare |
1268 | system("rm -rf $udev_root"); | |
1269 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1270 | ||
1271 | # create initial config file | |
1272 | open CONF, ">$main_conf" || die "unable to create config file: $main_conf"; | |
1273 | print CONF "udev_root=\"$udev_root\"\n"; | |
1274 | print CONF "udev_db=\"$udev_db\"\n"; | |
1275 | print CONF "udev_rules=\"$conf_tmp\"\n"; | |
2e317184 GKH |
1276 | close CONF; |
1277 | ||
1278 | my $test_num = 1; | |
1279 | ||
1280 | if ($ARGV[0]) { | |
1281 | # only run one test | |
1282 | $test_num = $ARGV[0]; | |
2e317184 | 1283 | |
0345b862 KS |
1284 | if (defined($tests[$test_num-1]->{desc})) { |
1285 | print "udev-test will run test number $test_num only:\n\n"; | |
1286 | run_test($tests[$test_num-1], $test_num); | |
1287 | } else { | |
1288 | print "test does not exist.\n"; | |
1289 | } | |
2e317184 GKH |
1290 | } else { |
1291 | # test all | |
1292 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
1293 | ||
1294 | foreach my $config (@tests) { | |
1295 | run_test($config, $test_num); | |
1296 | $test_num++; | |
2e317184 GKH |
1297 | } |
1298 | } | |
1299 | ||
a367f04e GKH |
1300 | print "$error errors occured\n\n"; |
1301 | ||
1302 | # cleanup | |
2b41e68a | 1303 | system("rm -rf $udev_db"); |
a367f04e GKH |
1304 | system("rm -rf $udev_root"); |
1305 | unlink($conf_tmp); | |
72ffa78d | 1306 | unlink($main_conf); |
a367f04e | 1307 |