]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/udev-test.pl
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.
9 # Every test is driven by its own temporary config file.
10 # This program prepares the environment, creates the config and calls udev.
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.
17 # Copyright © 2004 Leann Ogasawara <ogasawara@osdl.org>
22 my $udev_bin = "./test-udev";
26 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin";
27 my $udev_bin_gdb = "gdb --args $udev_bin";
28 my $udev_bin_strace = "strace -efile $udev_bin";
29 my $udev_run = "test/run";
30 my $udev_tmpfs = "test/tmpfs";
31 my $udev_sys = "${udev_tmpfs}/sys";
32 my $udev_dev = "${udev_tmpfs}/dev";
33 my $udev_rules_dir = "$udev_run/udev/rules.d";
34 my $udev_rules = "$udev_rules_dir/udev-test.rules";
35 my $EXIT_TEST_SKIP = 77;
37 my $rules_10k_tags = "";
38 for (my $i = 1; $i <= 10000; ++$i) {
39 $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n";
42 my $rules_10k_tags_continuation = "KERNEL==\"sda\", \\\n";
43 for (my $i = 1; $i < 10000; ++$i) {
44 $rules_10k_tags_continuation .= 'TAG+="test' . $i . "\",\\\n";
46 $rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n";
51 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
53 exp_rem_error
=> "yes",
59 desc
=> "label test of scsi disc",
60 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
61 exp_name
=> "boot_disk",
63 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
64 KERNEL=="ttyACM0", SYMLINK+="modem"
68 desc
=> "label test of scsi disc",
69 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
70 exp_name
=> "boot_disk",
72 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
73 KERNEL=="ttyACM0", SYMLINK+="modem"
77 desc
=> "label test of scsi disc",
78 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
79 exp_name
=> "boot_disk",
81 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
82 KERNEL=="ttyACM0", SYMLINK+="modem"
86 desc
=> "label test of scsi partition",
87 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
88 exp_name
=> "boot_disk1",
90 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
94 desc
=> "label test of pattern match",
95 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
96 exp_name
=> "boot_disk1",
98 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
99 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
100 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
101 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
105 desc
=> "label test of multiple sysfs files",
106 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
107 exp_name
=> "boot_disk1",
109 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
110 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
114 desc
=> "label test of max sysfs files (skip invalid rule)",
115 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
116 exp_name
=> "boot_disk1",
118 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", ATTRS{queue_depth}=="32", SYMLINK+="boot_diskXX%n"
119 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
123 desc
=> "catch device by *",
124 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
125 exp_name
=> "modem/0",
127 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
131 desc
=> "catch device by * - take 2",
132 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
133 exp_name
=> "modem/0",
135 KERNEL=="*ACM1", SYMLINK+="bad"
136 KERNEL=="*ACM0", SYMLINK+="modem/%n"
140 desc
=> "catch device by ?",
141 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
142 exp_name
=> "modem/0",
144 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
145 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
146 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
150 desc
=> "catch device by character class",
151 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
152 exp_name
=> "modem/0",
154 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
155 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
156 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
160 desc
=> "replace kernel name",
161 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
164 KERNEL=="ttyACM0", SYMLINK+="modem"
168 desc
=> "Handle comment lines in config file (and replace kernel name)",
169 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
173 KERNEL=="ttyACM0", SYMLINK+="modem"
178 desc
=> "Handle comment lines in config file with whitespace (and replace kernel name)",
179 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
182 # this is a comment with whitespace before the comment
183 KERNEL=="ttyACM0", SYMLINK+="modem"
188 desc
=> "Handle whitespace only lines (and replace kernel name)",
189 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
190 exp_name
=> "whitespace",
195 # this is a comment with whitespace before the comment
196 KERNEL=="ttyACM0", SYMLINK+="whitespace"
203 desc
=> "Handle empty lines in config file (and replace kernel name)",
204 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
208 KERNEL=="ttyACM0", SYMLINK+="modem"
213 desc
=> "Handle backslashed multi lines in config file (and replace kernel name)",
214 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
217 KERNEL=="ttyACM0", \\
223 desc
=> "preserve backslashes, if they are not for a newline",
224 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
227 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
231 desc
=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
232 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
243 KERNEL=="ttyACM0", \\
249 desc
=> "subdirectory handling",
250 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
251 exp_name
=> "sub/direct/ory/modem",
253 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
257 desc
=> "parent device name match of scsi partition",
258 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
259 exp_name
=> "first_disk5",
261 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
265 desc
=> "test substitution chars",
266 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
267 exp_name
=> "Major:8:minor:5:kernelnumber:5:id:0:0:0:0",
269 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
273 desc
=> "import of shell-value returned from program",
274 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
275 exp_name
=> "node12345678",
277 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
278 KERNEL=="ttyACM0", SYMLINK+="modem"
282 desc
=> "substitution of sysfs value (%s{file})",
283 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
284 exp_name
=> "disk-ATA-sda",
286 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
287 KERNEL=="ttyACM0", SYMLINK+="modem"
291 desc
=> "program result substitution",
292 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
293 exp_name
=> "special-device-5",
294 not_exp_name
=> "not",
296 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
297 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
301 desc
=> "program result substitution (newline removal)",
302 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
303 exp_name
=> "newline_removed",
305 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
309 desc
=> "program result substitution",
310 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
311 exp_name
=> "test-0:0:0:0",
313 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
317 desc
=> "program with lots of arguments",
318 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
321 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
325 desc
=> "program with subshell",
326 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
329 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
333 desc
=> "program arguments combined with apostrophes",
334 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
337 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
341 desc
=> "program arguments combined with escaped double quotes, part 1",
342 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
345 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
349 desc
=> "program arguments combined with escaped double quotes, part 2",
350 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
353 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}"
357 desc
=> "program arguments combined with escaped double quotes, part 3",
358 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
361 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
365 desc
=> "characters before the %c{N} substitution",
366 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
367 exp_name
=> "my-foo9",
369 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
373 desc
=> "substitute the second to last argument",
374 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
375 exp_name
=> "my-foo8",
377 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
381 desc
=> "test substitution by variable name",
382 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
383 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
385 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
389 desc
=> "test substitution by variable name 2",
390 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
391 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
393 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
397 desc
=> "test substitution by variable name 3",
398 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
399 exp_name
=> "850:0:0:05",
401 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
405 desc
=> "test substitution by variable name 4",
406 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
409 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
413 desc
=> "test substitution by variable name 5",
414 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
415 exp_name
=> "8550:0:0:0",
417 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
421 desc
=> "non matching SUBSYSTEMS for device with no parent",
422 devpath
=> "/devices/virtual/tty/console",
425 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
426 KERNEL=="console", SYMLINK+="TTY"
430 desc
=> "non matching SUBSYSTEMS",
431 devpath
=> "/devices/virtual/tty/console",
434 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
435 KERNEL=="console", SYMLINK+="TTY"
439 desc
=> "ATTRS match",
440 devpath
=> "/devices/virtual/tty/console",
443 KERNEL=="console", SYMLINK+="TTY"
444 ATTRS{dev}=="5:1", SYMLINK+="foo"
448 desc
=> "ATTR (empty file)",
449 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
452 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
453 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
454 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
455 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
459 desc
=> "ATTR (non-existent file)",
460 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
461 exp_name
=> "non-existent",
463 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
464 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
465 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
466 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
467 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
468 KERNEL=="sda", SYMLINK+="wrong"
472 desc
=> "program and bus type match",
473 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
474 exp_name
=> "scsi-0:0:0:0",
476 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
477 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
478 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
482 desc
=> "sysfs parent hierarchy",
483 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
486 ATTRS{idProduct}=="007b", SYMLINK+="modem"
490 desc
=> "name test with ! in the name",
491 devpath
=> "/devices/virtual/block/fake!blockdev0",
492 exp_name
=> "is/a/fake/blockdev0",
494 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
495 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
496 KERNEL=="ttyACM0", SYMLINK+="modem"
500 desc
=> "name test with ! in the name, but no matching rule",
501 devpath
=> "/devices/virtual/block/fake!blockdev0",
502 exp_name
=> "fake/blockdev0",
503 exp_rem_error
=> "yes",
505 KERNEL=="ttyACM0", SYMLINK+="modem"
509 desc
=> "KERNELS rule",
510 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
511 exp_name
=> "scsi-0:0:0:0",
513 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
514 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
515 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
516 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
517 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
521 desc
=> "KERNELS wildcard all",
522 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
523 exp_name
=> "scsi-0:0:0:0",
525 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
526 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
527 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
528 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
529 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
533 desc
=> "KERNELS wildcard partial",
534 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
535 exp_name
=> "scsi-0:0:0:0",
537 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
538 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
542 desc
=> "KERNELS wildcard partial 2",
543 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
544 exp_name
=> "scsi-0:0:0:0",
546 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
547 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
551 desc
=> "substitute attr with link target value (first match)",
552 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
553 exp_name
=> "driver-is-sd",
555 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
559 desc
=> "substitute attr with link target value (currently selected device)",
560 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
561 exp_name
=> "driver-is-ahci",
563 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
567 desc
=> "ignore ATTRS attribute whitespace",
568 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
569 exp_name
=> "ignored",
571 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
575 desc
=> "do not ignore ATTRS attribute whitespace",
576 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
577 exp_name
=> "matched-with-space",
579 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
580 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
584 desc
=> "permissions USER=bad GROUP=name",
585 devpath
=> "/devices/virtual/tty/tty33",
587 exp_perms
=> "0:0:0600",
589 KERNEL=="tty33", OWNER="bad", GROUP="name"
593 desc
=> "permissions OWNER=1",
594 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
596 exp_perms
=> "1::0600",
598 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
602 desc
=> "permissions GROUP=1",
603 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
605 exp_perms
=> ":1:0660",
607 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
611 desc
=> "textual user id",
612 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
614 exp_perms
=> "daemon::0600",
616 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="daemon"
620 desc
=> "textual group id",
621 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
623 exp_perms
=> ":daemon:0660",
625 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
629 desc
=> "textual user/group id",
630 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
632 exp_perms
=> "root:mail:0660",
634 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
638 desc
=> "permissions MODE=0777",
639 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
641 exp_perms
=> "::0777",
643 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
647 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
648 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
650 exp_perms
=> "1:1:0777",
652 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
656 desc
=> "permissions OWNER to 1",
657 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
658 exp_name
=> "ttyACM0",
661 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
665 desc
=> "permissions GROUP to 1",
666 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
667 exp_name
=> "ttyACM0",
668 exp_perms
=> ":1:0660",
670 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
674 desc
=> "permissions MODE to 0060",
675 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
676 exp_name
=> "ttyACM0",
677 exp_perms
=> "::0060",
679 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
683 desc
=> "permissions OWNER, GROUP, MODE",
684 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
685 exp_name
=> "ttyACM0",
686 exp_perms
=> "1:1:0777",
688 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
692 desc
=> "permissions only rule",
693 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
694 exp_name
=> "ttyACM0",
695 exp_perms
=> "1:1:0777",
697 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
698 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
699 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
703 desc
=> "multiple permissions only rule",
704 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
705 exp_name
=> "ttyACM0",
706 exp_perms
=> "1:1:0777",
708 SUBSYSTEM=="tty", OWNER="1"
709 SUBSYSTEM=="tty", GROUP="1"
710 SUBSYSTEM=="tty", MODE="0777"
711 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
712 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
716 desc
=> "permissions only rule with override at SYMLINK+ rule",
717 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
718 exp_name
=> "ttyACM0",
719 exp_perms
=> "1:2:0777",
721 SUBSYSTEM=="tty", OWNER="1"
722 SUBSYSTEM=="tty", GROUP="1"
723 SUBSYSTEM=="tty", MODE="0777"
724 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
725 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
729 desc
=> "major/minor number test",
730 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
732 exp_majorminor
=> "8:0",
734 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
738 desc
=> "big major number test",
739 devpath
=> "/devices/virtual/misc/misc-fake1",
741 exp_majorminor
=> "4095:1",
743 KERNEL=="misc-fake1", SYMLINK+="node"
747 desc
=> "big major and big minor number test",
748 devpath
=> "/devices/virtual/misc/misc-fake89999",
750 exp_majorminor
=> "4095:89999",
752 KERNEL=="misc-fake89999", SYMLINK+="node"
756 desc
=> "multiple symlinks with format char",
757 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
758 exp_name
=> "symlink2-ttyACM0",
760 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
764 desc
=> "multiple symlinks with a lot of s p a c e s",
765 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
769 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
773 desc
=> "symlink with spaces in substituted variable",
774 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
775 exp_name
=> "name-one_two_three-end",
778 ENV{WITH_WS}="one two three"
779 SYMLINK="name-\$env{WITH_WS}-end"
783 desc
=> "symlink with leading space in substituted variable",
784 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
785 exp_name
=> "name-one_two_three-end",
788 ENV{WITH_WS}=" one two three"
789 SYMLINK="name-\$env{WITH_WS}-end"
793 desc
=> "symlink with trailing space in substituted variable",
794 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
795 exp_name
=> "name-one_two_three-end",
798 ENV{WITH_WS}="one two three "
799 SYMLINK="name-\$env{WITH_WS}-end"
803 desc
=> "symlink with lots of space in substituted variable",
804 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
805 exp_name
=> "name-one_two_three-end",
808 ENV{WITH_WS}=" one two three "
809 SYMLINK="name-\$env{WITH_WS}-end"
813 desc
=> "symlink with multiple spaces in substituted variable",
814 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
815 exp_name
=> "name-one_two_three-end",
818 ENV{WITH_WS}=" one two three "
819 SYMLINK="name-\$env{WITH_WS}-end"
823 desc
=> "symlink with space and var with space, part 1",
824 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
828 ENV{WITH_WS}=" one two three "
829 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
833 desc
=> "symlink with space and var with space, part 2",
834 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
835 exp_name
=> "name-one_two_three-end",
838 ENV{WITH_WS}=" one two three "
839 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
843 desc
=> "symlink with space and var with space, part 3",
844 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
845 exp_name
=> "another_symlink",
848 ENV{WITH_WS}=" one two three "
849 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
853 desc
=> "symlink creation (same directory)",
854 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
855 exp_name
=> "modem0",
857 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
861 desc
=> "multiple symlinks",
862 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
863 exp_name
=> "second-0",
865 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
869 desc
=> "symlink name '.'",
870 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
872 exp_add_error
=> "yes",
873 exp_rem_error
=> "yes",
875 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
879 desc
=> "symlink node to itself",
880 devpath
=> "/devices/virtual/tty/tty0",
882 exp_add_error
=> "yes",
883 exp_rem_error
=> "yes",
886 KERNEL=="tty0", SYMLINK+="tty0"
890 desc
=> "symlink %n substitution",
891 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
892 exp_name
=> "symlink0",
894 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
898 desc
=> "symlink %k substitution",
899 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
900 exp_name
=> "symlink-ttyACM0",
902 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
906 desc
=> "symlink %M:%m substitution",
907 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
908 exp_name
=> "major-166:0",
910 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
914 desc
=> "symlink %b substitution",
915 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
916 exp_name
=> "symlink-0:0:0:0",
918 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
922 desc
=> "symlink %c substitution",
923 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
926 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
930 desc
=> "symlink %c{N} substitution",
931 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
934 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
938 desc
=> "symlink %c{N+} substitution",
939 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
942 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
946 desc
=> "symlink only rule with %c{N+}",
947 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
950 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
954 desc
=> "symlink %s{filename} substitution",
955 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
958 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
962 desc
=> "program result substitution (numbered part of)",
963 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
966 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
970 desc
=> "program result substitution (numbered part of+)",
971 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
974 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
978 desc
=> "SUBSYSTEM match test",
979 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
982 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
983 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
984 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
988 desc
=> "DRIVERS match test",
989 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
992 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
993 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
997 desc
=> "devnode substitution test",
998 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1001 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1005 desc
=> "parent node name substitution test",
1006 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1007 exp_name
=> "sda-part-1",
1009 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1013 desc
=> "udev_root substitution",
1014 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1015 exp_name
=> "start-/dev-end",
1017 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1021 desc
=> "last_rule option",
1022 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1025 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1026 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1030 desc
=> "negation KERNEL!=",
1031 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1032 exp_name
=> "match",
1034 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1035 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1036 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1040 desc
=> "negation SUBSYSTEM!=",
1041 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1042 exp_name
=> "not-anything",
1044 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1045 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1046 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1050 desc
=> "negation PROGRAM!= exit code",
1051 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1052 exp_name
=> "nonzero-program",
1054 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1055 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1059 desc
=> "ENV{} test",
1060 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1063 ENV{ENV_KEY_TEST}="test"
1064 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1065 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1066 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1070 desc
=> "ENV{} test",
1071 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1074 ENV{ENV_KEY_TEST}="test"
1075 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1076 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1077 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1078 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1082 desc
=> "ENV{} test (assign)",
1083 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1086 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1087 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1088 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1089 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1093 desc
=> "ENV{} test (assign 2 times)",
1094 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1097 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1098 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1099 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1100 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1101 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1105 desc
=> "ENV{} test (assign2)",
1106 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1109 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1110 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1111 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1112 SUBSYSTEM=="block", SYMLINK+="before"
1113 ENV{PARTITION}=="true", SYMLINK+="part"
1117 desc
=> "untrusted string sanitize",
1118 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1121 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1125 desc
=> "untrusted string sanitize (don't replace utf8)",
1126 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1129 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1133 desc
=> "untrusted string sanitize (replace invalid utf8)",
1134 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1135 exp_name
=> "replaced",
1137 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1141 desc
=> "read sysfs value from parent device",
1142 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1143 exp_name
=> "serial-354172020305000",
1145 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1149 desc
=> "match against empty key string",
1150 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1153 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1154 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1155 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1156 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1160 desc
=> "check ACTION value",
1161 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1164 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1165 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1169 desc
=> "final assignment",
1170 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1172 exp_perms
=> "root:tty:0640",
1174 KERNEL=="sda", GROUP:="tty"
1175 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1179 desc
=> "final assignment 2",
1180 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1182 exp_perms
=> "root:tty:0640",
1184 KERNEL=="sda", GROUP:="tty"
1185 SUBSYSTEM=="block", MODE:="640"
1186 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1190 desc
=> "env substitution",
1191 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1192 exp_name
=> "node-add-me",
1194 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1198 desc
=> "reset list to current value",
1199 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1200 exp_name
=> "three",
1201 not_exp_name
=> "two",
1203 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1204 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1205 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1209 desc
=> "test empty SYMLINK+ (empty override)",
1210 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1211 exp_name
=> "right",
1212 not_exp_name
=> "wrong",
1214 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1215 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1216 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1220 desc
=> "test multi matches",
1221 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1222 exp_name
=> "right",
1224 KERNEL=="ttyACM*", SYMLINK+="before"
1225 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1229 desc
=> "test multi matches 2",
1230 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1231 exp_name
=> "right",
1233 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1234 KERNEL=="ttyACM*", SYMLINK+="before"
1235 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1239 desc
=> "test multi matches 3",
1240 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1241 exp_name
=> "right",
1243 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1244 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1245 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1246 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1250 desc
=> "test multi matches 4",
1251 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1252 exp_name
=> "right",
1254 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1255 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1256 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1257 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1258 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1262 desc
=> "test multi matches 5",
1263 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1264 exp_name
=> "found",
1265 not_exp_name
=> "bad",
1267 KERNEL=="sda", TAG="foo"
1268 TAGS=="|foo", SYMLINK+="found"
1269 TAGS=="|aaa", SYMLINK+="bad"
1273 desc
=> "test multi matches 6",
1274 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1275 exp_name
=> "found",
1276 not_exp_name
=> "bad",
1278 KERNEL=="sda", TAG=""
1279 TAGS=="|foo", SYMLINK+="found"
1280 TAGS=="aaa|bbb", SYMLINK+="bad"
1284 desc
=> "test multi matches 7",
1285 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1286 exp_name
=> "found",
1287 not_exp_name
=> "bad",
1289 KERNEL=="sda", TAG="foo"
1290 TAGS=="foo||bar", SYMLINK+="found"
1291 TAGS=="aaa||bbb", SYMLINK+="bad"
1295 desc
=> "test multi matches 8",
1296 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1297 exp_name
=> "found",
1298 not_exp_name
=> "bad",
1300 KERNEL=="sda", TAG=""
1301 TAGS=="foo||bar", SYMLINK+="found"
1302 TAGS=="aaa|bbb", SYMLINK+="bad"
1306 desc
=> "test multi matches 9",
1307 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1308 exp_name
=> "found",
1309 not_exp_name
=> "bad",
1311 KERNEL=="sda", TAG="foo"
1312 TAGS=="foo|", SYMLINK+="found"
1313 TAGS=="aaa|", SYMLINK+="bad"
1317 desc
=> "test multi matches 10",
1318 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1319 exp_name
=> "found",
1320 not_exp_name
=> "bad",
1322 KERNEL=="sda", TAG=""
1323 TAGS=="foo|", SYMLINK+="found"
1324 TAGS=="aaa|bbb", SYMLINK+="bad"
1328 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1329 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1330 exp_name
=> "parent",
1333 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1334 KERNEL=="sda", SYMLINK+="parent"
1338 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1339 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1340 exp_name
=> "parentenv-parent_right",
1343 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1347 desc
=> "GOTO test",
1348 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1349 exp_name
=> "right",
1351 KERNEL=="sda1", GOTO="TEST"
1352 KERNEL=="sda1", SYMLINK+="wrong"
1353 KERNEL=="sda1", GOTO="BAD"
1354 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1355 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1356 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1361 desc
=> "GOTO label does not exist",
1362 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1363 exp_name
=> "right",
1365 KERNEL=="sda1", GOTO="does-not-exist"
1366 KERNEL=="sda1", SYMLINK+="right",
1371 desc
=> "SYMLINK+ compare test",
1372 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1373 exp_name
=> "right",
1374 not_exp_name
=> "wrong",
1376 KERNEL=="sda1", SYMLINK+="link"
1377 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1378 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1382 desc
=> "invalid key operation",
1383 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1386 KERNEL="sda1", SYMLINK+="no"
1387 KERNEL=="sda1", SYMLINK+="yes"
1391 desc
=> "operator chars in attribute",
1392 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1395 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1399 desc
=> "overlong comment line",
1400 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1403 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1404 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1405 KERNEL=="sda1", SYMLINK+=="no"
1406 KERNEL=="sda1", SYMLINK+="yes"
1410 desc
=> "magic subsys/kernel lookup",
1411 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1412 exp_name
=> "00:16:41:e2:8d:ff",
1414 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1418 desc
=> "TEST absolute path",
1419 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1420 exp_name
=> "there",
1422 TEST=="/etc/machine-id", SYMLINK+="there"
1423 TEST!="/etc/machine-id", SYMLINK+="notthere"
1427 desc
=> "TEST subsys/kernel lookup",
1428 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1431 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1435 desc
=> "TEST relative path",
1436 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1437 exp_name
=> "relative",
1439 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1443 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1444 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1445 exp_name
=> "found-subdir",
1447 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1451 desc
=> "TEST MODE=0000",
1452 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1454 exp_perms
=> "0:0:0000",
1455 exp_rem_error
=> "yes",
1457 KERNEL=="sda", MODE="0000"
1461 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1462 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1464 exp_perms
=> "1:1:0400",
1465 exp_rem_error
=> "yes",
1467 KERNEL=="sda", MODE="666"
1468 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1472 desc
=> "TEST PROGRAM feeds MODE with overflow",
1473 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1475 exp_perms
=> "0:0:0440",
1476 exp_rem_error
=> "yes",
1478 KERNEL=="sda", MODE="440"
1479 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1483 desc
=> "magic [subsys/sysname] attribute substitution",
1484 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1485 exp_name
=> "sda-8741C4G-end",
1486 exp_perms
=> "0:0:0600",
1488 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1489 KERNEL=="sda", ENV{TESTENV}="change-envp"
1490 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1494 desc
=> "builtin path_id",
1495 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1496 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1498 KERNEL=="sda", IMPORT{builtin}="path_id"
1499 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1503 desc
=> "add and match tag",
1504 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1505 exp_name
=> "found",
1506 not_exp_name
=> "bad",
1508 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1509 TAGS=="green", SYMLINK+="found"
1510 TAGS=="blue", SYMLINK+="bad"
1514 desc
=> "don't crash with lots of tags",
1515 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1516 exp_name
=> "found",
1517 rules
=> $rules_10k_tags . <<EOF
1518 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
1522 desc
=> "continuations",
1523 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1524 exp_name
=> "found",
1525 not_exp_name
=> "bad",
1526 rules
=> $rules_10k_tags_continuation . <<EOF
1527 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="bad"
1529 # comment in continuation
1531 # space before comment
1533 # spaces before and after token are dropped
1538 TAGS=="hoge1", TAGS=="hoge2", TAGS=="hoge3", TAGS=="hoge4", SYMLINK+="found"
1542 desc
=> "continuations with empty line",
1543 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1544 exp_name
=> "found",
1545 not_exp_name
=> "bad",
1547 # empty line finishes continuation
1548 KERNEL=="sda", TAG+="foo" \\
1550 KERNEL=="sdb", TAG+="hoge"
1551 KERNEL=="sda", TAG+="aaa" \\
1552 KERNEL=="sdb", TAG+="bbb"
1553 TAGS=="foo", SYMLINK+="found"
1554 TAGS=="aaa", SYMLINK+="bad"
1558 desc
=> "continuations with white only line",
1559 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1560 exp_name
=> "found",
1561 not_exp_name
=> "bad",
1563 # space only line finishes continuation
1564 KERNEL=="sda", TAG+="foo" \\
1566 KERNEL=="sdb", TAG+="hoge"
1567 KERNEL=="sda", TAG+="aaa" \\
1568 KERNEL=="sdb", TAG+="bbb"
1569 TAGS=="foo", SYMLINK+="found"
1570 TAGS=="aaa", SYMLINK+="bad"
1576 my ($action, $devpath, $rules) = @_;
1578 # create temporary rules
1579 system("mkdir", "-p", "$udev_rules_dir");
1580 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1584 if ($valgrind > 0) {
1585 return system("$udev_bin_valgrind $action $devpath");
1586 } elsif ($gdb > 0) {
1587 return system("$udev_bin_gdb $action $devpath");
1588 } elsif ($strace > 0) {
1589 return system("$udev_bin_strace $action $devpath");
1591 return system("$udev_bin", "$action", "$devpath");
1597 sub permissions_test
{
1598 my($rules, $uid, $gid, $mode) = @_;
1604 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1606 if (defined(getpwnam($1))) {
1607 $userid = int(getpwnam($1));
1611 if ($uid != $userid) { $wrong = 1; }
1614 if (defined(getgrnam($2))) {
1615 $groupid = int(getgrnam($2));
1619 if ($gid != $groupid) { $wrong = 1; }
1622 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1625 print "permissions: ok\n";
1627 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1628 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1629 print "permissions: error\n";
1635 sub major_minor_test
{
1636 my($rules, $rdev) = @_;
1638 my $major = ($rdev >> 8) & 0xfff;
1639 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1642 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1644 if ($major != $1) { $wrong = 1; };
1647 if ($minor != $2) { $wrong = 1; };
1650 print "major:minor: ok\n";
1652 printf " expected major:minor is: %i:%i\n", $1, $2;
1653 printf " created major:minor is : %i:%i\n", $major, $minor;
1654 print "major:minor: error\n";
1661 system("umount", $udev_tmpfs);
1663 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
1665 if (system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) {
1666 warn "unable to mount tmpfs";
1670 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1671 # setting group and mode of udev_dev ensures the tests work
1672 # even if the parent directory has setgid bit enabled.
1673 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1674 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1676 if (system("mknod", $udev_dev . "/null", "c", "1", "3")) {
1677 warn "unable to create $udev_dev/null";
1681 # check if we are permitted to create block device nodes
1682 my $block_device_filename = $udev_dev . "/sda";
1683 if (system("mknod", $block_device_filename, "b", "8", "0")) {
1684 warn "unable to create $block_device_filename";
1687 unlink $block_device_filename;
1689 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
1691 system("rm", "-rf", "$udev_run");
1693 if (!mkdir($udev_run)) {
1694 warn "unable to create directory $udev_run";
1702 my ($rules, $number) = @_;
1705 print "TEST $number: $rules->{desc}\n";
1706 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1708 $rc = udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1710 print "$udev_bin add failed with code $rc\n";
1713 if (defined($rules->{not_exp_name
})) {
1714 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1715 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1716 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1722 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1723 (-l
"$udev_dev/$rules->{exp_name}")) {
1725 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1726 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1728 if (defined($rules->{exp_perms
})) {
1729 permissions_test
($rules, $uid, $gid, $mode);
1731 if (defined($rules->{exp_majorminor
})) {
1732 major_minor_test
($rules, $rdev);
1737 if ($rules->{exp_add_error
}) {
1738 print " as expected\n";
1741 system("tree", "$udev_dev");
1748 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1753 $rc = udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1755 print "$udev_bin remove failed with code $rc\n";
1758 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1759 (-l
"$udev_dev/$rules->{exp_name}")) {
1760 print "remove: error";
1761 if ($rules->{exp_rem_error
}) {
1762 print " as expected\n";
1765 system("tree", "$udev_dev");
1771 print "remove: ok\n";
1776 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1783 system("rm", "-rf", "$udev_run");
1784 system("umount", "$udev_tmpfs");
1788 # only run if we have root permissions
1789 # due to mknod restrictions
1791 print "Must have root permissions to run properly.\n";
1792 exit($EXIT_TEST_SKIP);
1795 # skip the test when running in a chroot
1796 system("systemd-detect-virt", "-r", "-q");
1798 print "Running in a chroot, skipping the test.\n";
1799 exit($EXIT_TEST_SKIP);
1802 if (!udev_setup
()) {
1803 warn "Failed to set up the environment, skipping the test";
1805 exit($EXIT_TEST_SKIP);
1808 if (system($udev_bin, "check")) {
1809 warn "$udev_bin failed to set up the environment, skipping the test";
1811 exit($EXIT_TEST_SKIP);
1817 foreach my $arg (@ARGV) {
1818 if ($arg =~ m/--valgrind/) {
1820 printf("using valgrind\n");
1821 } elsif ($arg =~ m/--gdb/) {
1823 printf("using gdb\n");
1824 } elsif ($arg =~ m/--strace/) {
1826 printf("using strace\n");
1833 foreach my $arg (@list) {
1834 if (defined($tests[$arg-1]->{desc
})) {
1835 print "udev-test will run test number $arg:\n\n";
1836 run_test
($tests[$arg-1], $arg);
1838 print "test does not exist.\n";
1843 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1845 foreach my $rules (@tests) {
1846 run_test
($rules, $test_num);
1851 print "$error errors occurred\n\n";