]> git.ipfire.org Git - thirdparty/systemd.git/blame - test/udev-test.pl
add uft8 validation for safe volume label exporting
[thirdparty/systemd.git] / test / udev-test.pl
CommitLineData
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#
65005a7f 12# udev parses the rules, looks at the provided sysfs and
a367f04e
GKH
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#
a367f04e 17# Kay Sievers <kay.sievers@vrfy.org>, 2003
f22e9686 18# Leann Ogasawara <ogasawara@osdl.org>, 2004
a367f04e
GKH
19
20use warnings;
21use strict;
22
65005a7f
KS
23my $PWD = $ENV{PWD};
24my $sysfs = "sys/";
25my $udev_bin = "../udev";
26my $udev_root = "udev-root/"; # !!! directory will be removed !!!
27my $udev_db = ".udevdb";
28my $udev_conf = "udev-test.conf";
29my $udev_rules = "udev-test.rules";
a367f04e 30
18ebc430
GKH
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";
a367f04e
GKH
34
35my @tests = (
36 {
fa19f181
KS
37 desc => "label test of scsi disc",
38 subsys => "block",
f61d732a 39 devpath => "/block/sda",
c013b034 40 exp_name => "boot_disk" ,
65005a7f 41 rules => <<EOF
28ce66de
KS
42BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
43KERNEL=="ttyUSB0", NAME="visor"
a367f04e
GKH
44EOF
45 },
46 {
fa19f181
KS
47 desc => "label test of scsi partition",
48 subsys => "block",
f61d732a 49 devpath => "/block/sda/sda1",
c013b034 50 exp_name => "boot_disk1" ,
65005a7f 51 rules => <<EOF
28ce66de 52BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
83be97ba
KS
53EOF
54 },
55 {
fa19f181
KS
56 desc => "label test of pattern match",
57 subsys => "block",
f61d732a 58 devpath => "/block/sda/sda1",
c013b034 59 exp_name => "boot_disk1" ,
65005a7f 60 rules => <<EOF
28ce66de
KS
61BUS=="scsi", SYSFS{vendor}=="?IBM-ESXS", NAME="boot_disk%n-1"
62BUS=="scsi", SYSFS{vendor}=="IBM-ESXS?", NAME="boot_disk%n-2"
63BUS=="scsi", SYSFS{vendor}=="IBM-ES??", NAME="boot_disk%n"
64BUS=="scsi", SYSFS{vendor}=="IBM-ESXSS", NAME="boot_disk%n-3"
358c8c20
GKH
65EOF
66 },
67 {
fa19f181
KS
68 desc => "label test of multiple sysfs files",
69 subsys => "block",
f61d732a 70 devpath => "/block/sda/sda1",
fa19f181 71 exp_name => "boot_disk1" ,
65005a7f 72 rules => <<EOF
28ce66de
KS
73BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_diskX%n"
74BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", NAME="boot_disk%n"
358c8c20
GKH
75EOF
76 },
77 {
fa19f181
KS
78 desc => "label test of max sysfs files",
79 subsys => "block",
f61d732a 80 devpath => "/block/sda/sda1",
fa19f181 81 exp_name => "boot_disk1" ,
65005a7f 82 rules => <<EOF
28ce66de
KS
83BUS=="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"
84BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", SYSFS{model}=="ST336605LW !#", SYSFS{scsi_level}=="4", SYSFS{rev}=="B245", SYSFS{type}=="0", NAME="boot_disk%n"
0db6d4cc
KS
85EOF
86 },
87 {
fa19f181
KS
88 desc => "catch device by *",
89 subsys => "tty",
f61d732a 90 devpath => "/class/tty/ttyUSB0",
fa19f181 91 exp_name => "visor/0" ,
65005a7f 92 rules => <<EOF
28ce66de 93KERNEL=="ttyUSB*", NAME="visor/%n"
2e317184
GKH
94EOF
95 },
96 {
fa19f181
KS
97 desc => "catch device by * - take 2",
98 subsys => "tty",
f61d732a 99 devpath => "/class/tty/ttyUSB0",
fa19f181 100 exp_name => "visor/0" ,
65005a7f 101 rules => <<EOF
28ce66de
KS
102KERNEL=="*USB1", NAME="bad"
103KERNEL=="*USB0", NAME="visor/%n"
9f1da361
KS
104EOF
105 },
106 {
fa19f181
KS
107 desc => "catch device by ?",
108 subsys => "tty",
f61d732a 109 devpath => "/class/tty/ttyUSB0",
fa19f181 110 exp_name => "visor/0" ,
65005a7f 111 rules => <<EOF
28ce66de
KS
112KERNEL=="ttyUSB??*", NAME="visor/%n-1"
113KERNEL=="ttyUSB??", NAME="visor/%n-2"
114KERNEL=="ttyUSB?", NAME="visor/%n"
9f1da361
KS
115EOF
116 },
117 {
fa19f181
KS
118 desc => "catch device by character class",
119 subsys => "tty",
f61d732a 120 devpath => "/class/tty/ttyUSB0",
fa19f181 121 exp_name => "visor/0" ,
65005a7f 122 rules => <<EOF
28ce66de
KS
123KERNEL=="ttyUSB[A-Z]*", NAME="visor/%n-1"
124KERNEL=="ttyUSB?[0-9]", NAME="visor/%n-2"
125KERNEL=="ttyUSB[0-9]*", NAME="visor/%n"
a367f04e
GKH
126EOF
127 },
128 {
fa19f181
KS
129 desc => "replace kernel name",
130 subsys => "tty",
f61d732a 131 devpath => "/class/tty/ttyUSB0",
fa19f181 132 exp_name => "visor" ,
65005a7f 133 rules => <<EOF
28ce66de 134KERNEL=="ttyUSB0", NAME="visor"
281ff00a
GKH
135EOF
136 },
137 {
fa19f181
KS
138 desc => "Handle comment lines in config file (and replace kernel name)",
139 subsys => "tty",
f61d732a 140 devpath => "/class/tty/ttyUSB0",
fa19f181 141 exp_name => "visor" ,
65005a7f 142 rules => <<EOF
281ff00a 143# this is a comment
28ce66de 144KERNEL=="ttyUSB0", NAME="visor"
281ff00a
GKH
145
146EOF
147 },
148 {
fa19f181
KS
149 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
150 subsys => "tty",
f61d732a 151 devpath => "/class/tty/ttyUSB0",
fa19f181 152 exp_name => "visor" ,
65005a7f 153 rules => <<EOF
281ff00a 154 # this is a comment with whitespace before the comment
28ce66de 155KERNEL=="ttyUSB0", NAME="visor"
281ff00a 156
3db7fa27
KS
157EOF
158 },
159 {
160 desc => "Handle whitespace only lines (and replace kernel name)",
161 subsys => "tty",
162 devpath => "/class/tty/ttyUSB0",
163 exp_name => "whitespace" ,
65005a7f 164 rules => <<EOF
3db7fa27
KS
165
166
167
168 # this is a comment with whitespace before the comment
28ce66de 169KERNEL=="ttyUSB0", NAME="whitespace"
3db7fa27
KS
170
171
172
281ff00a
GKH
173EOF
174 },
175 {
fa19f181
KS
176 desc => "Handle empty lines in config file (and replace kernel name)",
177 subsys => "tty",
f61d732a 178 devpath => "/class/tty/ttyUSB0",
fa19f181 179 exp_name => "visor" ,
65005a7f 180 rules => <<EOF
281ff00a 181
28ce66de 182KERNEL=="ttyUSB0", NAME="visor"
281ff00a 183
9f8dfa19
KS
184EOF
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" ,
65005a7f 191 rules => <<EOF
28ce66de 192KERNEL=="ttyUSB0", \\
9f8dfa19
KS
193NAME="visor"
194
77313cd0
KS
195EOF
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",
65005a7f 202 rules => <<EOF
28ce66de 203KERNEL=="ttyUSB0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", NAME="aaa"
9f8dfa19
KS
204EOF
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" ,
65005a7f 211 rules => <<EOF
9f8dfa19
KS
212
213#
214\\
215
216\\\\
217
218#\\
219
28ce66de 220KERNEL=="ttyUSB0", \\
87da5b2c 221 NAME="visor"
9f8dfa19 222
5499d319
KS
223EOF
224 },
225 {
fa19f181
KS
226 desc => "subdirectory handling",
227 subsys => "tty",
f61d732a 228 devpath => "/class/tty/ttyUSB0",
fa19f181 229 exp_name => "sub/direct/ory/visor" ,
65005a7f 230 rules => <<EOF
28ce66de 231KERNEL=="ttyUSB0", NAME="sub/direct/ory/visor"
a367f04e
GKH
232EOF
233 },
234 {
fa19f181
KS
235 desc => "place on bus of scsi partition",
236 subsys => "block",
f61d732a 237 devpath => "/block/sda/sda3",
fa19f181 238 exp_name => "first_disk3" ,
65005a7f 239 rules => <<EOF
28ce66de 240BUS=="scsi", ID=="0:0:0:0", NAME="first_disk%n"
a367f04e
GKH
241EOF
242 },
243 {
bf5d2964 244 desc => "test substitution chars",
fa19f181 245 subsys => "block",
f61d732a 246 devpath => "/block/sda/sda3",
fa19f181 247 exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
65005a7f 248 rules => <<EOF
28ce66de 249BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
63ead27c
KS
250EOF
251 },
252 {
bf5d2964 253 desc => "test substitution chars (with length limit)",
fa19f181 254 subsys => "block",
f61d732a 255 devpath => "/block/sda/sda3",
fa19f181 256 exp_name => "M8-m3-n3-b0:0-sIBM" ,
65005a7f 257 rules => <<EOF
28ce66de 258BUS=="scsi", ID=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
bd0ed2ff
KS
259EOF
260 },
261 {
319c6700 262 desc => "import of shell-value file",
bd0ed2ff
KS
263 subsys => "block",
264 devpath => "/block/sda",
265 exp_name => "subdir/sys/node" ,
266 rules => <<EOF
be0856c8 267BUS=="scsi", IMPORT{file}="test.all", NAME="subdir%E{SYSFSDIR}/node"
bd0ed2ff 268KERNEL=="ttyUSB0", NAME="visor"
319c6700
KS
269EOF
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
be0856c8 277BUS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678 \\n TEST_key2=98765 \'", NAME="node\$env{TEST_KEY}"
319c6700 278KERNEL=="ttyUSB0", NAME="visor"
a27cd06c
KS
279EOF
280 },
281 {
fa19f181
KS
282 desc => "sustitution of sysfs value (%s{file})",
283 subsys => "block",
f61d732a 284 devpath => "/block/sda",
fa19f181 285 exp_name => "disk-IBM-ESXS-sda" ,
65005a7f 286 rules => <<EOF
28ce66de
KS
287BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="disk-%s{vendor}-%k"
288KERNEL=="ttyUSB0", NAME="visor"
a367f04e
GKH
289EOF
290 },
291 {
fa19f181
KS
292 desc => "program result substitution",
293 subsys => "block",
f61d732a 294 devpath => "/block/sda/sda3",
fa19f181 295 exp_name => "special-device-3" ,
65005a7f 296 rules => <<EOF
28ce66de
KS
297BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", NAME="%c-1-%n"
298BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special--*", NAME="%c-2-%n"
299BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n"
300BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-devic", NAME="%c-4-%n"
301BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", NAME="%c-%n"
f608f8ac
KS
302EOF
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" ,
65005a7f 309 rules => <<EOF
28ce66de 310BUS=="scsi", PROGRAM=="/bin/echo", RESULT=="block", NAME="subsys_block"
bbbe503e
KS
311EOF
312 },
313 {
314 desc => "program result substitution (newline removal)",
315 subsys => "block",
316 devpath => "/block/sda/sda3",
317 exp_name => "newline_removed" ,
65005a7f 318 rules => <<EOF
28ce66de 319BUS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", NAME="newline_removed"
f3b04a2e
GKH
320EOF
321 },
322 {
fa19f181
KS
323 desc => "program result substitution",
324 subsys => "block",
f61d732a 325 devpath => "/block/sda/sda3",
fa19f181 326 exp_name => "test-0:0:0:0" ,
65005a7f 327 rules => <<EOF
28ce66de 328BUS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c"
8ffb636f
KS
329EOF
330 },
331 {
fa19f181
KS
332 desc => "program with escaped format char (tricky: callout returns format char!)",
333 subsys => "block",
f61d732a 334 devpath => "/block/sda/sda3",
fa19f181 335 exp_name => "escape-3" ,
65005a7f 336 rules => <<EOF
28ce66de 337BUS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda3", NAME="%c"
dde05ccb
GKH
338EOF
339 },
340 {
fa19f181
KS
341 desc => "program with lots of arguments",
342 subsys => "block",
f61d732a 343 devpath => "/block/sda/sda3",
fa19f181 344 exp_name => "foo9" ,
65005a7f 345 rules => <<EOF
28ce66de 346BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="%c{7}"
35b38379
KS
347EOF
348 },
349 {
fa19f181
KS
350 desc => "program with subshell",
351 subsys => "block",
f61d732a 352 devpath => "/block/sda/sda3",
fa19f181 353 exp_name => "bar9" ,
65005a7f 354 rules => <<EOF
28ce66de 355BUS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda3", NAME="%c{7}"
35b38379
KS
356EOF
357 },
358 {
fa19f181
KS
359 desc => "program arguments combined with apostrophes",
360 subsys => "block",
f61d732a 361 devpath => "/block/sda/sda3",
fa19f181 362 exp_name => "foo7" ,
65005a7f 363 rules => <<EOF
28ce66de 364BUS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda3", NAME="%c{5}"
56c963dc
PM
365EOF
366 },
367 {
fa19f181
KS
368 desc => "characters before the %c{N} substitution",
369 subsys => "block",
f61d732a 370 devpath => "/block/sda/sda3",
fa19f181 371 exp_name => "my-foo9" ,
65005a7f 372 rules => <<EOF
28ce66de 373BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{7}"
56c963dc
PM
374EOF
375 },
376 {
fa19f181
KS
377 desc => "substitute the second to last argument",
378 subsys => "block",
f61d732a 379 devpath => "/block/sda/sda3",
fa19f181 380 exp_name => "my-foo8" ,
65005a7f 381 rules => <<EOF
28ce66de 382BUS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{6}"
bf5d2964
KS
383EOF
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
391BUS=="scsi", ID=="0:0:0:0", NAME="Major:\$major-minor:\$minor-kernelnumber:\$number-bus:\$id"
392EOF
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
400BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="Major:\$major-minor:%m-kernelnumber:\$number-bus:%b"
401EOF
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
409BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="%M%m%b%n"
410EOF
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
418BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major\$minor\$number"
419EOF
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
427BUS=="scsi", ID=="0:0:0:0", DEVPATH="*/sda/*", NAME="\$major%m%n\$id"
8ff8bbba
GKH
428EOF
429 },
430 {
fa19f181
KS
431 desc => "invalid program for device with no bus",
432 subsys => "tty",
f61d732a 433 devpath => "/class/tty/console",
fa19f181 434 exp_name => "TTY" ,
65005a7f 435 rules => <<EOF
28ce66de
KS
436BUS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo"
437KERNEL=="console", NAME="TTY"
1d936fbc
GKH
438EOF
439 },
440 {
fa19f181
KS
441 desc => "valid program for device with no bus",
442 subsys => "tty",
f61d732a 443 devpath => "/class/tty/console",
fa19f181 444 exp_name => "foo" ,
65005a7f 445 rules => <<EOF
28ce66de
KS
446PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo"
447KERNEL=="console", NAME="TTY"
64682333
GKH
448EOF
449 },
450 {
fa19f181
KS
451 desc => "invalid label for device with no bus",
452 subsys => "tty",
f61d732a 453 devpath => "/class/tty/console",
fa19f181 454 exp_name => "TTY" ,
65005a7f 455 rules => <<EOF
28ce66de
KS
456BUS=="foo", SYSFS{dev}=="5:1", NAME="foo"
457KERNEL=="console", NAME="TTY"
64682333
GKH
458EOF
459 },
460 {
fa19f181
KS
461 desc => "valid label for device with no bus",
462 subsys => "tty",
f61d732a 463 devpath => "/class/tty/console",
fa19f181 464 exp_name => "foo" ,
65005a7f 465 rules => <<EOF
28ce66de
KS
466SYSFS{dev}=="5:1", NAME="foo"
467KERNEL=="console", NAME="TTY"
772558f4
GKH
468EOF
469 },
470 {
fa19f181
KS
471 desc => "program and bus type match",
472 subsys => "block",
f61d732a 473 devpath => "/block/sda",
fa19f181 474 exp_name => "scsi-0:0:0:0" ,
65005a7f 475 rules => <<EOF
28ce66de
KS
476BUS=="usb", PROGRAM=="/bin/echo -n usb-%b", NAME="%c"
477BUS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", NAME="%c"
478BUS=="foo", PROGRAM=="/bin/echo -n foo-%b", NAME="%c"
724257d9
GKH
479EOF
480 },
481 {
fa19f181
KS
482 desc => "create all possible partitions",
483 subsys => "block",
f61d732a 484 devpath => "/block/sda",
fa19f181 485 exp_name => "boot_disk15" ,
15139b8a 486 exp_majorminor => "8:15",
65005a7f 487 rules => <<EOF
28ce66de 488BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME{all_partitions}="boot_disk"
50e5de03
KS
489EOF
490 },
491 {
fa19f181
KS
492 desc => "sysfs parent hierarchy",
493 subsys => "tty",
f61d732a 494 devpath => "/class/tty/ttyUSB0",
fa19f181 495 exp_name => "visor" ,
65005a7f 496 rules => <<EOF
28ce66de 497SYSFS{idProduct}=="2008", NAME="visor"
f0142622
GKH
498EOF
499 },
500 {
fa19f181
KS
501 desc => "name test with ! in the name",
502 subsys => "block",
f61d732a 503 devpath => "/block/rd!c0d0",
fa19f181 504 exp_name => "rd/c0d0" ,
65005a7f 505 rules => <<EOF
28ce66de
KS
506BUS=="scsi", NAME="%k"
507KERNEL=="ttyUSB0", NAME="visor"
b9fc973b
GKH
508EOF
509 },
510 {
fa19f181
KS
511 desc => "name test with ! in the name, but no matching rule",
512 subsys => "block",
f61d732a 513 devpath => "/block/rd!c0d0",
fa19f181 514 exp_name => "rd/c0d0" ,
65005a7f 515 rules => <<EOF
28ce66de 516KERNEL=="ttyUSB0", NAME="visor"
0f36e68e
GKH
517EOF
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" ,
65005a7f 524 rules => <<EOF
28ce66de
KS
525BUS=="scsi", NAME="%k"
526KERNEL=="ttyUSB0", NAME="visor"
93656247
PM
527EOF
528 },
529 {
fa19f181
KS
530 desc => "ID rule",
531 subsys => "block",
f61d732a 532 devpath => "/block/sda",
fa19f181 533 exp_name => "scsi-0:0:0:0",
65005a7f 534 rules => <<EOF
28ce66de
KS
535BUS=="usb", ID=="0:0:0:0", NAME="not-scsi"
536BUS=="scsi", ID=="0:0:0:1", NAME="no-match"
537BUS=="scsi", ID==":0", NAME="short-id"
538BUS=="scsi", ID=="/0:0:0:0", NAME="no-match"
539BUS=="scsi", ID=="0:0:0:0", NAME="scsi-0:0:0:0"
93656247
PM
540EOF
541 },
542 {
fa19f181
KS
543 desc => "ID wildcard all",
544 subsys => "block",
f61d732a 545 devpath => "/block/sda",
fa19f181 546 exp_name => "scsi-0:0:0:0",
65005a7f 547 rules => <<EOF
28ce66de
KS
548BUS=="scsi", ID=="*:1", NAME="no-match"
549BUS=="scsi", ID=="*:0:1", NAME="no-match"
550BUS=="scsi", ID=="*:0:0:1", NAME="no-match"
551BUS=="scsi", ID=="*", NAME="scsi-0:0:0:0"
552BUS=="scsi", ID=="0:0:0:0", NAME="bad"
93656247
PM
553EOF
554 },
555 {
fa19f181
KS
556 desc => "ID wildcard partial",
557 subsys => "block",
f61d732a 558 devpath => "/block/sda",
fa19f181 559 exp_name => "scsi-0:0:0:0",
65005a7f 560 rules => <<EOF
28ce66de
KS
561BUS=="scsi", ID=="*:0", NAME="scsi-0:0:0:0"
562BUS=="scsi", ID=="0:0:0:0", NAME="bad"
93656247
PM
563EOF
564 },
565 {
fa19f181
KS
566 desc => "ID wildcard partial 2",
567 subsys => "block",
f61d732a 568 devpath => "/block/sda",
fa19f181 569 exp_name => "scsi-0:0:0:0",
65005a7f 570 rules => <<EOF
28ce66de
KS
571BUS=="scsi", ID=="*:0:0:0", NAME="scsi-0:0:0:0"
572BUS=="scsi", ID=="0:0:0:0", NAME="bad"
d5f91372
KS
573EOF
574 },
575 {
fa19f181
KS
576 desc => "ignore SYSFS attribute whitespace",
577 subsys => "block",
f61d732a 578 devpath => "/block/sda",
fa19f181 579 exp_name => "ignored",
65005a7f 580 rules => <<EOF
28ce66de 581BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE", NAME="ignored"
d5f91372
KS
582EOF
583 },
584 {
fa19f181
KS
585 desc => "do not ignore SYSFS attribute whitespace",
586 subsys => "block",
f61d732a 587 devpath => "/block/sda",
fa19f181 588 exp_name => "matched-with-space",
65005a7f 589 rules => <<EOF
28ce66de
KS
590BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="wrong-to-ignore"
591BUS=="scsi", SYSFS{whitespace_test}=="WHITE SPACE ", NAME="matched-with-space"
0a5417a0
KS
592EOF
593 },
594 {
8b36cc0f 595 desc => "permissions USER=bad GROUP=name",
b8669191
GKH
596 subsys => "tty",
597 devpath => "/class/tty/tty33",
598 exp_name => "tty33",
4ae6d03f 599 exp_perms => "0:0:0660",
65005a7f 600 rules => <<EOF
28ce66de 601KERNEL=="tty33", NAME="tty33", OWNER="bad", GROUP="name"
b8669191
GKH
602EOF
603 },
604 {
8b36cc0f 605 desc => "permissions OWNER=5000",
fa19f181 606 subsys => "block",
f61d732a 607 devpath => "/block/sda",
fa19f181 608 exp_name => "node",
4ae6d03f 609 exp_perms => "5000::0660",
65005a7f 610 rules => <<EOF
28ce66de 611BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000"
b8669191
GKH
612EOF
613 },
614 {
8b36cc0f 615 desc => "permissions GROUP=100",
b8669191
GKH
616 subsys => "block",
617 devpath => "/block/sda",
618 exp_name => "node",
4ae6d03f 619 exp_perms => ":100:0660",
65005a7f 620 rules => <<EOF
28ce66de 621BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="100"
9b434de1
KS
622EOF
623 },
624 {
625 desc => "textual user id",
626 subsys => "block",
627 devpath => "/block/sda",
628 exp_name => "node",
0bb43877 629 exp_perms => "nobody::0660",
65005a7f 630 rules => <<EOF
0bb43877 631BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="nobody"
9b434de1
KS
632EOF
633 },
634 {
635 desc => "textual group id",
636 subsys => "block",
637 devpath => "/block/sda",
638 exp_name => "node",
639 exp_perms => ":daemon:0660",
65005a7f 640 rules => <<EOF
9b434de1 641BUS=="scsi", KERNEL=="sda", NAME="node", GROUP="daemon"
c8278763
KS
642EOF
643 },
644 {
645 desc => "textual user/group id",
646 subsys => "block",
647 devpath => "/block/sda",
648 exp_name => "node",
0bb43877 649 exp_perms => "root:mail:0660",
65005a7f 650 rules => <<EOF
0bb43877 651BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="root", GROUP="mail"
b8669191
GKH
652EOF
653 },
654 {
8b36cc0f 655 desc => "permissions MODE=0777",
b8669191
GKH
656 subsys => "block",
657 devpath => "/block/sda",
658 exp_name => "node",
659 exp_perms => "::0777",
65005a7f 660 rules => <<EOF
28ce66de 661BUS=="scsi", KERNEL=="sda", NAME="node", MODE="0777"
b8669191
GKH
662EOF
663 },
664 {
8b36cc0f 665 desc => "permissions OWNER=5000 GROUP=100 MODE=0777",
b8669191
GKH
666 subsys => "block",
667 devpath => "/block/sda",
668 exp_name => "node",
669 exp_perms => "5000:100:0777",
65005a7f 670 rules => <<EOF
28ce66de 671BUS=="scsi", KERNEL=="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777"
b8669191
GKH
672EOF
673 },
674 {
8b36cc0f 675 desc => "permissions OWNER to 5000",
b8669191
GKH
676 subsys => "tty",
677 devpath => "/class/tty/ttyUSB0",
678 exp_name => "ttyUSB0",
8b36cc0f 679 exp_perms => "5000::",
65005a7f 680 rules => <<EOF
28ce66de 681KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000"
b8669191
GKH
682EOF
683 },
684 {
8b36cc0f 685 desc => "permissions GROUP to 100",
b8669191
GKH
686 subsys => "tty",
687 devpath => "/class/tty/ttyUSB0",
688 exp_name => "ttyUSB0",
4ae6d03f 689 exp_perms => ":100:0660",
65005a7f 690 rules => <<EOF
28ce66de 691KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100"
b8669191
GKH
692EOF
693 },
694 {
8b36cc0f 695 desc => "permissions MODE to 0060",
b8669191
GKH
696 subsys => "tty",
697 devpath => "/class/tty/ttyUSB0",
698 exp_name => "ttyUSB0",
8b36cc0f 699 exp_perms => "::0060",
65005a7f 700 rules => <<EOF
28ce66de 701KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060"
b8669191
GKH
702EOF
703 },
704 {
8b36cc0f 705 desc => "permissions OWNER, GROUP, MODE",
b8669191
GKH
706 subsys => "tty",
707 devpath => "/class/tty/ttyUSB0",
708 exp_name => "ttyUSB0",
709 exp_perms => "5000:100:0777",
65005a7f 710 rules => <<EOF
28ce66de 711KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777"
e9390146
KS
712EOF
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",
65005a7f 720 rules => <<EOF
28ce66de
KS
721KERNEL=="ttyUSB[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
722KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
723KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n"
eb870090
KS
724EOF
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",
65005a7f 732 rules => <<EOF
28ce66de
KS
733SUBSYSTEM=="tty", OWNER="3000"
734SUBSYSTEM=="tty", GROUP="4000"
735SUBSYSTEM=="tty", MODE="0777"
736KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
737KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n"
eb870090
KS
738EOF
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",
65005a7f 746 rules => <<EOF
28ce66de
KS
747SUBSYSTEM=="tty", OWNER="3000"
748SUBSYSTEM=="tty", GROUP="4000"
749SUBSYSTEM=="tty", MODE="0777"
750KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
751KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="8000"
fa19f181
KS
752EOF
753 },
754 {
755 desc => "major/minor number test",
756 subsys => "block",
f61d732a 757 devpath => "/block/sda",
fa19f181 758 exp_name => "node",
fa19f181 759 exp_majorminor => "8:0",
65005a7f 760 rules => <<EOF
28ce66de 761BUS=="scsi", KERNEL=="sda", NAME="node"
a5e8d2b4
GKH
762EOF
763 },
764 {
765 desc => "big minor number test",
766 subsys => "i2c-dev",
f61d732a 767 devpath => "/class/i2c-dev/i2c-300",
a5e8d2b4
GKH
768 exp_name => "node",
769 exp_majorminor => "89:300",
65005a7f 770 rules => <<EOF
28ce66de 771KERNEL=="i2c-300", NAME="node"
7d12d4e1
GKH
772EOF
773 },
774 {
775 desc => "big major number test",
776 subsys => "i2c-dev",
f61d732a 777 devpath => "/class/i2c-dev/i2c-fake1",
7d12d4e1
GKH
778 exp_name => "node",
779 exp_majorminor => "4095:1",
65005a7f 780 rules => <<EOF
28ce66de 781KERNEL=="i2c-fake1", NAME="node"
7d12d4e1
GKH
782EOF
783 },
784 {
785 desc => "big major and big minor number test",
786 subsys => "i2c-dev",
f61d732a 787 devpath => "/class/i2c-dev/i2c-fake2",
7d12d4e1
GKH
788 exp_name => "node",
789 exp_majorminor => "4094:89999",
65005a7f 790 rules => <<EOF
28ce66de 791KERNEL=="i2c-fake2", NAME="node"
2b0f835c
KS
792EOF
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",
65005a7f 800 rules => <<EOF
28ce66de 801KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
7b2bdb4b
KS
802EOF
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
812KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK=" one two "
b8669191
GKH
813EOF
814 },
815 {
816 desc => "symlink creation (same directory)",
817 subsys => "tty",
818 devpath => "/class/tty/ttyUSB0",
819 exp_name => "visor0",
820 exp_target => "ttyUSB0",
65005a7f 821 rules => <<EOF
28ce66de 822KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n"
b8669191
GKH
823EOF
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",
65005a7f 831 rules => <<EOF
28ce66de 832BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
b8669191
GKH
833EOF
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",
65005a7f 841 rules => <<EOF
28ce66de 842BUS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
b8669191
GKH
843EOF
844 },
845 {
846 desc => "multiple symlinks",
847 subsys => "tty",
848 devpath => "/class/tty/ttyUSB0",
849 exp_name => "second-0" ,
850 exp_target => "visor" ,
65005a7f 851 rules => <<EOF
28ce66de 852KERNEL=="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
b8669191
GKH
853EOF
854 },
855 {
856 desc => "symlink only rule",
857 subsys => "block",
858 devpath => "/block/sda",
859 exp_name => "symlink-only2",
860 exp_target => "link",
65005a7f 861 rules => <<EOF
995aec87
KS
862BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only1"
863BUS=="scsi", KERNEL=="sda", SYMLINK+="symlink-only2"
864BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0"
b8669191
GKH
865EOF
866 },
867 {
868 desc => "symlink name '.'",
869 subsys => "block",
870 devpath => "/block/sda",
871 exp_name => ".",
872 exp_target => "link",
1cec1c24
KS
873 exp_add_error => "yes",
874 exp_rem_error => "yes",
65005a7f 875 rules => <<EOF
995aec87 876BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="."
b8669191
GKH
877EOF
878 },
879 {
880 desc => "symlink node to itself",
881 subsys => "tty",
882 devpath => "/class/tty/tty0",
883 exp_name => "link",
884 exp_target => "link",
1cec1c24 885 exp_rem_error => "yes",
db949b02 886 option => "clean",
65005a7f 887 rules => <<EOF
995aec87 888KERNEL=="tty0", NAME="link", SYMLINK+="link"
b8669191
GKH
889EOF
890 },
891 {
892 desc => "symlink %n substitution",
893 subsys => "tty",
894 devpath => "/class/tty/ttyUSB0",
895 exp_name => "symlink0",
896 exp_target => "ttyUSB0",
65005a7f 897 rules => <<EOF
995aec87 898KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink%n"
b8669191
GKH
899EOF
900 },
901 {
902 desc => "symlink %k substitution",
903 subsys => "tty",
904 devpath => "/class/tty/ttyUSB0",
905 exp_name => "symlink-ttyUSB0",
906 exp_target => "ttyUSB0",
65005a7f 907 rules => <<EOF
995aec87 908KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="symlink-%k"
b8669191
GKH
909EOF
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",
65005a7f 917 rules => <<EOF
995aec87 918KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="major-%M:%m"
b8669191
GKH
919EOF
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",
65005a7f 927 rules => <<EOF
995aec87 928BUS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b"
b8669191
GKH
929EOF
930 },
931 {
932 desc => "symlink %c substitution",
933 subsys => "tty",
934 devpath => "/class/tty/ttyUSB0",
935 exp_name => "test",
936 exp_target => "ttyUSB0",
65005a7f 937 rules => <<EOF
995aec87 938KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo test" NAME="ttyUSB%n", SYMLINK+="%c"
b8669191
GKH
939EOF
940 },
941 {
942 desc => "symlink %c{N} substitution",
943 subsys => "tty",
944 devpath => "/class/tty/ttyUSB0",
945 exp_name => "test",
946 exp_target => "ttyUSB0",
65005a7f 947 rules => <<EOF
995aec87 948KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2}"
b8669191
GKH
949EOF
950 },
951 {
952 desc => "symlink %c{N+} substitution",
953 subsys => "tty",
954 devpath => "/class/tty/ttyUSB0",
955 exp_name => "this",
956 exp_target => "ttyUSB0",
65005a7f 957 rules => <<EOF
995aec87 958KERNEL=="ttyUSB[0-9]*", PROGRAM=="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK+="%c{2+}"
b8669191
GKH
959EOF
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",
65005a7f 967 rules => <<EOF
995aec87
KS
968BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
969BUS=="scsi", KERNEL=="sda", NAME="link", SYMLINK+="symlink0"
b8669191
GKH
970EOF
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",
65005a7f 978 rules => <<EOF
995aec87 979KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%s{dev}"
b8669191
GKH
980EOF
981 },
982 {
983 desc => "symlink %Ns{filename} substitution",
984 subsys => "tty",
985 devpath => "/class/tty/ttyUSB0",
986 exp_name => "188",
987 exp_target => "ttyUSB0",
65005a7f 988 rules => <<EOF
995aec87 989KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%3s{dev}"
b8669191
GKH
990EOF
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",
65005a7f 998 rules => <<EOF
995aec87 999KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="percent%%sign"
b8669191
GKH
1000EOF
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",
65005a7f 1008 rules => <<EOF
995aec87 1009KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK+="%%%k_name"
b8669191
GKH
1010EOF
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",
65005a7f 1018 rules => <<EOF
995aec87 1019BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2} %c{3}"
b8669191
GKH
1020EOF
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",
65005a7f 1028 rules => <<EOF
995aec87 1029BUS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}"
0345b862
KS
1030EOF
1031 },
1032 {
1033 desc => "enumeration char test (single test)",
1034 subsys => "block",
1035 devpath => "/block/sda",
1036 exp_name => "cdrom",
65005a7f 1037 rules => <<EOF
28ce66de 1038KERNEL=="sda", NAME="cdrom%e"
0345b862
KS
1039EOF
1040 },
1041 {
69aa6dfb 1042 desc => "enumeration char test sequence 1/5 (keep)",
0345b862
KS
1043 subsys => "block",
1044 devpath => "/block/sda",
1045 exp_name => "cdrom",
1046 option => "keep",
65005a7f 1047 rules => <<EOF
28ce66de 1048KERNEL=="sda", NAME="cdrom%e"
0345b862
KS
1049EOF
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",
65005a7f 1057 rules => <<EOF
28ce66de 1058KERNEL=="sda1", NAME="enum%e"
0345b862
KS
1059EOF
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",
65005a7f 1067 rules => <<EOF
28ce66de 1068KERNEL=="sda2", NAME="cdrom%e"
0345b862
KS
1069EOF
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",
65005a7f 1077 rules => <<EOF
28ce66de 1078KERNEL=="sda3", NAME="enum%e"
0345b862
KS
1079EOF
1080 },
1081 {
1082 desc => "enumeration char test sequence 5/5 (clean)",
1083 subsys => "block",
1084 devpath => "/block/sda/sda4",
1085 exp_name => "cdrom2",
db949b02 1086 option => "clean",
65005a7f 1087 rules => <<EOF
28ce66de 1088KERNEL=="sda4", NAME="cdrom%e"
0345b862
KS
1089EOF
1090 },
1091 {
1092 desc => "enumeration char test after cleanup (single test)",
1093 subsys => "block",
1094 devpath => "/block/sda",
1095 exp_name => "cdrom",
65005a7f 1096 rules => <<EOF
28ce66de 1097KERNEL=="sda", NAME="cdrom%e"
fd9efc00
KS
1098EOF
1099 },
1100 {
1101 desc => "ignore rule test",
1102 subsys => "block",
1103 devpath => "/block/sda",
a72e3f66
KS
1104 exp_name => "nothing",
1105 not_exp_name => "node",
1cec1c24 1106 exp_add_error => "yes",
65005a7f 1107 rules => <<EOF
28ce66de 1108BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore"
fd9efc00
KS
1109EOF
1110 },
1111 {
1112 desc => "all_partitions, option-only rule",
1113 subsys => "block",
1114 devpath => "/block/sda",
1115 exp_name => "node6",
65005a7f 1116 rules => <<EOF
28ce66de
KS
1117SUBSYSTEM=="block", OPTIONS="all_partitions"
1118BUS=="scsi", KERNEL=="sda", NAME="node"
fd9efc00
KS
1119EOF
1120 },
1121 {
1122 desc => "all_partitions, option-only rule (fail on partition)",
1123 subsys => "block",
1124 devpath => "/block/sda/sda1",
1125 exp_name => "node6",
1cec1c24 1126 exp_add_error => "yes",
65005a7f 1127 rules => <<EOF
28ce66de
KS
1128SUBSYSTEM=="block", OPTIONS="all_partitions"
1129BUS=="scsi", KERNEL=="sda", NAME="node"
6818c51d
KS
1130EOF
1131 },
1132 {
7efa217d
KS
1133 desc => "ignore remove event test",
1134 subsys => "block",
1135 devpath => "/block/sda",
1136 exp_name => "node",
1cec1c24 1137 exp_rem_error => "yes",
65005a7f 1138 rules => <<EOF
28ce66de 1139BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove"
7efa217d
KS
1140EOF
1141 },
1142 {
1143 desc => "ignore remove event test (with all partitions)",
1144 subsys => "block",
1145 devpath => "/block/sda",
1146 exp_name => "node14",
1cec1c24 1147 exp_rem_error => "yes",
db949b02 1148 option => "clean",
65005a7f 1149 rules => <<EOF
28ce66de 1150BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_remove, all_partitions"
7efa217d
KS
1151EOF
1152 },
1153 {
1154 desc => "SUBSYSTEM match test",
6818c51d
KS
1155 subsys => "block",
1156 devpath => "/block/sda",
1157 exp_name => "node",
65005a7f 1158 rules => <<EOF
28ce66de
KS
1159BUS=="scsi", KERNEL=="sda", NAME="should_not_match", SUBSYSTEM=="vc"
1160BUS=="scsi", KERNEL=="sda", NAME="node", SUBSYSTEM=="block"
1161BUS=="scsi", KERNEL=="sda", NAME="should_not_match2", SUBSYSTEM=="vc"
2092fbcd
KS
1162EOF
1163 },
1164 {
7efa217d 1165 desc => "DRIVER match test",
2092fbcd
KS
1166 subsys => "block",
1167 devpath => "/block/sda",
1168 exp_name => "node",
65005a7f 1169 rules => <<EOF
28ce66de
KS
1170BUS=="scsi", KERNEL=="sda", NAME="should_not_match", DRIVER=="sd-wrong"
1171BUS=="scsi", KERNEL=="sda", NAME="node", DRIVER=="sd"
c1ab0461
KS
1172EOF
1173 },
1174 {
1175 desc => "temporary node creation test",
1176 subsys => "block",
1177 devpath => "/block/sda",
fd42f6a1 1178 exp_name => "node",
65005a7f 1179 rules => <<EOF
28ce66de 1180BUS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" NAME="node"
c1ab0461
KS
1181EOF
1182 },
1183 {
1184 desc => "devpath substitution test",
1185 subsys => "block",
1186 devpath => "/block/sda",
1187 exp_name => "sda",
65005a7f 1188 rules => <<EOF
28ce66de 1189BUS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/block/sda" NAME="%k"
69aa6dfb
KS
1190EOF
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",
65005a7f 1198 rules => <<EOF
28ce66de 1199BUS=="scsi", KERNEL=="sda", NAME="main_device"
69aa6dfb
KS
1200EOF
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",
65005a7f 1208 rules => <<EOF
28ce66de 1209BUS=="scsi", KERNEL=="sda1", NAME="%P-part-1"
69aa6dfb
KS
1210EOF
1211 },
1212 {
1213 desc => "udev_root substitution",
1214 subsys => "block",
1215 devpath => "/block/sda/sda1",
1216 exp_name => "start-udev-root-end",
65005a7f 1217 rules => <<EOF
28ce66de 1218BUS=="scsi", KERNEL=="sda1", NAME="start-%r-end"
3b6ed8bb
KS
1219EOF
1220 },
1221 {
1222 desc => "last_rule option",
1223 subsys => "block",
1224 devpath => "/block/sda/sda1",
1225 exp_name => "last",
65005a7f 1226 rules => <<EOF
995aec87 1227BUS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
28ce66de
KS
1228BUS=="scsi", KERNEL=="sda1", NAME="very-last"
1229EOF
1230 },
1231 {
1232 desc => "negation KERNEL!=",
1233 subsys => "block",
1234 devpath => "/block/sda/sda1",
1235 exp_name => "match",
65005a7f 1236 rules => <<EOF
28ce66de
KS
1237BUS=="scsi", KERNEL!="sda1", NAME="matches-but-is-negated"
1238BUS=="scsi", KERNEL!="xsda1", NAME="match"
1239BUS=="scsi", KERNEL=="sda1", NAME="wrong"
1240EOF
1241 },
1242 {
1243 desc => "negation SUBSYSTEM!=",
1244 subsys => "block",
1245 devpath => "/block/sda/sda1",
1246 exp_name => "not-anything",
65005a7f 1247 rules => <<EOF
28ce66de
KS
1248BUS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", NAME="matches-but-is-negated"
1249BUS=="scsi", SUBSYSTEM!="anything", NAME="not-anything"
1250BUS=="scsi", KERNEL=="sda1", NAME="wrong"
1251EOF
1252 },
1253 {
1254 desc => "negation PROGRAM!= exit code",
1255 subsys => "block",
1256 devpath => "/block/sda/sda1",
1257 exp_name => "nonzero-program",
65005a7f 1258 rules => <<EOF
28ce66de
KS
1259KERNEL=="sda1", PROGRAM!="/bin/false", NAME="nonzero-program"
1260BUS=="scsi", KERNEL=="sda1", NAME="wrong"
38285d23
KS
1261EOF
1262 },
1263 {
1264 desc => "test for whitespace between the operator",
1265 subsys => "block",
1266 devpath => "/block/sda/sda1",
1267 exp_name => "true",
65005a7f 1268 rules => <<EOF
38285d23
KS
1269KERNEL == "sda1" , NAME = "true"
1270BUS=="scsi", KERNEL=="sda1", NAME="wrong"
3e5958de
KS
1271EOF
1272 },
1273 {
1274 desc => "ENV{} test",
1275 subsys => "block",
1276 devpath => "/block/sda/sda1",
1277 exp_name => "true",
65005a7f
KS
1278 rules => <<EOF
1279BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong"
1280BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", NAME="true"
1281BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad"
3e5958de
KS
1282EOF
1283 },
1284 {
1285 desc => "ENV{} test",
1286 subsys => "block",
1287 devpath => "/block/sda/sda1",
1288 exp_name => "true",
65005a7f
KS
1289 rules => <<EOF
1290BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong"
1291BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sdax1", NAME="no"
1292BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sda1", NAME="true"
1293BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad"
5618b561
KS
1294EOF
1295 },
1296 {
1297 desc => "ENV{} test (assign)",
1298 subsys => "block",
1299 devpath => "/block/sda/sda1",
1300 exp_name => "true",
1301 rules => <<EOF
1302BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1303BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no"
1304BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", NAME="true"
1305BUS=="scsi", KERNEL=="sda1", NAME="bad"
1306EOF
1307 },
1308 {
1309 desc => "ENV{} test (assign2)",
1310 subsys => "block",
1311 devpath => "/block/sda/sda1",
1312 exp_name => "part",
1313 rules => <<EOF
1314SUBSYSTEM=="block", KERNEL="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1315SUBSYSTEM=="block", KERNEL="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1316ENV{MAINDEVICE}=="true", NAME="disk"
1317ENV{PARTITION}=="true", NAME="part"
1318NAME="bad"
18614ab2
KS
1319EOF
1320 },
1321 {
1322 desc => "untrusted string sanitize",
1323 subsys => "block",
1324 devpath => "/block/sda/sda1",
1325 exp_name => "sane",
1326 rules => <<EOF
1327BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT="name_ _/sbin/badprogram_", NAME="sane"
98bbc835
KS
1328EOF
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
1336KERNEL=="ttyUSB*", NAME="serial-%s{serial}"
db949b02
KS
1337EOF
1338 },
1339 {
1340 desc => "match against empty key string",
1341 subsys => "block",
1342 devpath => "/block/sda",
1343 exp_name => "ok",
1344 rules => <<EOF
1345KERNEL=="sda", SYSFS{nothing}!="", NAME="not-1-ok"
1346KERNEL=="sda", SYSFS{nothing}=="", NAME="not-2-ok"
1347KERNEL=="sda", SYSFS{vendor}!="", NAME="ok"
1348KERNEL=="sda", SYSFS{vendor}=="", NAME="not-3-ok"
821d0ec8
KS
1349EOF
1350 },
1351 {
1352 desc => "check ACTION value",
1353 subsys => "block",
1354 devpath => "/block/sda",
1355 exp_name => "ok",
1356 rules => <<EOF
1357ACTION=="unknown", KERNEL=="sda", NAME="unknown-not-ok"
1358ACTION=="add", KERNEL=="sda", NAME="ok"
1359EOF
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
1368KERNEL=="sda", NAME="ok"
1369KERNEL=="sda", NAME="not-ok"
1370KERNEL=="sda", SYMLINK+="link"
1371EOF
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
1382KERNEL=="sda", NAME="ok", RUN+="/bin/ln -s ok %r/testsymlink"
1383KERNEL=="sda", NAME="not-ok"
f040a4a2
KS
1384EOF
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
bf5d2964 1395KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'"
f040a4a2 1396KERNEL=="sda", NAME="not-ok"
821d0ec8
KS
1397EOF
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
1406KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2"
1407KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2"
1408KERNEL=="sda", NAME="not-ok2"
c974742b
KS
1409EOF
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
1418KERNEL=="sda", GROUP:="nobody"
1419KERNEL=="sda", GROUP="not-ok", MODE="0640", NAME="ok"
1420EOF
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
1429KERNEL=="sda", GROUP:="nobody"
1430SUBSYSTEM=="block", MODE:="640"
1431KERNEL=="sda", GROUP="not-ok", MODE="0666", NAME="ok"
bd0ed2ff
KS
1432EOF
1433 },
1434 {
1435 desc => "env substitution",
1436 subsys => "block",
1437 devpath => "/block/sda",
1438 exp_name => "node-add-me",
1439 rules => <<EOF
1440KERNEL=="sda", MODE="0666", NAME="node-\$env{ACTION}-me"
995aec87
KS
1441EOF
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
1451KERNEL=="ttyUSB[0-9]*", SYMLINK+="one"
1452KERNEL=="ttyUSB[0-9]*", SYMLINK+="two"
1453KERNEL=="ttyUSB[0-9]*", SYMLINK="three"
1454KERNEL=="ttyUSB[0-9]*", NAME="node"
a72e3f66
KS
1455EOF
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
1465KERNEL=="ttyUSB[0-9]*", NAME=""
1466KERNEL=="ttyUSB[0-9]*", NAME="wrong"
1467EOF
1468 },
1469 {
1470 desc => "test empty NAME 2",
1471 subsys => "tty",
1472 devpath => "/class/tty/ttyUSB0",
1473 exp_name => "right",
1474 rules => <<EOF
1475KERNEL=="ttyUSB[0-9]*", NAME="right"
1476KERNEL=="ttyUSB[0-9]*", NAME=""
1477KERNEL=="ttyUSB[0-9]*", NAME="wrong"
0cd4ac47
KS
1478EOF
1479 },
1480 {
1481 desc => "test multi matches",
1482 subsys => "tty",
1483 devpath => "/class/tty/ttyUSB0",
1484 exp_name => "right",
1485 rules => <<EOF
1486KERNEL=="ttyUSB*|nothing", NAME="right"
1487KERNEL=="ttyUSB*", NAME="wrong"
1488EOF
1489 },
1490 {
1491 desc => "test multi matches 2",
1492 subsys => "tty",
1493 devpath => "/class/tty/ttyUSB0",
1494 exp_name => "right",
1495 rules => <<EOF
1496KERNEL=="dontknow*|*nothing", NAME="nomatch"
1497KERNEL=="dontknow*|ttyUSB*|nothing*", NAME="right"
1498KERNEL=="ttyUSB*", NAME="wrong"
0bfb84e1
KS
1499EOF
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
1508KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1509KERNEL=="sda", NAME="parent"
1510EOF
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
1519KERNEL=="sda1", IMPORT{parent}="PARENT*", NAME="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
594dd610
KS
1520EOF
1521 },
1522 {
1523 desc => "GOTO test",
1524 subsys => "block",
1525 devpath => "/block/sda/sda1",
1526 exp_name => "right",
1527 rules => <<EOF
1528KERNEL=="sda1", GOTO="TEST"
1529KERNEL=="sda1", NAME="wrong"
1530KERNEL=="sda1", NAME="", LABEL="NO"
1531KERNEL=="sda1", NAME="right", LABEL="TEST"
1532KERNEL=="sda1", NAME="wrong2"
a367f04e
GKH
1533EOF
1534 },
1535);
1536
1537# set env
65005a7f 1538$ENV{ENV_KEY_TEST} = "test";
a367f04e 1539$ENV{SYSFS_PATH} = $sysfs;
65005a7f 1540$ENV{UDEV_CONFIG_FILE} = $udev_conf;
bbbe503e 1541$ENV{UDEV_NO_DEVD} = "yes";
16ac31aa 1542$ENV{UDEV_NO_HOTPLUGD} = "yes";
a367f04e
GKH
1543
1544
1545sub udev {
65005a7f 1546 my ($action, $subsys, $devpath, $rules) = @_;
a367f04e
GKH
1547
1548 $ENV{DEVPATH} = $devpath;
a367f04e 1549
65005a7f
KS
1550 # create temporary rules
1551 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1552 print CONF $$rules;
a367f04e
GKH
1553 close CONF;
1554
1555 $ENV{ACTION} = $action;
1556 system("$udev_bin $subsys");
1557}
1558
e5fbfe0a 1559my $error = 0;
72ffa78d 1560
b8669191 1561sub permissions_test {
65005a7f 1562 my($rules, $uid, $gid, $mode) = @_;
b8669191
GKH
1563
1564 my $wrong = 0;
9b434de1
KS
1565 my $userid;
1566 my $groupid;
1567
65005a7f 1568 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
b8669191 1569 if ($1 ne "") {
9b434de1
KS
1570 if (defined(getpwnam($1))) {
1571 $userid = int(getpwnam($1));
1572 } else {
1573 $userid = $1;
1574 }
1575 if ($uid != $userid) { $wrong = 1; }
b8669191
GKH
1576 }
1577 if ($2 ne "") {
9b434de1
KS
1578 if (defined(getgrnam($2))) {
1579 $groupid = int(getgrnam($2));
1580 } else {
1581 $groupid = $2;
1582 }
1583 if ($gid != $groupid) { $wrong = 1; }
b8669191
GKH
1584 }
1585 if ($3 ne "") {
1586 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1587 }
1588 if ($wrong == 0) {
9b434de1 1589 print "permissions: ok\n";
b8669191 1590 } else {
9b434de1
KS
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";
b8669191
GKH
1594 $error++;
1595 }
1596}
1597
1598sub major_minor_test {
65005a7f 1599 my($rules, $rdev) = @_;
b8669191
GKH
1600
1601 my $major = ($rdev >> 8) & 0xfff;
1602 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1603 my $wrong = 0;
1604
65005a7f 1605 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
b8669191
GKH
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) {
9b434de1 1613 print "major:minor: ok\n";
b8669191 1614 } else {
9b434de1
KS
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";
b8669191
GKH
1618 $error++;
1619 }
1620}
1621
1622sub symlink_test {
65005a7f 1623 my ($rules) = @_;
b8669191 1624
65005a7f 1625 my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`;
b8669191
GKH
1626
1627 if ($output =~ m/(.*)-> (.*)/) {
65005a7f 1628 if ($2 eq $rules->{exp_target}) {
9b434de1 1629 print "symlink: ok\n";
b8669191 1630 } else {
65005a7f
KS
1631 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
1632 print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n";
9b434de1 1633 print "symlink: error";
65005a7f 1634 if ($rules->{exp_add_error}) {
9b434de1 1635 print " as expected\n";
b8669191 1636 } else {
9b434de1 1637 print "\n";
b8669191
GKH
1638 $error++;
1639 }
1640 }
1641 } else {
65005a7f 1642 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
9b434de1 1643 print "symlink: not created";
65005a7f 1644 if ($rules->{exp_add_error}) {
9b434de1 1645 print " as expected\n";
b8669191 1646 } else {
9b434de1 1647 print "\n";
b8669191
GKH
1648 $error++;
1649 }
1650 }
1651}
1652
2e317184 1653sub run_test {
65005a7f 1654 my ($rules, $number) = @_;
fa19f181 1655
65005a7f 1656 print "TEST $number: $rules->{desc}\n";
b8669191 1657
65005a7f
KS
1658 if ($rules->{exp_target}) {
1659 print "device \'$rules->{devpath}\' expecting symlink '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
b8669191 1660 } else {
65005a7f 1661 print "device \'$rules->{devpath}\' expecting node \'$rules->{exp_name}\'\n";
b8669191
GKH
1662 }
1663
a367f04e 1664
65005a7f
KS
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}")) {
fa19f181
KS
1668
1669 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
65005a7f 1670 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}");
fa19f181 1671
995aec87
KS
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 }
65005a7f
KS
1679 if (defined($rules->{exp_perms})) {
1680 permissions_test($rules, $uid, $gid, $mode);
c612a0ac 1681 }
65005a7f
KS
1682 if (defined($rules->{exp_majorminor})) {
1683 major_minor_test($rules, $rdev);
b8669191 1684 }
65005a7f
KS
1685 if (defined($rules->{exp_target})) {
1686 symlink_test($rules);
fa19f181 1687 }
9b434de1 1688 print "add: ok\n";
a367f04e 1689 } else {
9b434de1 1690 print "add: error";
65005a7f 1691 if ($rules->{exp_add_error}) {
9b434de1 1692 print " as expected\n";
b8669191 1693 } else {
9b434de1 1694 print "\n";
b8669191
GKH
1695 system("tree $udev_root");
1696 print "\n";
1697 $error++;
1698 }
a367f04e
GKH
1699 }
1700
65005a7f 1701 if (defined($rules->{option}) && $rules->{option} eq "keep") {
0345b862
KS
1702 print "\n\n";
1703 return;
1704 }
1705
65005a7f
KS
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}")) {
9b434de1 1709 print "remove: error";
65005a7f 1710 if ($rules->{exp_rem_error}) {
9b434de1 1711 print " as expected\n";
b8669191 1712 } else {
9b434de1 1713 print "\n";
b8669191
GKH
1714 system("tree $udev_root");
1715 print "\n";
1716 $error++;
1717 }
a367f04e 1718 } else {
9b434de1 1719 print "remove: ok\n";
a367f04e 1720 }
0345b862 1721
9b434de1
KS
1722 print "\n";
1723
db949b02 1724 if (defined($rules->{option}) && $rules->{option} eq "clean") {
2b41e68a 1725 system("rm -rf $udev_db");
0345b862
KS
1726 system("rm -rf $udev_root");
1727 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1728 }
1729
a367f04e
GKH
1730}
1731
800ab95b
GKH
1732# only run if we have root permissions
1733# due to mknod restrictions
1734if (!($<==0)) {
1735 print "Must have root permissions to run properly.\n";
1736 exit;
1737}
1738
2e317184
GKH
1739# prepare
1740system("rm -rf $udev_root");
1741mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1742
65005a7f
KS
1743# create config file
1744open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
2e317184
GKH
1745print CONF "udev_root=\"$udev_root\"\n";
1746print CONF "udev_db=\"$udev_db\"\n";
65005a7f 1747print CONF "udev_rules=\"$udev_rules\"\n";
2e317184
GKH
1748close CONF;
1749
1750my $test_num = 1;
1751
1752if ($ARGV[0]) {
1753 # only run one test
1754 $test_num = $ARGV[0];
2e317184 1755
0345b862
KS
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 }
2e317184
GKH
1762} else {
1763 # test all
1764 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1765
65005a7f
KS
1766 foreach my $rules (@tests) {
1767 run_test($rules, $test_num);
2e317184 1768 $test_num++;
2e317184
GKH
1769 }
1770}
1771
a367f04e
GKH
1772print "$error errors occured\n\n";
1773
1774# cleanup
2b41e68a 1775system("rm -rf $udev_db");
a367f04e 1776system("rm -rf $udev_root");
65005a7f
KS
1777unlink($udev_rules);
1778unlink($udev_conf);
a367f04e 1779