]>
Commit | Line | Data |
---|---|---|
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 parses the rules, 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 | # Kay Sievers <kay.sievers@vrfy.org>, 2003 | |
18 | # Leann Ogasawara <ogasawara@osdl.org>, 2004 | |
19 | ||
20 | use warnings; | |
21 | use strict; | |
22 | ||
23 | my $PWD = $ENV{PWD}; | |
24 | my $sysfs = "sys/"; | |
25 | my $udev_bin = "../udev"; | |
26 | my $udev_root = "udev-root/"; # !!! directory will be removed !!! | |
27 | my $udev_db = ".udevdb"; | |
28 | my $udev_conf = "udev-test.conf"; | |
29 | my $udev_rules = "udev-test.rules"; | |
30 | ||
31 | # uncomment following line to run udev with valgrind. | |
32 | # Should make this a runtime option to the script someday... | |
33 | #my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev"; | |
34 | ||
35 | my @tests = ( | |
36 | { | |
37 | desc => "label test of scsi disc", | |
38 | subsys => "block", | |
39 | devpath => "/block/sda", | |
40 | exp_name => "boot_disk" , | |
41 | rules => <<EOF | |
42 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n" | |
43 | KERNEL=="ttyUSB0", NAME="visor" | |
44 | EOF | |
45 | }, | |
46 | { | |
47 | desc => "label test of scsi partition", | |
48 | subsys => "block", | |
49 | devpath => "/block/sda/sda1", | |
50 | exp_name => "boot_disk1" , | |
51 | rules => <<EOF | |
52 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n" | |
53 | EOF | |
54 | }, | |
55 | { | |
56 | desc => "label test of pattern match", | |
57 | subsys => "block", | |
58 | devpath => "/block/sda/sda1", | |
59 | exp_name => "boot_disk1" , | |
60 | rules => <<EOF | |
61 | BUS=="scsi", SYSFS{vendor}=="?IBM-ESXS", NAME="boot_disk%n-1" | |
62 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS?", NAME="boot_disk%n-2" | |
63 | BUS=="scsi", SYSFS{vendor}=="IBM-ES??", NAME="boot_disk%n" | |
64 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXSS", NAME="boot_disk%n-3" | |
65 | EOF | |
66 | }, | |
67 | { | |
68 | desc => "label test of multiple sysfs files", | |
69 | subsys => "block", | |
70 | devpath => "/block/sda/sda1", | |
71 | exp_name => "boot_disk1" , | |
72 | rules => <<EOF | |
73 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_diskX%n" | |
74 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_disk%n" | |
75 | EOF | |
76 | }, | |
77 | { | |
78 | desc => "label test of max sysfs files", | |
79 | subsys => "block", | |
80 | devpath => "/block/sda/sda1", | |
81 | exp_name => "boot_disk1" , | |
82 | rules => <<EOF | |
83 | 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" | |
84 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", SYSFS{scsi_level}=="4", SYSFS{rev}=="B245", SYSFS{type}=="0", NAME="boot_disk%n" | |
85 | EOF | |
86 | }, | |
87 | { | |
88 | desc => "catch device by *", | |
89 | subsys => "tty", | |
90 | devpath => "/class/tty/ttyUSB0", | |
91 | exp_name => "visor/0" , | |
92 | rules => <<EOF | |
93 | KERNEL=="ttyUSB*", NAME="visor/%n" | |
94 | EOF | |
95 | }, | |
96 | { | |
97 | desc => "catch device by * - take 2", | |
98 | subsys => "tty", | |
99 | devpath => "/class/tty/ttyUSB0", | |
100 | exp_name => "visor/0" , | |
101 | rules => <<EOF | |
102 | KERNEL=="*USB1", NAME="bad" | |
103 | KERNEL=="*USB0", NAME="visor/%n" | |
104 | EOF | |
105 | }, | |
106 | { | |
107 | desc => "catch device by ?", | |
108 | subsys => "tty", | |
109 | devpath => "/class/tty/ttyUSB0", | |
110 | exp_name => "visor/0" , | |
111 | rules => <<EOF | |
112 | KERNEL=="ttyUSB??*", NAME="visor/%n-1" | |
113 | KERNEL=="ttyUSB??", NAME="visor/%n-2" | |
114 | KERNEL=="ttyUSB?", NAME="visor/%n" | |
115 | EOF | |
116 | }, | |
117 | { | |
118 | desc => "catch device by character class", | |
119 | subsys => "tty", | |
120 | devpath => "/class/tty/ttyUSB0", | |
121 | exp_name => "visor/0" , | |
122 | rules => <<EOF | |
123 | KERNEL=="ttyUSB[A-Z]*", NAME="visor/%n-1" | |
124 | KERNEL=="ttyUSB?[0-9]", NAME="visor/%n-2" | |
125 | KERNEL=="ttyUSB[0-9]*", NAME="visor/%n" | |
126 | EOF | |
127 | }, | |
128 | { | |
129 | desc => "replace kernel name", | |
130 | subsys => "tty", | |
131 | devpath => "/class/tty/ttyUSB0", | |
132 | exp_name => "visor" , | |
133 | rules => <<EOF | |
134 | KERNEL=="ttyUSB0", NAME="visor" | |
135 | EOF | |
136 | }, | |
137 | { | |
138 | desc => "Handle comment lines in config file (and replace kernel name)", | |
139 | subsys => "tty", | |
140 | devpath => "/class/tty/ttyUSB0", | |
141 | exp_name => "visor" , | |
142 | rules => <<EOF | |
143 | # this is a comment | |
144 | KERNEL=="ttyUSB0", NAME="visor" | |
145 | ||
146 | EOF | |
147 | }, | |
148 | { | |
149 | desc => "Handle comment lines in config file with whitespace (and replace kernel name)", | |
150 | subsys => "tty", | |
151 | devpath => "/class/tty/ttyUSB0", | |
152 | exp_name => "visor" , | |
153 | rules => <<EOF | |
154 | # this is a comment with whitespace before the comment | |
155 | KERNEL=="ttyUSB0", NAME="visor" | |
156 | ||
157 | EOF | |
158 | }, | |
159 | { | |
160 | desc => "Handle whitespace only lines (and replace kernel name)", | |
161 | subsys => "tty", | |
162 | devpath => "/class/tty/ttyUSB0", | |
163 | exp_name => "whitespace" , | |
164 | rules => <<EOF | |
165 | ||
166 | ||
167 | ||
168 | # this is a comment with whitespace before the comment | |
169 | KERNEL=="ttyUSB0", NAME="whitespace" | |
170 | ||
171 | ||
172 | ||
173 | EOF | |
174 | }, | |
175 | { | |
176 | desc => "Handle empty lines in config file (and replace kernel name)", | |
177 | subsys => "tty", | |
178 | devpath => "/class/tty/ttyUSB0", | |
179 | exp_name => "visor" , | |
180 | rules => <<EOF | |
181 | ||
182 | KERNEL=="ttyUSB0", NAME="visor" | |
183 | ||
184 | EOF | |
185 | }, | |
186 | { | |
187 | desc => "Handle backslashed multi lines in config file (and replace kernel name)", | |
188 | subsys => "tty", | |
189 | devpath => "/class/tty/ttyUSB0", | |
190 | exp_name => "visor" , | |
191 | rules => <<EOF | |
192 | KERNEL=="ttyUSB0", \\ | |
193 | NAME="visor" | |
194 | ||
195 | EOF | |
196 | }, | |
197 | { | |
198 | desc => "preserve backslashes, if they are not for a newline", | |
199 | subsys => "tty", | |
200 | devpath => "/class/tty/ttyUSB0", | |
201 | exp_name => "aaa", | |
202 | rules => <<EOF | |
203 | KERNEL=="ttyUSB0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", NAME="aaa" | |
204 | EOF | |
205 | }, | |
206 | { | |
207 | desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)", | |
208 | subsys => "tty", | |
209 | devpath => "/class/tty/ttyUSB0", | |
210 | exp_name => "visor" , | |
211 | rules => <<EOF | |
212 | ||
213 | # | |
214 | \\ | |
215 | ||
216 | \\\\ | |
217 | ||
218 | #\\ | |
219 | ||
220 | KERNEL=="ttyUSB0", \\ | |
221 | NAME="visor" | |
222 | ||
223 | EOF | |
224 | }, | |
225 | { | |
226 | desc => "subdirectory handling", | |
227 | subsys => "tty", | |
228 | devpath => "/class/tty/ttyUSB0", | |
229 | exp_name => "sub/direct/ory/visor" , | |
230 | rules => <<EOF | |
231 | KERNEL=="ttyUSB0", NAME="sub/direct/ory/visor" | |
232 | EOF | |
233 | }, | |
234 | { | |
235 | desc => "place on bus of scsi partition", | |
236 | subsys => "block", | |
237 | devpath => "/block/sda/sda3", | |
238 | exp_name => "first_disk3" , | |
239 | rules => <<EOF | |
240 | BUS=="scsi", ID=="0:0:0:0", NAME="first_disk%n" | |
241 | EOF | |
242 | }, | |
243 | { | |
244 | desc => "test substitution chars", | |
245 | subsys => "block", | |
246 | devpath => "/block/sda/sda3", | |
247 | exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , | |
248 | rules => <<EOF | |
249 | BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b" | |
250 | EOF | |
251 | }, | |
252 | { | |
253 | desc => "test substitution chars (with length limit)", | |
254 | subsys => "block", | |
255 | devpath => "/block/sda/sda3", | |
256 | exp_name => "M8-m3-n3-b0:0-sIBM" , | |
257 | rules => <<EOF | |
258 | BUS=="scsi", ID=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}" | |
259 | EOF | |
260 | }, | |
261 | { | |
262 | desc => "import of shell-value file", | |
263 | subsys => "block", | |
264 | devpath => "/block/sda", | |
265 | exp_name => "subdir/sys/node" , | |
266 | rules => <<EOF | |
267 | BUS=="scsi", IMPORT{file}="test.all", NAME="subdir%E{SYSFSDIR}/node" | |
268 | KERNEL=="ttyUSB0", NAME="visor" | |
269 | EOF | |
270 | }, | |
271 | { | |
272 | desc => "import of shell-value returned from program", | |
273 | subsys => "block", | |
274 | devpath => "/block/sda", | |
275 | exp_name => "node12345678", | |
276 | rules => <<EOF | |
277 | BUS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678 \\n TEST_key2=98765 \'", NAME="node\$env{TEST_KEY}" | |
278 | KERNEL=="ttyUSB0", NAME="visor" | |
279 | EOF | |
280 | }, | |
281 | { | |
282 | desc => "sustitution of sysfs value (%s{file})", | |
283 | subsys => "block", | |
284 | devpath => "/block/sda", | |
285 | exp_name => "disk-IBM-ESXS-sda" , | |
286 | rules => <<EOF | |
287 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="disk-%s{vendor}-%k" | |
288 | KERNEL=="ttyUSB0", NAME="visor" | |
289 | EOF | |
290 | }, | |
291 | { | |
292 | desc => "program result substitution", | |
293 | subsys => "block", | |
294 | devpath => "/block/sda/sda3", | |
295 | exp_name => "special-device-3" , | |
296 | rules => <<EOF | |
297 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", NAME="%c-1-%n" | |
298 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special--*", NAME="%c-2-%n" | |
299 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n" | |
300 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-devic", NAME="%c-4-%n" | |
301 | BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", NAME="%c-%n" | |
302 | EOF | |
303 | }, | |
304 | { | |
305 | desc => "program result substitution (no argument should be subsystem)", | |
306 | subsys => "block", | |
307 | devpath => "/block/sda/sda3", | |
308 | exp_name => "subsys_block" , | |
309 | rules => <<EOF | |
310 | BUS=="scsi", PROGRAM=="/bin/echo", RESULT=="block", NAME="subsys_block" | |
311 | EOF | |
312 | }, | |
313 | { | |
314 | desc => "program result substitution (newline removal)", | |
315 | subsys => "block", | |
316 | devpath => "/block/sda/sda3", | |
317 | exp_name => "newline_removed" , | |
318 | rules => <<EOF | |
319 | BUS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", NAME="newline_removed" | |
320 | EOF | |
321 | }, | |
322 | { | |
323 | desc => "program result substitution", | |
324 | subsys => "block", | |
325 | devpath => "/block/sda/sda3", | |
326 | exp_name => "test-0:0:0:0" , | |
327 | rules => <<EOF | |
328 | BUS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c" | |
329 | EOF | |
330 | }, | |
331 | { | |
332 | desc => "program with escaped format char (tricky: callout returns format char!)", | |
333 | subsys => "block", | |
334 | devpath => "/block/sda/sda3", | |
335 | exp_name => "escape-3" , | |
336 | rules => <<EOF | |
337 | BUS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda3", NAME="%c" | |
338 | EOF | |
339 | }, | |
340 | { | |
341 | desc => "program with lots of arguments", | |
342 | subsys => "block", | |
343 | devpath => "/block/sda/sda3", | |
344 | exp_name => "foo9" , | |
345 | rules => <<EOF | |
346 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="%c{7}" | |
347 | EOF | |
348 | }, | |
349 | { | |
350 | desc => "program with subshell", | |
351 | subsys => "block", | |
352 | devpath => "/block/sda/sda3", | |
353 | exp_name => "bar9" , | |
354 | rules => <<EOF | |
355 | BUS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda3", NAME="%c{7}" | |
356 | EOF | |
357 | }, | |
358 | { | |
359 | desc => "program arguments combined with apostrophes", | |
360 | subsys => "block", | |
361 | devpath => "/block/sda/sda3", | |
362 | exp_name => "foo7" , | |
363 | rules => <<EOF | |
364 | BUS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda3", NAME="%c{5}" | |
365 | EOF | |
366 | }, | |
367 | { | |
368 | desc => "characters before the %c{N} substitution", | |
369 | subsys => "block", | |
370 | devpath => "/block/sda/sda3", | |
371 | exp_name => "my-foo9" , | |
372 | rules => <<EOF | |
373 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{7}" | |
374 | EOF | |
375 | }, | |
376 | { | |
377 | desc => "substitute the second to last argument", | |
378 | subsys => "block", | |
379 | devpath => "/block/sda/sda3", | |
380 | exp_name => "my-foo8" , | |
381 | rules => <<EOF | |
382 | BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{6}" | |
383 | EOF | |
384 | }, | |
385 | { | |
386 | desc => "test substitution by variable name", | |
387 | subsys => "block", | |
388 | devpath => "/block/sda/sda3", | |
389 | exp_name => "Major:8-minor:3-kernelnumber:3-bus:0:0:0:0" , | |
390 | rules => <<EOF | |
391 | BUS=="scsi", ID=="0:0:0:0", NAME="Major:\$major-minor:\$minor-kernelnumber:\$number-bus:\$id" | |
392 | EOF | |
393 | }, | |
394 | { | |
395 | desc => "test substitution by variable name 2", | |
396 | subsys => "block", | |
397 | devpath => "/block/sda/sda3", | |
398 | exp_name => "Major:8-minor:3-kernelnumber:3-bus:0:0:0:0" , | |
399 | rules => <<EOF | |
400 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="Major:\$major-minor:%m-kernelnumber:\$number-bus:%b" | |
401 | EOF | |
402 | }, | |
403 | { | |
404 | desc => "test substitution by variable name 3", | |
405 | subsys => "block", | |
406 | devpath => "/block/sda/sda3", | |
407 | exp_name => "830:0:0:03" , | |
408 | rules => <<EOF | |
409 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="%M%m%b%n" | |
410 | EOF | |
411 | }, | |
412 | { | |
413 | desc => "test substitution by variable name 4", | |
414 | subsys => "block", | |
415 | devpath => "/block/sda/sda3", | |
416 | exp_name => "833" , | |
417 | rules => <<EOF | |
418 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major\$minor\$number" | |
419 | EOF | |
420 | }, | |
421 | { | |
422 | desc => "test substitution by variable name 5", | |
423 | subsys => "block", | |
424 | devpath => "/block/sda/sda3", | |
425 | exp_name => "8330:0:0:0" , | |
426 | rules => <<EOF | |
427 | BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major%m%n\$id" | |
428 | EOF | |
429 | }, | |
430 | { | |
431 | desc => "invalid program for device with no bus", | |
432 | subsys => "tty", | |
433 | devpath => "/class/tty/console", | |
434 | exp_name => "TTY" , | |
435 | rules => <<EOF | |
436 | BUS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo" | |
437 | KERNEL=="console", NAME="TTY" | |
438 | EOF | |
439 | }, | |
440 | { | |
441 | desc => "valid program for device with no bus", | |
442 | subsys => "tty", | |
443 | devpath => "/class/tty/console", | |
444 | exp_name => "foo" , | |
445 | rules => <<EOF | |
446 | PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo" | |
447 | KERNEL=="console", NAME="TTY" | |
448 | EOF | |
449 | }, | |
450 | { | |
451 | desc => "invalid label for device with no bus", | |
452 | subsys => "tty", | |
453 | devpath => "/class/tty/console", | |
454 | exp_name => "TTY" , | |
455 | rules => <<EOF | |
456 | BUS=="foo", SYSFS{dev}=="5:1", NAME="foo" | |
457 | KERNEL=="console", NAME="TTY" | |
458 | EOF | |
459 | }, | |
460 | { | |
461 | desc => "valid label for device with no bus", | |
462 | subsys => "tty", | |
463 | devpath => "/class/tty/console", | |
464 | exp_name => "foo" , | |
465 | rules => <<EOF | |
466 | SYSFS{dev}=="5:1", NAME="foo" | |
467 | KERNEL=="console", NAME="TTY" | |
468 | EOF | |
469 | }, | |
470 | { | |
471 | desc => "program and bus type match", | |
472 | subsys => "block", | |
473 | devpath => "/block/sda", | |
474 | exp_name => "scsi-0:0:0:0" , | |
475 | rules => <<EOF | |
476 | BUS=="usb", PROGRAM=="/bin/echo -n usb-%b", NAME="%c" | |
477 | BUS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", NAME="%c" | |
478 | BUS=="foo", PROGRAM=="/bin/echo -n foo-%b", NAME="%c" | |
479 | EOF | |
480 | }, | |
481 | { | |
482 | desc => "create all possible partitions", | |
483 | subsys => "block", | |
484 | devpath => "/block/sda", | |
485 | exp_name => "boot_disk15" , | |
486 | exp_majorminor => "8:15", | |
487 | rules => <<EOF | |
488 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME{all_partitions}="boot_disk" | |
489 | EOF | |
490 | }, | |
491 | { | |
492 | desc => "sysfs parent hierarchy", | |
493 | subsys => "tty", | |
494 | devpath => "/class/tty/ttyUSB0", | |
495 | exp_name => "visor" , | |
496 | rules => <<EOF | |
497 | SYSFS{idProduct}=="2008", NAME="visor" | |
498 | EOF | |
499 | }, | |
500 | { | |
501 | desc => "name test with ! in the name", | |
502 | subsys => "block", | |
503 | devpath => "/block/rd!c0d0", | |
504 | exp_name => "rd/c0d0" , | |
505 | rules => <<EOF | |
506 | BUS=="scsi", NAME="%k" | |
507 | KERNEL=="ttyUSB0", NAME="visor" | |
508 | EOF | |
509 | }, | |
510 | { | |
511 | desc => "name test with ! in the name, but no matching rule", | |
512 | subsys => "block", | |
513 | devpath => "/block/rd!c0d0", | |
514 | exp_name => "rd/c0d0" , | |
515 | rules => <<EOF | |
516 | KERNEL=="ttyUSB0", NAME="visor" | |
517 | EOF | |
518 | }, | |
519 | { | |
520 | desc => "name test with ! in the name for a partition", | |
521 | subsys => "block", | |
522 | devpath => "/block/cciss!c0d0/cciss!c0d0p1", | |
523 | exp_name => "cciss/c0d0p1" , | |
524 | rules => <<EOF | |
525 | BUS=="scsi", NAME="%k" | |
526 | KERNEL=="ttyUSB0", NAME="visor" | |
527 | EOF | |
528 | }, | |
529 | { | |
530 | desc => "ID rule", | |
531 | subsys => "block", | |
532 | devpath => "/block/sda", | |
533 | exp_name => "scsi-0:0:0:0", | |
534 | rules => <<EOF | |
535 | BUS=="usb", ID=="0:0:0:0", NAME="not-scsi" | |
536 | BUS=="scsi", ID=="0:0:0:1", NAME="no-match" | |
537 | BUS=="scsi", ID==":0", NAME="short-id" | |
538 | BUS=="scsi", ID=="/0:0:0:0", NAME="no-match" | |
539 | BUS=="scsi", ID=="0:0:0:0", NAME="scsi-0:0:0:0" | |
540 | EOF | |
541 | }, | |
542 | { | |
543 | desc => "ID wildcard all", | |
544 | subsys => "block", | |
545 | devpath => "/block/sda", | |
546 | exp_name => "scsi-0:0:0:0", | |
547 | rules => <<EOF | |
548 | BUS=="scsi", ID=="*:1", NAME="no-match" | |
549 | BUS=="scsi", ID=="*:0:1", NAME="no-match" | |
550 | BUS=="scsi", ID=="*:0:0:1", NAME="no-match" | |
551 | BUS=="scsi", ID=="*", NAME="scsi-0:0:0:0" | |
552 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
553 | EOF | |
554 | }, | |
555 | { | |
556 | desc => "ID wildcard partial", | |
557 | subsys => "block", | |
558 | devpath => "/block/sda", | |
559 | exp_name => "scsi-0:0:0:0", | |
560 | rules => <<EOF | |
561 | BUS=="scsi", ID=="*:0", NAME="scsi-0:0:0:0" | |
562 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
563 | EOF | |
564 | }, | |
565 | { | |
566 | desc => "ID wildcard partial 2", | |
567 | subsys => "block", | |
568 | devpath => "/block/sda", | |
569 | exp_name => "scsi-0:0:0:0", | |
570 | rules => <<EOF | |
571 | BUS=="scsi", ID=="*:0:0:0", NAME="scsi-0:0:0:0" | |
572 | BUS=="scsi", ID=="0:0:0:0", NAME="bad" | |
573 | EOF | |
574 | }, | |
575 | { | |
576 | desc => "ignore SYSFS attribute whitespace", | |
577 | subsys => "block", | |
578 | devpath => "/block/sda", | |
579 | exp_name => "ignored", | |
580 | rules => <<EOF | |
581 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE", NAME="ignored" | |
582 | EOF | |
583 | }, | |
584 | { | |
585 | desc => "do not ignore SYSFS attribute whitespace", | |
586 | subsys => "block", | |
587 | devpath => "/block/sda", | |
588 | exp_name => "matched-with-space", | |
589 | rules => <<EOF | |
590 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="wrong-to-ignore" | |
591 | BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="matched-with-space" | |
592 | EOF | |
593 | }, | |
594 | { | |
595 | desc => "permissions USER=bad GROUP=name", | |
596 | subsys => "tty", | |
597 | devpath => "/class/tty/tty33", | |
598 | exp_name => "tty33", | |
599 | exp_perms => "0:0:0660", | |
600 | rules => <<EOF | |
601 | KERNEL=="tty33", NAME="tty33", OWNER="bad", GROUP="name" | |
602 | EOF | |
603 | }, | |
604 | { | |
605 | desc => "permissions OWNER=5000", | |
606 | subsys => "block", | |
607 | devpath => "/block/sda", | |
608 | exp_name => "node", | |
609 | exp_perms => "5000::0660", | |
610 | rules => <<EOF | |
611 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000" | |
612 | EOF | |
613 | }, | |
614 | { | |
615 | desc => "permissions GROUP=100", | |
616 | subsys => "block", | |
617 | devpath => "/block/sda", | |
618 | exp_name => "node", | |
619 | exp_perms => ":100:0660", | |
620 | rules => <<EOF | |
621 | BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="100" | |
622 | EOF | |
623 | }, | |
624 | { | |
625 | desc => "textual user id", | |
626 | subsys => "block", | |
627 | devpath => "/block/sda", | |
628 | exp_name => "node", | |
629 | exp_perms => "nobody::0660", | |
630 | rules => <<EOF | |
631 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="nobody" | |
632 | EOF | |
633 | }, | |
634 | { | |
635 | desc => "textual group id", | |
636 | subsys => "block", | |
637 | devpath => "/block/sda", | |
638 | exp_name => "node", | |
639 | exp_perms => ":daemon:0660", | |
640 | rules => <<EOF | |
641 | BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="daemon" | |
642 | EOF | |
643 | }, | |
644 | { | |
645 | desc => "textual user/group id", | |
646 | subsys => "block", | |
647 | devpath => "/block/sda", | |
648 | exp_name => "node", | |
649 | exp_perms => "root:mail:0660", | |
650 | rules => <<EOF | |
651 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="root", GROUP="mail" | |
652 | EOF | |
653 | }, | |
654 | { | |
655 | desc => "permissions MODE=0777", | |
656 | subsys => "block", | |
657 | devpath => "/block/sda", | |
658 | exp_name => "node", | |
659 | exp_perms => "::0777", | |
660 | rules => <<EOF | |
661 | BUS=="scsi", KERNEL=="sda", NAME="node", MODE="0777" | |
662 | EOF | |
663 | }, | |
664 | { | |
665 | desc => "permissions OWNER=5000 GROUP=100 MODE=0777", | |
666 | subsys => "block", | |
667 | devpath => "/block/sda", | |
668 | exp_name => "node", | |
669 | exp_perms => "5000:100:0777", | |
670 | rules => <<EOF | |
671 | BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777" | |
672 | EOF | |
673 | }, | |
674 | { | |
675 | desc => "permissions OWNER to 5000", | |
676 | subsys => "tty", | |
677 | devpath => "/class/tty/ttyUSB0", | |
678 | exp_name => "ttyUSB0", | |
679 | exp_perms => "5000::", | |
680 | rules => <<EOF | |
681 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000" | |
682 | EOF | |
683 | }, | |
684 | { | |
685 | desc => "permissions GROUP to 100", | |
686 | subsys => "tty", | |
687 | devpath => "/class/tty/ttyUSB0", | |
688 | exp_name => "ttyUSB0", | |
689 | exp_perms => ":100:0660", | |
690 | rules => <<EOF | |
691 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100" | |
692 | EOF | |
693 | }, | |
694 | { | |
695 | desc => "permissions MODE to 0060", | |
696 | subsys => "tty", | |
697 | devpath => "/class/tty/ttyUSB0", | |
698 | exp_name => "ttyUSB0", | |
699 | exp_perms => "::0060", | |
700 | rules => <<EOF | |
701 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060" | |
702 | EOF | |
703 | }, | |
704 | { | |
705 | desc => "permissions OWNER, GROUP, MODE", | |
706 | subsys => "tty", | |
707 | devpath => "/class/tty/ttyUSB0", | |
708 | exp_name => "ttyUSB0", | |
709 | exp_perms => "5000:100:0777", | |
710 | rules => <<EOF | |
711 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777" | |
712 | EOF | |
713 | }, | |
714 | { | |
715 | desc => "permissions only rule", | |
716 | subsys => "tty", | |
717 | devpath => "/class/tty/ttyUSB0", | |
718 | exp_name => "ttyUSB0", | |
719 | exp_perms => "5000:100:0777", | |
720 | rules => <<EOF | |
721 | KERNEL=="ttyUSB[0-9]*", OWNER="5000", GROUP="100", MODE="0777" | |
722 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
723 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
724 | EOF | |
725 | }, | |
726 | { | |
727 | desc => "multiple permissions only rule", | |
728 | subsys => "tty", | |
729 | devpath => "/class/tty/ttyUSB0", | |
730 | exp_name => "ttyUSB0", | |
731 | exp_perms => "3000:4000:0777", | |
732 | rules => <<EOF | |
733 | SUBSYSTEM=="tty", OWNER="3000" | |
734 | SUBSYSTEM=="tty", GROUP="4000" | |
735 | SUBSYSTEM=="tty", MODE="0777" | |
736 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
737 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n" | |
738 | EOF | |
739 | }, | |
740 | { | |
741 | desc => "permissions only rule with override at NAME rule", | |
742 | subsys => "tty", | |
743 | devpath => "/class/tty/ttyUSB0", | |
744 | exp_name => "ttyUSB0", | |
745 | exp_perms => "3000:8000:0777", | |
746 | rules => <<EOF | |
747 | SUBSYSTEM=="tty", OWNER="3000" | |
748 | SUBSYSTEM=="tty", GROUP="4000" | |
749 | SUBSYSTEM=="tty", MODE="0777" | |
750 | KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444" | |
751 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="8000" | |
752 | EOF | |
753 | }, | |
754 | { | |
755 | desc => "major/minor number test", | |
756 | subsys => "block", | |
757 | devpath => "/block/sda", | |
758 | exp_name => "node", | |
759 | exp_majorminor => "8:0", | |
760 | rules => <<EOF | |
761 | BUS=="scsi", KERNEL=="sda", NAME="node" | |
762 | EOF | |
763 | }, | |
764 | { | |
765 | desc => "big minor number test", | |
766 | subsys => "i2c-dev", | |
767 | devpath => "/class/i2c-dev/i2c-300", | |
768 | exp_name => "node", | |
769 | exp_majorminor => "89:300", | |
770 | rules => <<EOF | |
771 | KERNEL=="i2c-300", NAME="node" | |
772 | EOF | |
773 | }, | |
774 | { | |
775 | desc => "big major number test", | |
776 | subsys => "i2c-dev", | |
777 | devpath => "/class/i2c-dev/i2c-fake1", | |
778 | exp_name => "node", | |
779 | exp_majorminor => "4095:1", | |
780 | rules => <<EOF | |
781 | KERNEL=="i2c-fake1", NAME="node" | |
782 | EOF | |
783 | }, | |
784 | { | |
785 | desc => "big major and big minor number test", | |
786 | subsys => "i2c-dev", | |
787 | devpath => "/class/i2c-dev/i2c-fake2", | |
788 | exp_name => "node", | |
789 | exp_majorminor => "4094:89999", | |
790 | rules => <<EOF | |
791 | KERNEL=="i2c-fake2", NAME="node" | |
792 | EOF | |
793 | }, | |
794 | { | |
795 | desc => "multiple symlinks with format char", | |
796 | subsys => "tty", | |
797 | devpath => "/class/tty/ttyUSB0", | |
798 | exp_name => "symlink2-ttyUSB0", | |
799 | exp_target => "ttyUSB0", | |
800 | rules => <<EOF | |
801 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b" | |
802 | EOF | |
803 | }, | |
804 | { | |
805 | desc => "multiple symlinks with a lot of s p a c e s", | |
806 | subsys => "tty", | |
807 | devpath => "/class/tty/ttyUSB0", | |
808 | exp_name => "one", | |
809 | not_exp_name => " ", | |
810 | exp_target => "ttyUSB0", | |
811 | rules => <<EOF | |
812 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK=" one two " | |
813 | EOF | |
814 | }, | |
815 | { | |
816 | desc => "symlink creation (same directory)", | |
817 | subsys => "tty", | |
818 | devpath => "/class/tty/ttyUSB0", | |
819 | exp_name => "visor0", | |
820 | exp_target => "ttyUSB0", | |
821 | rules => <<EOF | |
822 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n" | |
823 | EOF | |
824 | }, | |
825 | { | |
826 | desc => "symlink creation (relative link forward)", | |
827 | subsys => "block", | |
828 | devpath => "/block/sda/sda2", | |
829 | exp_name => "1/2/symlink" , | |
830 | exp_target => "a/b/node", | |
831 | rules => <<EOF | |
832 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink" | |
833 | EOF | |
834 | }, | |
835 | { | |
836 | desc => "symlink creation (relative link back and forward)", | |
837 | subsys => "block", | |
838 | devpath => "/block/sda/sda2", | |
839 | exp_name => "1/2/c/d/symlink" , | |
840 | exp_target => "../../a/b/node", | |
841 | rules => <<EOF | |
842 | BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink" | |
843 | EOF | |
844 | }, | |
845 | { | |
846 | desc => "multiple symlinks", | |
847 | subsys => "tty", | |
848 | devpath => "/class/tty/ttyUSB0", | |
849 | exp_name => "second-0" , | |
850 | exp_target => "visor" , | |
851 | rules => <<EOF | |
852 | KERNEL=="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n" | |
853 | EOF | |
854 | }, | |
855 | { | |
856 | desc => "symlink only rule", | |
857 | subsys => "block", | |
858 | devpath => "/block/sda", | |
859 | exp_name => "symlink-only2", | |
860 | exp_target => "link", | |
861 | rules => <<EOF | |
862 | BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only1" | |
863 | BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only2" | |
864 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0" | |
865 | EOF | |
866 | }, | |
867 | { | |
868 | desc => "symlink name '.'", | |
869 | subsys => "block", | |
870 | devpath => "/block/sda", | |
871 | exp_name => ".", | |
872 | exp_target => "link", | |
873 | exp_add_error => "yes", | |
874 | exp_rem_error => "yes", | |
875 | rules => <<EOF | |
876 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="." | |
877 | EOF | |
878 | }, | |
879 | { | |
880 | desc => "symlink node to itself", | |
881 | subsys => "tty", | |
882 | devpath => "/class/tty/tty0", | |
883 | exp_name => "link", | |
884 | exp_target => "link", | |
885 | exp_rem_error => "yes", | |
886 | option => "clean", | |
887 | rules => <<EOF | |
888 | KERNEL=="tty0", NAME="link", SYMLINK+="link" | |
889 | EOF | |
890 | }, | |
891 | { | |
892 | desc => "symlink %n substitution", | |
893 | subsys => "tty", | |
894 | devpath => "/class/tty/ttyUSB0", | |
895 | exp_name => "symlink0", | |
896 | exp_target => "ttyUSB0", | |
897 | rules => <<EOF | |
898 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink%n" | |
899 | EOF | |
900 | }, | |
901 | { | |
902 | desc => "symlink %k substitution", | |
903 | subsys => "tty", | |
904 | devpath => "/class/tty/ttyUSB0", | |
905 | exp_name => "symlink-ttyUSB0", | |
906 | exp_target => "ttyUSB0", | |
907 | rules => <<EOF | |
908 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink-%k" | |
909 | EOF | |
910 | }, | |
911 | { | |
912 | desc => "symlink %M:%m substitution", | |
913 | subsys => "tty", | |
914 | devpath => "/class/tty/ttyUSB0", | |
915 | exp_name => "major-188:0", | |
916 | exp_target => "ttyUSB0", | |
917 | rules => <<EOF | |
918 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="major-%M:%m" | |
919 | EOF | |
920 | }, | |
921 | { | |
922 | desc => "symlink %b substitution", | |
923 | subsys => "block", | |
924 | devpath => "/block/sda", | |
925 | exp_name => "symlink-0:0:0:0", | |
926 | exp_target => "node", | |
927 | rules => <<EOF | |
928 | BUS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b" | |
929 | EOF | |
930 | }, | |
931 | { | |
932 | desc => "symlink %c substitution", | |
933 | subsys => "tty", | |
934 | devpath => "/class/tty/ttyUSB0", | |
935 | exp_name => "test", | |
936 | exp_target => "ttyUSB0", | |
937 | rules => <<EOF | |
938 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo test" NAME="ttyUSB%n", SYMLINK+="%c" | |
939 | EOF | |
940 | }, | |
941 | { | |
942 | desc => "symlink %c{N} substitution", | |
943 | subsys => "tty", | |
944 | devpath => "/class/tty/ttyUSB0", | |
945 | exp_name => "test", | |
946 | exp_target => "ttyUSB0", | |
947 | rules => <<EOF | |
948 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2}" | |
949 | EOF | |
950 | }, | |
951 | { | |
952 | desc => "symlink %c{N+} substitution", | |
953 | subsys => "tty", | |
954 | devpath => "/class/tty/ttyUSB0", | |
955 | exp_name => "this", | |
956 | exp_target => "ttyUSB0", | |
957 | rules => <<EOF | |
958 | KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2+}" | |
959 | EOF | |
960 | }, | |
961 | { | |
962 | desc => "symlink only rule with %c{N+}", | |
963 | subsys => "block", | |
964 | devpath => "/block/sda", | |
965 | exp_name => "test", | |
966 | exp_target => "link", | |
967 | rules => <<EOF | |
968 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}" | |
969 | BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0" | |
970 | EOF | |
971 | }, | |
972 | { | |
973 | desc => "symlink %s{filename} substitution", | |
974 | subsys => "tty", | |
975 | devpath => "/class/tty/ttyUSB0", | |
976 | exp_name => "188:0", | |
977 | exp_target => "ttyUSB0", | |
978 | rules => <<EOF | |
979 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%s{dev}" | |
980 | EOF | |
981 | }, | |
982 | { | |
983 | desc => "symlink %Ns{filename} substitution", | |
984 | subsys => "tty", | |
985 | devpath => "/class/tty/ttyUSB0", | |
986 | exp_name => "188", | |
987 | exp_target => "ttyUSB0", | |
988 | rules => <<EOF | |
989 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%3s{dev}" | |
990 | EOF | |
991 | }, | |
992 | { | |
993 | desc => "symlink with '%' in name", | |
994 | subsys => "tty", | |
995 | devpath => "/class/tty/ttyUSB0", | |
996 | exp_name => "percent%sign", | |
997 | exp_target => "ttyUSB0", | |
998 | rules => <<EOF | |
999 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="percent%%sign" | |
1000 | EOF | |
1001 | }, | |
1002 | { | |
1003 | desc => "symlink with '%' in name", | |
1004 | subsys => "tty", | |
1005 | devpath => "/class/tty/ttyUSB0", | |
1006 | exp_name => "%ttyUSB0_name", | |
1007 | exp_target => "ttyUSB0", | |
1008 | rules => <<EOF | |
1009 | KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%%%k_name" | |
1010 | EOF | |
1011 | }, | |
1012 | { | |
1013 | desc => "program result substitution (numbered part of)", | |
1014 | subsys => "block", | |
1015 | devpath => "/block/sda/sda3", | |
1016 | exp_name => "link1", | |
1017 | exp_target => "node", | |
1018 | rules => <<EOF | |
1019 | BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2} %c{3}" | |
1020 | EOF | |
1021 | }, | |
1022 | { | |
1023 | desc => "program result substitution (numbered part of+)", | |
1024 | subsys => "block", | |
1025 | devpath => "/block/sda/sda3", | |
1026 | exp_name => "link4", | |
1027 | exp_target => "node", | |
1028 | rules => <<EOF | |
1029 | BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}" | |
1030 | EOF | |
1031 | }, | |
1032 | { | |
1033 | desc => "enumeration char test (single test)", | |
1034 | subsys => "block", | |
1035 | devpath => "/block/sda", | |
1036 | exp_name => "cdrom", | |
1037 | rules => <<EOF | |
1038 | KERNEL=="sda", NAME="cdrom%e" | |
1039 | EOF | |
1040 | }, | |
1041 | { | |
1042 | desc => "enumeration char test sequence 1/5 (keep)", | |
1043 | subsys => "block", | |
1044 | devpath => "/block/sda", | |
1045 | exp_name => "cdrom", | |
1046 | option => "keep", | |
1047 | rules => <<EOF | |
1048 | KERNEL=="sda", NAME="cdrom%e" | |
1049 | EOF | |
1050 | }, | |
1051 | { | |
1052 | desc => "enumeration char test sequence 2/5 (keep)", | |
1053 | subsys => "block", | |
1054 | devpath => "/block/sda/sda1", | |
1055 | exp_name => "enum", | |
1056 | option => "keep", | |
1057 | rules => <<EOF | |
1058 | KERNEL=="sda1", NAME="enum%e" | |
1059 | EOF | |
1060 | }, | |
1061 | { | |
1062 | desc => "enumeration char test sequence 3/5 (keep)", | |
1063 | subsys => "block", | |
1064 | devpath => "/block/sda/sda2", | |
1065 | exp_name => "cdrom1", | |
1066 | option => "keep", | |
1067 | rules => <<EOF | |
1068 | KERNEL=="sda2", NAME="cdrom%e" | |
1069 | EOF | |
1070 | }, | |
1071 | { | |
1072 | desc => "enumeration char test sequence 4/5 (keep)", | |
1073 | subsys => "block", | |
1074 | devpath => "/block/sda/sda3", | |
1075 | exp_name => "enum1", | |
1076 | option => "keep", | |
1077 | rules => <<EOF | |
1078 | KERNEL=="sda3", NAME="enum%e" | |
1079 | EOF | |
1080 | }, | |
1081 | { | |
1082 | desc => "enumeration char test sequence 5/5 (clean)", | |
1083 | subsys => "block", | |
1084 | devpath => "/block/sda/sda4", | |
1085 | exp_name => "cdrom2", | |
1086 | option => "clean", | |
1087 | rules => <<EOF | |
1088 | KERNEL=="sda4", NAME="cdrom%e" | |
1089 | EOF | |
1090 | }, | |
1091 | { | |
1092 | desc => "enumeration char test after cleanup (single test)", | |
1093 | subsys => "block", | |
1094 | devpath => "/block/sda", | |
1095 | exp_name => "cdrom", | |
1096 | rules => <<EOF | |
1097 | KERNEL=="sda", NAME="cdrom%e" | |
1098 | EOF | |
1099 | }, | |
1100 | { | |
1101 | desc => "ignore rule test", | |
1102 | subsys => "block", | |
1103 | devpath => "/block/sda", | |
1104 | exp_name => "nothing", | |
1105 | not_exp_name => "node", | |
1106 | exp_add_error => "yes", | |
1107 | rules => <<EOF | |
1108 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore" | |
1109 | EOF | |
1110 | }, | |
1111 | { | |
1112 | desc => "all_partitions, option-only rule", | |
1113 | subsys => "block", | |
1114 | devpath => "/block/sda", | |
1115 | exp_name => "node6", | |
1116 | rules => <<EOF | |
1117 | SUBSYSTEM=="block", OPTIONS="all_partitions" | |
1118 | BUS=="scsi", KERNEL=="sda", NAME="node" | |
1119 | EOF | |
1120 | }, | |
1121 | { | |
1122 | desc => "all_partitions, option-only rule (fail on partition)", | |
1123 | subsys => "block", | |
1124 | devpath => "/block/sda/sda1", | |
1125 | exp_name => "node6", | |
1126 | exp_add_error => "yes", | |
1127 | rules => <<EOF | |
1128 | SUBSYSTEM=="block", OPTIONS="all_partitions" | |
1129 | BUS=="scsi", KERNEL=="sda", NAME="node" | |
1130 | EOF | |
1131 | }, | |
1132 | { | |
1133 | desc => "ignore remove event test", | |
1134 | subsys => "block", | |
1135 | devpath => "/block/sda", | |
1136 | exp_name => "node", | |
1137 | exp_rem_error => "yes", | |
1138 | rules => <<EOF | |
1139 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove" | |
1140 | EOF | |
1141 | }, | |
1142 | { | |
1143 | desc => "ignore remove event test (with all partitions)", | |
1144 | subsys => "block", | |
1145 | devpath => "/block/sda", | |
1146 | exp_name => "node14", | |
1147 | exp_rem_error => "yes", | |
1148 | option => "clean", | |
1149 | rules => <<EOF | |
1150 | BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove, all_partitions" | |
1151 | EOF | |
1152 | }, | |
1153 | { | |
1154 | desc => "SUBSYSTEM match test", | |
1155 | subsys => "block", | |
1156 | devpath => "/block/sda", | |
1157 | exp_name => "node", | |
1158 | rules => <<EOF | |
1159 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match", SUBSYSTEM=="vc" | |
1160 | BUS=="scsi", KERNEL=="sda", NAME="node", SUBSYSTEM=="block" | |
1161 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match2", SUBSYSTEM=="vc" | |
1162 | EOF | |
1163 | }, | |
1164 | { | |
1165 | desc => "DRIVER match test", | |
1166 | subsys => "block", | |
1167 | devpath => "/block/sda", | |
1168 | exp_name => "node", | |
1169 | rules => <<EOF | |
1170 | BUS=="scsi", KERNEL=="sda", NAME="should_not_match", DRIVER=="sd-wrong" | |
1171 | BUS=="scsi", KERNEL=="sda", NAME="node", DRIVER=="sd" | |
1172 | EOF | |
1173 | }, | |
1174 | { | |
1175 | desc => "temporary node creation test", | |
1176 | subsys => "block", | |
1177 | devpath => "/block/sda", | |
1178 | exp_name => "node", | |
1179 | rules => <<EOF | |
1180 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" NAME="node" | |
1181 | EOF | |
1182 | }, | |
1183 | { | |
1184 | desc => "devpath substitution test", | |
1185 | subsys => "block", | |
1186 | devpath => "/block/sda", | |
1187 | exp_name => "sda", | |
1188 | rules => <<EOF | |
1189 | BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/block/sda" NAME="%k" | |
1190 | EOF | |
1191 | }, | |
1192 | { | |
1193 | desc => "parent node name substitution test sequence 1/2 (keep)", | |
1194 | subsys => "block", | |
1195 | devpath => "/block/sda", | |
1196 | exp_name => "main_device", | |
1197 | option => "keep", | |
1198 | rules => <<EOF | |
1199 | BUS=="scsi", KERNEL=="sda", NAME="main_device" | |
1200 | EOF | |
1201 | }, | |
1202 | { | |
1203 | desc => "parent node name substitution test sequence 2/2 (clean)", | |
1204 | subsys => "block", | |
1205 | devpath => "/block/sda/sda1", | |
1206 | exp_name => "main_device-part-1", | |
1207 | option => "clean", | |
1208 | rules => <<EOF | |
1209 | BUS=="scsi", KERNEL=="sda1", NAME="%P-part-1" | |
1210 | EOF | |
1211 | }, | |
1212 | { | |
1213 | desc => "udev_root substitution", | |
1214 | subsys => "block", | |
1215 | devpath => "/block/sda/sda1", | |
1216 | exp_name => "start-udev-root-end", | |
1217 | rules => <<EOF | |
1218 | BUS=="scsi", KERNEL=="sda1", NAME="start-%r-end" | |
1219 | EOF | |
1220 | }, | |
1221 | { | |
1222 | desc => "last_rule option", | |
1223 | subsys => "block", | |
1224 | devpath => "/block/sda/sda1", | |
1225 | exp_name => "last", | |
1226 | rules => <<EOF | |
1227 | BUS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule" | |
1228 | BUS=="scsi", KERNEL=="sda1", NAME="very-last" | |
1229 | EOF | |
1230 | }, | |
1231 | { | |
1232 | desc => "negation KERNEL!=", | |
1233 | subsys => "block", | |
1234 | devpath => "/block/sda/sda1", | |
1235 | exp_name => "match", | |
1236 | rules => <<EOF | |
1237 | BUS=="scsi", KERNEL!="sda1", NAME="matches-but-is-negated" | |
1238 | BUS=="scsi", KERNEL!="xsda1", NAME="match" | |
1239 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1240 | EOF | |
1241 | }, | |
1242 | { | |
1243 | desc => "negation SUBSYSTEM!=", | |
1244 | subsys => "block", | |
1245 | devpath => "/block/sda/sda1", | |
1246 | exp_name => "not-anything", | |
1247 | rules => <<EOF | |
1248 | BUS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", NAME="matches-but-is-negated" | |
1249 | BUS=="scsi", SUBSYSTEM!="anything", NAME="not-anything" | |
1250 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1251 | EOF | |
1252 | }, | |
1253 | { | |
1254 | desc => "negation PROGRAM!= exit code", | |
1255 | subsys => "block", | |
1256 | devpath => "/block/sda/sda1", | |
1257 | exp_name => "nonzero-program", | |
1258 | rules => <<EOF | |
1259 | KERNEL=="sda1", PROGRAM!="/bin/false", NAME="nonzero-program" | |
1260 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1261 | EOF | |
1262 | }, | |
1263 | { | |
1264 | desc => "test for whitespace between the operator", | |
1265 | subsys => "block", | |
1266 | devpath => "/block/sda/sda1", | |
1267 | exp_name => "true", | |
1268 | rules => <<EOF | |
1269 | KERNEL == "sda1" , NAME = "true" | |
1270 | BUS=="scsi", KERNEL=="sda1", NAME="wrong" | |
1271 | EOF | |
1272 | }, | |
1273 | { | |
1274 | desc => "ENV{} test", | |
1275 | subsys => "block", | |
1276 | devpath => "/block/sda/sda1", | |
1277 | exp_name => "true", | |
1278 | rules => <<EOF | |
1279 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong" | |
1280 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", NAME="true" | |
1281 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad" | |
1282 | EOF | |
1283 | }, | |
1284 | { | |
1285 | desc => "ENV{} test", | |
1286 | subsys => "block", | |
1287 | devpath => "/block/sda/sda1", | |
1288 | exp_name => "true", | |
1289 | rules => <<EOF | |
1290 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong" | |
1291 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sdax1", NAME="no" | |
1292 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sda1", NAME="true" | |
1293 | BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad" | |
1294 | EOF | |
1295 | }, | |
1296 | { | |
1297 | desc => "ENV{} test (assign)", | |
1298 | subsys => "block", | |
1299 | devpath => "/block/sda/sda1", | |
1300 | exp_name => "true", | |
1301 | rules => <<EOF | |
1302 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true" | |
1303 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no" | |
1304 | BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", NAME="true" | |
1305 | BUS=="scsi", KERNEL=="sda1", NAME="bad" | |
1306 | EOF | |
1307 | }, | |
1308 | { | |
1309 | desc => "ENV{} test (assign2)", | |
1310 | subsys => "block", | |
1311 | devpath => "/block/sda/sda1", | |
1312 | exp_name => "part", | |
1313 | rules => <<EOF | |
1314 | SUBSYSTEM=="block", KERNEL="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false" | |
1315 | SUBSYSTEM=="block", KERNEL="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true" | |
1316 | ENV{MAINDEVICE}=="true", NAME="disk" | |
1317 | ENV{PARTITION}=="true", NAME="part" | |
1318 | NAME="bad" | |
1319 | EOF | |
1320 | }, | |
1321 | { | |
1322 | desc => "untrusted string sanitize", | |
1323 | subsys => "block", | |
1324 | devpath => "/block/sda/sda1", | |
1325 | exp_name => "sane", | |
1326 | rules => <<EOF | |
1327 | BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT="name_ _/sbin/badprogram_", NAME="sane" | |
1328 | EOF | |
1329 | }, | |
1330 | { | |
1331 | desc => "read sysfs value from device down in the chain", | |
1332 | subsys => "block", | |
1333 | devpath => "/class/tty/ttyUSB0", | |
1334 | exp_name => "serial-0000:00:09.0", | |
1335 | rules => <<EOF | |
1336 | KERNEL=="ttyUSB*", NAME="serial-%s{serial}" | |
1337 | EOF | |
1338 | }, | |
1339 | { | |
1340 | desc => "match against empty key string", | |
1341 | subsys => "block", | |
1342 | devpath => "/block/sda", | |
1343 | exp_name => "ok", | |
1344 | rules => <<EOF | |
1345 | KERNEL=="sda", SYSFS{nothing}!="", NAME="not-1-ok" | |
1346 | KERNEL=="sda", SYSFS{nothing}=="", NAME="not-2-ok" | |
1347 | KERNEL=="sda", SYSFS{vendor}!="", NAME="ok" | |
1348 | KERNEL=="sda", SYSFS{vendor}=="", NAME="not-3-ok" | |
1349 | EOF | |
1350 | }, | |
1351 | { | |
1352 | desc => "check ACTION value", | |
1353 | subsys => "block", | |
1354 | devpath => "/block/sda", | |
1355 | exp_name => "ok", | |
1356 | rules => <<EOF | |
1357 | ACTION=="unknown", KERNEL=="sda", NAME="unknown-not-ok" | |
1358 | ACTION=="add", KERNEL=="sda", NAME="ok" | |
1359 | EOF | |
1360 | }, | |
1361 | { | |
1362 | desc => "apply NAME only once", | |
1363 | subsys => "block", | |
1364 | devpath => "/block/sda", | |
1365 | exp_name => "link", | |
1366 | exp_target => "ok", | |
1367 | rules => <<EOF | |
1368 | KERNEL=="sda", NAME="ok" | |
1369 | KERNEL=="sda", NAME="not-ok" | |
1370 | KERNEL=="sda", SYMLINK+="link" | |
1371 | EOF | |
1372 | }, | |
1373 | { | |
1374 | desc => "test RUN key", | |
1375 | subsys => "block", | |
1376 | devpath => "/block/sda", | |
1377 | exp_name => "testsymlink", | |
1378 | exp_target => "ok", | |
1379 | exp_rem_error => "yes", | |
1380 | option => "clean", | |
1381 | rules => <<EOF | |
1382 | KERNEL=="sda", NAME="ok", RUN+="/bin/ln -s ok %r/testsymlink" | |
1383 | KERNEL=="sda", NAME="not-ok" | |
1384 | EOF | |
1385 | }, | |
1386 | { | |
1387 | desc => "test RUN key and DEVNAME", | |
1388 | subsys => "block", | |
1389 | devpath => "/block/sda", | |
1390 | exp_name => "testsymlink", | |
1391 | exp_target => "ok", | |
1392 | exp_rem_error => "yes", | |
1393 | option => "clean", | |
1394 | rules => <<EOF | |
1395 | KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'" | |
1396 | KERNEL=="sda", NAME="not-ok" | |
1397 | EOF | |
1398 | }, | |
1399 | { | |
1400 | desc => "test RUN key remove", | |
1401 | subsys => "block", | |
1402 | devpath => "/block/sda", | |
1403 | exp_name => "testsymlink2", | |
1404 | exp_target => "ok2", | |
1405 | rules => <<EOF | |
1406 | KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2" | |
1407 | KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2" | |
1408 | KERNEL=="sda", NAME="not-ok2" | |
1409 | EOF | |
1410 | }, | |
1411 | { | |
1412 | desc => "final assignment", | |
1413 | subsys => "block", | |
1414 | devpath => "/block/sda", | |
1415 | exp_name => "ok", | |
1416 | exp_perms => "root:nobody:0640", | |
1417 | rules => <<EOF | |
1418 | KERNEL=="sda", GROUP:="nobody" | |
1419 | KERNEL=="sda", GROUP="not-ok", MODE="0640", NAME="ok" | |
1420 | EOF | |
1421 | }, | |
1422 | { | |
1423 | desc => "final assignment", | |
1424 | subsys => "block", | |
1425 | devpath => "/block/sda", | |
1426 | exp_name => "ok", | |
1427 | exp_perms => "root:nobody:0640", | |
1428 | rules => <<EOF | |
1429 | KERNEL=="sda", GROUP:="nobody" | |
1430 | SUBSYSTEM=="block", MODE:="640" | |
1431 | KERNEL=="sda", GROUP="not-ok", MODE="0666", NAME="ok" | |
1432 | EOF | |
1433 | }, | |
1434 | { | |
1435 | desc => "env substitution", | |
1436 | subsys => "block", | |
1437 | devpath => "/block/sda", | |
1438 | exp_name => "node-add-me", | |
1439 | rules => <<EOF | |
1440 | KERNEL=="sda", MODE="0666", NAME="node-\$env{ACTION}-me" | |
1441 | EOF | |
1442 | }, | |
1443 | { | |
1444 | desc => "reset list to current value", | |
1445 | subsys => "tty", | |
1446 | devpath => "/class/tty/ttyUSB0", | |
1447 | exp_name => "three", | |
1448 | not_exp_name => "two", | |
1449 | exp_target => "node", | |
1450 | rules => <<EOF | |
1451 | KERNEL=="ttyUSB[0-9]*", SYMLINK+="one" | |
1452 | KERNEL=="ttyUSB[0-9]*", SYMLINK+="two" | |
1453 | KERNEL=="ttyUSB[0-9]*", SYMLINK="three" | |
1454 | KERNEL=="ttyUSB[0-9]*", NAME="node" | |
1455 | EOF | |
1456 | }, | |
1457 | { | |
1458 | desc => "test empty NAME", | |
1459 | subsys => "tty", | |
1460 | devpath => "/class/tty/ttyUSB0", | |
1461 | exp_name => "node", | |
1462 | not_exp_name => "wrong", | |
1463 | exp_add_error => "yes", | |
1464 | rules => <<EOF | |
1465 | KERNEL=="ttyUSB[0-9]*", NAME="" | |
1466 | KERNEL=="ttyUSB[0-9]*", NAME="wrong" | |
1467 | EOF | |
1468 | }, | |
1469 | { | |
1470 | desc => "test empty NAME 2", | |
1471 | subsys => "tty", | |
1472 | devpath => "/class/tty/ttyUSB0", | |
1473 | exp_name => "right", | |
1474 | rules => <<EOF | |
1475 | KERNEL=="ttyUSB[0-9]*", NAME="right" | |
1476 | KERNEL=="ttyUSB[0-9]*", NAME="" | |
1477 | KERNEL=="ttyUSB[0-9]*", NAME="wrong" | |
1478 | EOF | |
1479 | }, | |
1480 | { | |
1481 | desc => "test multi matches", | |
1482 | subsys => "tty", | |
1483 | devpath => "/class/tty/ttyUSB0", | |
1484 | exp_name => "right", | |
1485 | rules => <<EOF | |
1486 | KERNEL=="ttyUSB*|nothing", NAME="right" | |
1487 | KERNEL=="ttyUSB*", NAME="wrong" | |
1488 | EOF | |
1489 | }, | |
1490 | { | |
1491 | desc => "test multi matches 2", | |
1492 | subsys => "tty", | |
1493 | devpath => "/class/tty/ttyUSB0", | |
1494 | exp_name => "right", | |
1495 | rules => <<EOF | |
1496 | KERNEL=="dontknow*|*nothing", NAME="nomatch" | |
1497 | KERNEL=="dontknow*|ttyUSB*|nothing*", NAME="right" | |
1498 | KERNEL=="ttyUSB*", NAME="wrong" | |
1499 | EOF | |
1500 | }, | |
1501 | { | |
1502 | desc => "IMPORT parent test sequence 1/2 (keep)", | |
1503 | subsys => "block", | |
1504 | devpath => "/block/sda", | |
1505 | exp_name => "parent", | |
1506 | option => "keep", | |
1507 | rules => <<EOF | |
1508 | KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'" | |
1509 | KERNEL=="sda", NAME="parent" | |
1510 | EOF | |
1511 | }, | |
1512 | { | |
1513 | desc => "IMPORT parent test sequence 2/2 (keep)", | |
1514 | subsys => "block", | |
1515 | devpath => "/block/sda/sda1", | |
1516 | exp_name => "parentenv-parent_right", | |
1517 | option => "clean", | |
1518 | rules => <<EOF | |
1519 | KERNEL=="sda1", IMPORT{parent}="PARENT*", NAME="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}" | |
1520 | EOF | |
1521 | }, | |
1522 | { | |
1523 | desc => "GOTO test", | |
1524 | subsys => "block", | |
1525 | devpath => "/block/sda/sda1", | |
1526 | exp_name => "right", | |
1527 | rules => <<EOF | |
1528 | KERNEL=="sda1", GOTO="TEST" | |
1529 | KERNEL=="sda1", NAME="wrong" | |
1530 | KERNEL=="sda1", NAME="", LABEL="NO" | |
1531 | KERNEL=="sda1", NAME="right", LABEL="TEST" | |
1532 | KERNEL=="sda1", NAME="wrong2" | |
1533 | EOF | |
1534 | }, | |
1535 | ); | |
1536 | ||
1537 | # set env | |
1538 | $ENV{ENV_KEY_TEST} = "test"; | |
1539 | $ENV{SYSFS_PATH} = $sysfs; | |
1540 | $ENV{UDEV_CONFIG_FILE} = $udev_conf; | |
1541 | $ENV{UDEV_NO_DEVD} = "yes"; | |
1542 | $ENV{UDEV_NO_HOTPLUGD} = "yes"; | |
1543 | ||
1544 | ||
1545 | sub udev { | |
1546 | my ($action, $subsys, $devpath, $rules) = @_; | |
1547 | ||
1548 | $ENV{DEVPATH} = $devpath; | |
1549 | ||
1550 | # create temporary rules | |
1551 | open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules"; | |
1552 | print CONF $$rules; | |
1553 | close CONF; | |
1554 | ||
1555 | $ENV{ACTION} = $action; | |
1556 | system("$udev_bin $subsys"); | |
1557 | } | |
1558 | ||
1559 | my $error = 0; | |
1560 | ||
1561 | sub permissions_test { | |
1562 | my($rules, $uid, $gid, $mode) = @_; | |
1563 | ||
1564 | my $wrong = 0; | |
1565 | my $userid; | |
1566 | my $groupid; | |
1567 | ||
1568 | $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/; | |
1569 | if ($1 ne "") { | |
1570 | if (defined(getpwnam($1))) { | |
1571 | $userid = int(getpwnam($1)); | |
1572 | } else { | |
1573 | $userid = $1; | |
1574 | } | |
1575 | if ($uid != $userid) { $wrong = 1; } | |
1576 | } | |
1577 | if ($2 ne "") { | |
1578 | if (defined(getgrnam($2))) { | |
1579 | $groupid = int(getgrnam($2)); | |
1580 | } else { | |
1581 | $groupid = $2; | |
1582 | } | |
1583 | if ($gid != $groupid) { $wrong = 1; } | |
1584 | } | |
1585 | if ($3 ne "") { | |
1586 | if (($mode & 07777) != oct($3)) { $wrong = 1; }; | |
1587 | } | |
1588 | if ($wrong == 0) { | |
1589 | print "permissions: ok\n"; | |
1590 | } else { | |
1591 | printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); | |
1592 | printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; | |
1593 | print "permissions: error\n"; | |
1594 | $error++; | |
1595 | } | |
1596 | } | |
1597 | ||
1598 | sub major_minor_test { | |
1599 | my($rules, $rdev) = @_; | |
1600 | ||
1601 | my $major = ($rdev >> 8) & 0xfff; | |
1602 | my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); | |
1603 | my $wrong = 0; | |
1604 | ||
1605 | $rules->{exp_majorminor} =~ m/^(.*):(.*)$/; | |
1606 | if ($1 ne "") { | |
1607 | if ($major != $1) { $wrong = 1; }; | |
1608 | } | |
1609 | if ($2 ne "") { | |
1610 | if ($minor != $2) { $wrong = 1; }; | |
1611 | } | |
1612 | if ($wrong == 0) { | |
1613 | print "major:minor: ok\n"; | |
1614 | } else { | |
1615 | printf " expected major:minor is: %i:%i\n", $1, $2; | |
1616 | printf " created major:minor is : %i:%i\n", $major, $minor; | |
1617 | print "major:minor: error\n"; | |
1618 | $error++; | |
1619 | } | |
1620 | } | |
1621 | ||
1622 | sub symlink_test { | |
1623 | my ($rules) = @_; | |
1624 | ||
1625 | my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`; | |
1626 | ||
1627 | if ($output =~ m/(.*)-> (.*)/) { | |
1628 | if ($2 eq $rules->{exp_target}) { | |
1629 | print "symlink: ok\n"; | |
1630 | } else { | |
1631 | print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; | |
1632 | print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n"; | |
1633 | print "symlink: error"; | |
1634 | if ($rules->{exp_add_error}) { | |
1635 | print " as expected\n"; | |
1636 | } else { | |
1637 | print "\n"; | |
1638 | $error++; | |
1639 | } | |
1640 | } | |
1641 | } else { | |
1642 | print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n"; | |
1643 | print "symlink: not created"; | |
1644 | if ($rules->{exp_add_error}) { | |
1645 | print " as expected\n"; | |
1646 | } else { | |
1647 | print "\n"; | |
1648 | $error++; | |
1649 | } | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | sub run_test { | |
1654 | my ($rules, $number) = @_; | |
1655 | ||
1656 | print "TEST $number: $rules->{desc}\n"; | |
1657 | ||
1658 | if ($rules->{exp_target}) { | |
1659 | print "device \'$rules->{devpath}\' expecting symlink '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n"; | |
1660 | } else { | |
1661 | print "device \'$rules->{devpath}\' expecting node \'$rules->{exp_name}\'\n"; | |
1662 | } | |
1663 | ||
1664 | ||
1665 | udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); | |
1666 | if ((-e "$PWD/$udev_root$rules->{exp_name}") || | |
1667 | (-l "$PWD/$udev_root$rules->{exp_name}")) { | |
1668 | ||
1669 | my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, | |
1670 | $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}"); | |
1671 | ||
1672 | if (defined($rules->{not_exp_name})) { | |
1673 | if ((-e "$PWD/$udev_root$rules->{not_exp_name}") || | |
1674 | (-l "$PWD/$udev_root$rules->{not_exp_name}")) { | |
1675 | print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n"; | |
1676 | $error++ | |
1677 | } | |
1678 | } | |
1679 | if (defined($rules->{exp_perms})) { | |
1680 | permissions_test($rules, $uid, $gid, $mode); | |
1681 | } | |
1682 | if (defined($rules->{exp_majorminor})) { | |
1683 | major_minor_test($rules, $rdev); | |
1684 | } | |
1685 | if (defined($rules->{exp_target})) { | |
1686 | symlink_test($rules); | |
1687 | } | |
1688 | print "add: ok\n"; | |
1689 | } else { | |
1690 | print "add: error"; | |
1691 | if ($rules->{exp_add_error}) { | |
1692 | print " as expected\n"; | |
1693 | } else { | |
1694 | print "\n"; | |
1695 | system("tree $udev_root"); | |
1696 | print "\n"; | |
1697 | $error++; | |
1698 | } | |
1699 | } | |
1700 | ||
1701 | if (defined($rules->{option}) && $rules->{option} eq "keep") { | |
1702 | print "\n\n"; | |
1703 | return; | |
1704 | } | |
1705 | ||
1706 | udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules}); | |
1707 | if ((-e "$PWD/$udev_root$rules->{exp_name}") || | |
1708 | (-l "$PWD/$udev_root$rules->{exp_name}")) { | |
1709 | print "remove: error"; | |
1710 | if ($rules->{exp_rem_error}) { | |
1711 | print " as expected\n"; | |
1712 | } else { | |
1713 | print "\n"; | |
1714 | system("tree $udev_root"); | |
1715 | print "\n"; | |
1716 | $error++; | |
1717 | } | |
1718 | } else { | |
1719 | print "remove: ok\n"; | |
1720 | } | |
1721 | ||
1722 | print "\n"; | |
1723 | ||
1724 | if (defined($rules->{option}) && $rules->{option} eq "clean") { | |
1725 | system("rm -rf $udev_db"); | |
1726 | system("rm -rf $udev_root"); | |
1727 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1728 | } | |
1729 | ||
1730 | } | |
1731 | ||
1732 | # only run if we have root permissions | |
1733 | # due to mknod restrictions | |
1734 | if (!($<==0)) { | |
1735 | print "Must have root permissions to run properly.\n"; | |
1736 | exit; | |
1737 | } | |
1738 | ||
1739 | # prepare | |
1740 | system("rm -rf $udev_root"); | |
1741 | mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; | |
1742 | ||
1743 | # create config file | |
1744 | open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf"; | |
1745 | print CONF "udev_root=\"$udev_root\"\n"; | |
1746 | print CONF "udev_db=\"$udev_db\"\n"; | |
1747 | print CONF "udev_rules=\"$udev_rules\"\n"; | |
1748 | close CONF; | |
1749 | ||
1750 | my $test_num = 1; | |
1751 | ||
1752 | if ($ARGV[0]) { | |
1753 | # only run one test | |
1754 | $test_num = $ARGV[0]; | |
1755 | ||
1756 | if (defined($tests[$test_num-1]->{desc})) { | |
1757 | print "udev-test will run test number $test_num only:\n\n"; | |
1758 | run_test($tests[$test_num-1], $test_num); | |
1759 | } else { | |
1760 | print "test does not exist.\n"; | |
1761 | } | |
1762 | } else { | |
1763 | # test all | |
1764 | print "\nudev-test will run ".($#tests + 1)." tests:\n\n"; | |
1765 | ||
1766 | foreach my $rules (@tests) { | |
1767 | run_test($rules, $test_num); | |
1768 | $test_num++; | |
1769 | } | |
1770 | } | |
1771 | ||
1772 | print "$error errors occured\n\n"; | |
1773 | ||
1774 | # cleanup | |
1775 | system("rm -rf $udev_db"); | |
1776 | system("rm -rf $udev_root"); | |
1777 | unlink($udev_rules); | |
1778 | unlink($udev_conf); | |
1779 |