]>
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>
21 use POSIX
qw(WIFEXITED WEXITSTATUS);
22 use IPC
::SysV
qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
24 use Time
::HiRes
qw(usleep);
25 use Cwd
qw(getcwd abs_path);
27 my $udev_bin = "./test-udev";
31 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin";
32 my $udev_bin_gdb = "gdb --args $udev_bin";
33 my $udev_bin_strace = "strace -efile $udev_bin";
34 my $udev_run = "test/run";
35 my $udev_tmpfs = "test/tmpfs";
36 my $udev_sys = "${udev_tmpfs}/sys";
37 my $udev_dev = "${udev_tmpfs}/dev";
38 my $udev_rules_dir = "$udev_run/udev/rules.d";
39 my $udev_rules = "$udev_rules_dir/udev-test.rules";
40 my $EXIT_TEST_SKIP = 77;
42 my $rules_10k_tags = "";
43 for (my $i = 1; $i <= 10000; ++$i) {
44 $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n";
47 my $rules_10k_tags_continuation = "KERNEL==\"sda\", \\\n";
48 for (my $i = 1; $i < 10000; ++$i) {
49 $rules_10k_tags_continuation .= 'TAG+="test' . $i . "\",\\\n";
51 $rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n";
53 # Create a device list with all block devices under /sys
54 # (except virtual devices and cd-roms)
55 # the optional argument exp_func returns expected and non-expected
56 # symlinks for the device.
61 foreach my $bd (glob "$udev_sys/dev/block/*") {
62 my $tgt = readlink($bd);
63 my ($exp, $notexp) = (undef, undef);
65 next if ($tgt =~ m!/virtual/! || $tgt =~ m!/sr[0-9]*$!);
67 $tgt =~ s!^\.\./\.\.!!;
68 ($exp, $notexp) = $exp_func->($tgt) if defined($exp_func);
72 not_exp_links
=> $notexp,
74 push(@devices, $device);
79 # This generator returns a suitable exp_func for use with
82 my ($pattern, $links, $donot) = @_;
86 if ($name =~ /$pattern/) {
87 return ($links, undef);
89 return (undef, $links);
91 return (undef, undef);
102 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
103 exp_rem_error
=> "yes",
106 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
107 exp_rem_error
=> "yes",
114 desc
=> "label test of scsi disc",
117 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
118 exp_links
=> ["boot_disk"],
121 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
122 KERNEL=="ttyACM0", SYMLINK+="modem"
126 desc
=> "label test of scsi disc",
129 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
130 exp_links
=> ["boot_disk"],
133 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
134 KERNEL=="ttyACM0", SYMLINK+="modem"
138 desc
=> "label test of scsi disc",
141 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
142 exp_links
=> ["boot_disk"],
145 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
146 KERNEL=="ttyACM0", SYMLINK+="modem"
150 desc
=> "label test of scsi partition",
153 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
154 exp_links
=> ["boot_disk1"],
157 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
161 desc
=> "label test of pattern match",
164 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
165 exp_links
=> ["boot_disk1", "boot_disk1-4", "boot_disk1-5"],
166 not_exp_links
=> ["boot_disk1-1", "boot_disk1-2", "boot_disk1-3"]
169 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
170 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
171 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
172 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
173 SUBSYSTEMS=="scsi", ATTRS{vendor}=="AT?", SYMLINK+="boot_disk%n-4"
174 SUBSYSTEMS=="scsi", ATTRS{vendor}=="??A", SYMLINK+="boot_disk%n-5"
178 desc
=> "label test of multiple sysfs files",
181 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
182 exp_links
=> ["boot_disk1"],
183 not_exp_links
=> ["boot_diskX1"],
186 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
187 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
191 desc
=> "label test of max sysfs files (skip invalid rule)",
194 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
195 exp_links
=> ["boot_disk1", "boot_diskXY1"],
196 not_exp_links
=> ["boot_diskXX1"],
199 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"
200 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", ATTRS{queue_depth}=="1", SYMLINK+="boot_diskXY%n"
201 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
205 desc
=> "catch device by *",
208 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
209 exp_links
=> ["modem/0", "catch-all"],
212 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
213 KERNEL=="*", SYMLINK+="catch-all"
218 desc
=> "catch device by * - take 2",
221 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
222 exp_links
=> ["modem/0"],
223 not_exp_links
=> ["bad"],
226 KERNEL=="*ACM1", SYMLINK+="bad"
227 KERNEL=="*ACM0", SYMLINK+="modem/%n"
231 desc
=> "catch device by ?",
234 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
235 exp_links
=> ["modem/0"],
236 not_exp_links
=> ["modem/0-1", "modem/0-2"],
239 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
240 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
241 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
245 desc
=> "catch device by character class",
248 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
249 exp_links
=> ["modem/0"],
250 not_exp_links
=> ["modem/0-1", "modem/0-2"],
253 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
254 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
255 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
259 desc
=> "don't replace kernel name",
262 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
263 exp_links
=> ["modem"],
266 KERNEL=="ttyACM0", SYMLINK+="modem"
270 desc
=> "Handle comment lines in config file (and don't replace kernel name)",
273 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
274 exp_links
=> ["modem"],
278 KERNEL=="ttyACM0", SYMLINK+="modem"
283 desc
=> "Handle comment lines in config file with whitespace (and don't replace kernel name)",
286 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
287 exp_links
=> ["modem"],
290 # this is a comment with whitespace before the comment
291 KERNEL=="ttyACM0", SYMLINK+="modem"
296 desc
=> "Handle whitespace only lines (and don't replace kernel name)",
299 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
300 exp_links
=> ["whitespace"],
306 # this is a comment with whitespace before the comment
307 KERNEL=="ttyACM0", SYMLINK+="whitespace"
314 desc
=> "Handle empty lines in config file (and don't replace kernel name)",
317 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
318 exp_links
=> ["modem"],
322 KERNEL=="ttyACM0", SYMLINK+="modem"
327 desc
=> "Handle backslashed multi lines in config file (and don't replace kernel name)",
330 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
331 exp_links
=> ["modem"],
334 KERNEL=="ttyACM0", \\
340 desc
=> "preserve backslashes, if they are not for a newline",
343 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
344 exp_links
=> ["aaa"],
347 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
352 desc
=> "Handle stupid backslashed multi lines in config file (and don't replace kernel name)",
355 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
356 exp_links
=> ["modem"],
367 KERNEL=="ttyACM0", \\
373 desc
=> "subdirectory handling",
376 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
377 exp_links
=> ["sub/direct/ory/modem"],
380 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
384 desc
=> "parent device name match of scsi partition",
387 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
388 exp_links
=> ["first_disk5"],
391 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
395 desc
=> "test substitution chars",
398 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
399 exp_links
=> ["Major:8:minor:5:kernelnumber:5:id:0:0:0:0"],
402 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
406 desc
=> "import of shell-value returned from program",
409 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
410 exp_links
=> ["node12345678"],
413 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
414 KERNEL=="ttyACM0", SYMLINK+="modem"
418 desc
=> "substitution of sysfs value (%s{file})",
421 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
422 exp_links
=> ["disk-ATA-sda"],
423 not_exp_links
=> ["modem"],
426 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
427 KERNEL=="ttyACM0", SYMLINK+="modem"
431 desc
=> "program result substitution",
434 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
435 exp_links
=> ["special-device-5"],
436 not_exp_links
=> ["not"],
439 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
440 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
444 desc
=> "program result substitution (newline removal)",
447 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
448 exp_links
=> ["newline_removed"],
451 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
455 desc
=> "program result substitution",
458 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
459 exp_links
=> ["test-0:0:0:0"],
462 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
466 desc
=> "program with lots of arguments",
469 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
470 exp_links
=> ["foo9"],
471 not_exp_links
=> ["foo3", "foo4", "foo5", "foo6", "foo7", "foo8"],
474 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
478 desc
=> "program with subshell",
481 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
482 exp_links
=> ["bar9"],
483 not_exp_links
=> ["foo3", "foo4", "foo5", "foo6", "foo7", "foo8"],
486 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
490 desc
=> "program arguments combined with apostrophes",
493 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
494 exp_links
=> ["foo7"],
495 not_exp_links
=> ["foo3", "foo4", "foo5", "foo6", "foo8"],
498 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
502 desc
=> "program arguments combined with escaped double quotes, part 1",
505 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
506 exp_links
=> ["foo2"],
507 not_exp_links
=> ["foo1"],
510 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
514 desc
=> "program arguments combined with escaped double quotes, part 2",
517 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
518 exp_links
=> ["foo2"],
519 not_exp_links
=> ["foo1"],
522 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}"
526 desc
=> "program arguments combined with escaped double quotes, part 3",
529 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
530 exp_links
=> ["foo2"],
531 not_exp_links
=> ["foo1", "foo3"],
534 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
538 desc
=> "characters before the %c{N} substitution",
541 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
542 exp_links
=> ["my-foo9"],
545 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
549 desc
=> "substitute the second to last argument",
552 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
553 exp_links
=> ["my-foo8"],
554 not_exp_links
=> ["my-foo3", "my-foo4", "my-foo5", "my-foo6", "my-foo7", "my-foo9"],
557 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
561 desc
=> "test substitution by variable name",
564 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
565 exp_links
=> ["Major:8-minor:5-kernelnumber:5-id:0:0:0:0"],
568 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
572 desc
=> "test substitution by variable name 2",
575 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
576 exp_links
=> ["Major:8-minor:5-kernelnumber:5-id:0:0:0:0"],
579 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
583 desc
=> "test substitution by variable name 3",
586 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
587 exp_links
=> ["850:0:0:05"],
590 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
594 desc
=> "test substitution by variable name 4",
597 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
598 exp_links
=> ["855"],
601 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
605 desc
=> "test substitution by variable name 5",
608 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
609 exp_links
=> ["8550:0:0:0"],
612 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
616 desc
=> "non matching SUBSYSTEMS for device with no parent",
619 devpath
=> "/devices/virtual/tty/console",
620 exp_links
=> ["TTY"],
621 not_exp_links
=> ["foo"],
624 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
625 KERNEL=="console", SYMLINK+="TTY"
629 desc
=> "non matching SUBSYSTEMS",
632 devpath
=> "/devices/virtual/tty/console",
633 exp_links
=> ["TTY"],
634 not_exp_links
=> ["foo"],
637 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
638 KERNEL=="console", SYMLINK+="TTY"
642 desc
=> "ATTRS match",
645 devpath
=> "/devices/virtual/tty/console",
646 exp_links
=> ["foo", "TTY"],
649 KERNEL=="console", SYMLINK+="TTY"
650 ATTRS{dev}=="5:1", SYMLINK+="foo"
654 desc
=> "ATTR (empty file)",
657 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
658 exp_links
=> ["empty", "not-something"],
659 not_exp_links
=> ["something", "not-empty"],
662 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
663 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
664 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
665 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
669 desc
=> "ATTR (non-existent file)",
672 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
673 exp_links
=> ["non-existent", "wrong"],
674 not_exp_links
=> ["something", "empty", "not-empty",
675 "not-something", "something"],
678 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
679 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
680 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
681 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
682 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
683 KERNEL=="sda", SYMLINK+="wrong"
687 desc
=> "program and bus type match",
690 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
691 exp_links
=> ["scsi-0:0:0:0"],
694 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
695 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
696 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
700 desc
=> "sysfs parent hierarchy",
703 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
704 exp_links
=> ["modem"],
707 ATTRS{idProduct}=="007b", SYMLINK+="modem"
711 desc
=> "name test with ! in the name",
714 devpath
=> "/devices/virtual/block/fake!blockdev0",
715 devnode
=> "fake/blockdev0",
716 exp_links
=> ["is/a/fake/blockdev0"],
717 not_exp_links
=> ["is/not/a/fake/blockdev0", "modem"],
720 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
721 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
722 KERNEL=="ttyACM0", SYMLINK+="modem"
726 desc
=> "name test with ! in the name, but no matching rule",
729 devpath
=> "/devices/virtual/block/fake!blockdev0",
730 devnode
=> "fake/blockdev0",
731 not_exp_links
=> ["modem"],
734 KERNEL=="ttyACM0", SYMLINK+="modem"
738 desc
=> "KERNELS rule",
741 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
742 exp_links
=> ["scsi-0:0:0:0"],
743 not_exp_links
=> ["no-match", "short-id", "not-scsi"],
746 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
747 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
748 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
749 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
750 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
754 desc
=> "KERNELS wildcard all",
757 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
758 exp_links
=> ["scsi-0:0:0:0"],
759 not_exp_links
=> ["no-match", "before"],
762 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
763 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
764 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
765 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
766 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
770 desc
=> "KERNELS wildcard partial",
773 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
774 exp_links
=> ["scsi-0:0:0:0", "before"],
777 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
778 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
782 desc
=> "KERNELS wildcard partial 2",
785 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
786 exp_links
=> ["scsi-0:0:0:0", "before"],
789 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
790 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
794 desc
=> "substitute attr with link target value (first match)",
797 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
798 exp_links
=> ["driver-is-sd"],
801 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
805 desc
=> "substitute attr with link target value (currently selected device)",
808 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
809 exp_links
=> ["driver-is-ahci"],
812 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
816 desc
=> "ignore ATTRS attribute whitespace",
819 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
820 exp_links
=> ["ignored"],
823 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
827 desc
=> "do not ignore ATTRS attribute whitespace",
830 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
831 exp_links
=> ["matched-with-space"],
832 not_exp_links
=> ["wrong-to-ignore"],
835 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
836 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
840 desc
=> "permissions USER=bad GROUP=name",
843 devpath
=> "/devices/virtual/tty/tty33",
844 exp_perms
=> "0:0:0600",
847 KERNEL=="tty33", OWNER="bad", GROUP="name"
851 desc
=> "permissions OWNER=1",
854 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
855 exp_links
=> ["node"],
856 exp_perms
=> "1::0600",
859 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
863 desc
=> "permissions GROUP=1",
866 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
867 exp_links
=> ["node"],
868 exp_perms
=> ":1:0660",
871 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
875 desc
=> "textual user id",
878 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
879 exp_links
=> ["node"],
880 exp_perms
=> "daemon::0600",
883 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="daemon"
887 desc
=> "textual group id",
890 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
891 exp_links
=> ["node"],
892 exp_perms
=> ":daemon:0660",
895 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
899 desc
=> "textual user/group id",
902 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
903 exp_links
=> ["node"],
904 exp_perms
=> "root:audio:0660",
907 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="audio"
911 desc
=> "permissions MODE=0777",
914 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
915 exp_links
=> ["node"],
916 exp_perms
=> "::0777",
919 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
923 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
926 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
927 exp_links
=> ["node"],
928 exp_perms
=> "1:1:0777",
931 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
935 desc
=> "permissions OWNER to 1",
938 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
942 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
946 desc
=> "permissions GROUP to 1",
949 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
950 exp_perms
=> ":1:0660",
953 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
957 desc
=> "permissions MODE to 0060",
960 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
961 exp_perms
=> "::0060",
964 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
968 desc
=> "permissions OWNER, GROUP, MODE",
971 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
972 exp_perms
=> "1:1:0777",
975 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
979 desc
=> "permissions only rule",
982 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
983 exp_perms
=> "1:1:0777",
986 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
987 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
988 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
992 desc
=> "multiple permissions only rule",
995 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
996 exp_perms
=> "1:1:0777",
999 SUBSYSTEM=="tty", OWNER="1"
1000 SUBSYSTEM=="tty", GROUP="1"
1001 SUBSYSTEM=="tty", MODE="0777"
1002 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
1003 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
1007 desc
=> "permissions only rule with override at SYMLINK+ rule",
1010 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1011 exp_perms
=> "1:2:0777",
1014 SUBSYSTEM=="tty", OWNER="1"
1015 SUBSYSTEM=="tty", GROUP="1"
1016 SUBSYSTEM=="tty", MODE="0777"
1017 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
1018 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
1022 desc
=> "major/minor number test",
1025 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1026 exp_links
=> ["node"],
1027 exp_majorminor
=> "8:0",
1030 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
1034 desc
=> "big major number test",
1037 devpath
=> "/devices/virtual/misc/misc-fake1",
1038 exp_links
=> ["node"],
1039 exp_majorminor
=> "4095:1",
1042 KERNEL=="misc-fake1", SYMLINK+="node"
1046 desc
=> "big major and big minor number test",
1049 devpath
=> "/devices/virtual/misc/misc-fake89999",
1050 exp_links
=> ["node"],
1051 exp_majorminor
=> "4095:89999",
1054 KERNEL=="misc-fake89999", SYMLINK+="node"
1058 desc
=> "multiple symlinks with format char",
1061 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1062 exp_links
=> ["symlink1-0", "symlink2-ttyACM0", "symlink3-"],
1065 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
1069 desc
=> "multiple symlinks with a lot of s p a c e s",
1072 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1073 exp_links
=> ["one", "two"],
1074 not_exp_links
=> [" "],
1077 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
1081 desc
=> "symlink with spaces in substituted variable",
1084 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1085 exp_links
=> ["name-one_two_three-end"],
1086 not_exp_links
=> [" "],
1089 ENV{WITH_WS}="one two three"
1090 SYMLINK="name-\$env{WITH_WS}-end"
1094 desc
=> "symlink with leading space in substituted variable",
1097 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1098 exp_links
=> ["name-one_two_three-end"],
1099 not_exp_links
=> [" "],
1102 ENV{WITH_WS}=" one two three"
1103 SYMLINK="name-\$env{WITH_WS}-end"
1107 desc
=> "symlink with trailing space in substituted variable",
1110 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1111 exp_links
=> ["name-one_two_three-end"],
1112 not_exp_links
=> [" "],
1115 ENV{WITH_WS}="one two three "
1116 SYMLINK="name-\$env{WITH_WS}-end"
1120 desc
=> "symlink with lots of space in substituted variable",
1123 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1124 exp_links
=> ["name-one_two_three-end"],
1125 not_exp_links
=> [" "],
1128 ENV{WITH_WS}=" one two three "
1129 SYMLINK="name-\$env{WITH_WS}-end"
1133 desc
=> "symlink with multiple spaces in substituted variable",
1136 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1137 exp_links
=> ["name-one_two_three-end"],
1138 not_exp_links
=> [" "],
1141 ENV{WITH_WS}=" one two three "
1142 SYMLINK="name-\$env{WITH_WS}-end"
1146 desc
=> "symlink with space and var with space",
1149 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1150 exp_links
=> ["first", "name-one_two_three-end",
1151 "another_symlink", "a", "b", "c"],
1152 not_exp_links
=> [" "],
1155 ENV{WITH_WS}=" one two three "
1156 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
1160 desc
=> "symlink creation (same directory)",
1163 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1164 exp_links
=> ["modem0"],
1167 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
1171 desc
=> "multiple symlinks",
1174 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1175 exp_links
=> ["first-0", "second-0", "third-0"],
1178 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
1182 desc
=> "symlink name '.'",
1185 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1187 exp_add_error
=> "yes",
1188 exp_rem_error
=> "yes",
1191 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
1195 desc
=> "symlink node to itself",
1198 devpath
=> "/devices/virtual/tty/tty0",
1199 exp_links
=> ["link"],
1200 exp_add_error
=> "yes",
1201 exp_rem_error
=> "yes",
1205 KERNEL=="tty0", SYMLINK+="tty0"
1209 desc
=> "symlink %n substitution",
1212 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1213 exp_links
=> ["symlink0"],
1216 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
1220 desc
=> "symlink %k substitution",
1223 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1224 exp_links
=> ["symlink-ttyACM0"],
1227 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
1231 desc
=> "symlink %M:%m substitution",
1234 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1235 exp_links
=> ["major-166:0"],
1238 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
1242 desc
=> "symlink %b substitution",
1245 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1246 exp_links
=> ["symlink-0:0:0:0"],
1249 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
1253 desc
=> "symlink %c substitution",
1256 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1257 exp_links
=> ["test"],
1260 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
1264 desc
=> "symlink %c{N} substitution",
1267 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1268 exp_links
=> ["test"],
1269 not_exp_links
=> ["symlink", "this"],
1272 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
1276 desc
=> "symlink %c{N+} substitution",
1279 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1280 exp_links
=> ["test", "this"],
1281 not_exp_links
=> ["symlink"],
1284 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
1288 desc
=> "symlink only rule with %c{N+}",
1291 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1292 exp_links
=> ["test", "this"],
1293 not_exp_links
=> ["symlink"],
1296 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
1300 desc
=> "symlink %s{filename} substitution",
1303 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1304 exp_links
=> ["166:0"],
1307 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
1311 desc
=> "program result substitution (numbered part of)",
1314 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
1315 exp_links
=> ["link1", "link2"],
1316 not_exp_links
=> ["node"],
1319 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
1323 desc
=> "program result substitution (numbered part of+)",
1326 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
1327 exp_links
=> ["link1", "link2", "link3", "link4"],
1328 not_exp_links
=> ["node"],
1331 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
1335 desc
=> "SUBSYSTEM match test",
1338 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1339 exp_links
=> ["node"],
1340 not_exp_links
=> ["should_not_match", "should_not_match2"],
1343 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
1344 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
1345 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
1349 desc
=> "DRIVERS match test",
1352 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1353 exp_links
=> ["node"],
1354 not_exp_links
=> ["should_not_match"]
1357 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
1358 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
1362 desc
=> "devnode substitution test",
1365 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1366 exp_links
=> ["node"],
1369 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1373 desc
=> "parent node name substitution test",
1376 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1377 exp_links
=> ["sda-part-1"],
1380 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-%n"
1384 desc
=> "udev_root substitution",
1387 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1388 exp_links
=> ["start-/dev-end"],
1391 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1395 # This is not supported any more
1396 desc
=> "last_rule option",
1399 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1400 exp_links
=> ["last"],
1401 not_exp_links
=> ["very-last"],
1402 exp_nodev_error
=> "yes",
1405 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1406 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1410 desc
=> "negation KERNEL!=",
1413 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1414 exp_links
=> ["match", "before"],
1415 not_exp_links
=> ["matches-but-is-negated"],
1418 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1419 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1420 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1424 desc
=> "negation SUBSYSTEM!=",
1427 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1428 exp_links
=> ["before", "not-anything"],
1429 not_exp_links
=> ["matches-but-is-negated"],
1432 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1433 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1434 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1438 desc
=> "negation PROGRAM!= exit code",
1441 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1442 exp_links
=> ["before", "nonzero-program"],
1445 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1446 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1450 desc
=> "ENV{} test",
1453 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1454 exp_links
=> ["true"],
1455 not_exp_links
=> ["bad", "wrong"],
1458 ENV{ENV_KEY_TEST}="test"
1459 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1460 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1461 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1465 desc
=> "ENV{} test",
1468 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1469 exp_links
=> ["true"],
1470 not_exp_links
=> ["bad", "wrong", "no"],
1473 ENV{ENV_KEY_TEST}="test"
1474 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1475 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1476 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1477 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1481 desc
=> "ENV{} test (assign)",
1484 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1485 exp_links
=> ["true", "before"],
1486 not_exp_links
=> ["no"],
1489 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1490 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1491 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1492 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1496 desc
=> "ENV{} test (assign 2 times)",
1499 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1500 exp_links
=> ["true", "before"],
1501 not_exp_links
=> ["no", "bad"],
1504 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1505 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1506 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1507 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1508 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="bad"
1509 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1513 desc
=> "ENV{} test (assign2)",
1516 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1517 exp_links
=> ["part"],
1518 not_exp_links
=> ["disk"],
1521 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1522 exp_links
=> ["disk"],
1523 not_exp_links
=> ["part"],
1527 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1528 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1529 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1530 SUBSYSTEM=="block", SYMLINK+="before"
1531 ENV{PARTITION}=="true", SYMLINK+="part"
1535 desc
=> "untrusted string sanitize",
1538 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1539 exp_links
=> ["sane"],
1542 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1546 desc
=> "untrusted string sanitize (don't replace utf8)",
1549 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1550 exp_links
=> ["uber"],
1553 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1557 desc
=> "untrusted string sanitize (replace invalid utf8)",
1560 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1561 exp_links
=> ["replaced"],
1564 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1568 desc
=> "read sysfs value from parent device",
1571 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1572 exp_links
=> ["serial-354172020305000"],
1575 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1579 desc
=> "match against empty key string",
1582 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1583 exp_links
=> ["ok"],
1584 not_exp_links
=> ["not-1-ok", "not-2-ok", "not-3-ok"],
1587 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1588 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1589 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1590 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1594 desc
=> "check ACTION value",
1597 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1598 exp_links
=> ["ok"],
1599 not_exp_links
=> ["unknown-not-ok"],
1602 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1603 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1607 desc
=> "final assignment",
1610 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1611 exp_links
=> ["ok"],
1612 exp_perms
=> "root:tty:0640",
1615 KERNEL=="sda", GROUP:="tty"
1616 KERNEL=="sda", GROUP="root", MODE="0640", SYMLINK+="ok"
1620 desc
=> "final assignment 2",
1623 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1624 exp_links
=> ["ok"],
1625 exp_perms
=> "root:tty:0640",
1628 KERNEL=="sda", GROUP:="tty"
1629 SUBSYSTEM=="block", MODE:="640"
1630 KERNEL=="sda", GROUP="root", MODE="0666", SYMLINK+="ok"
1634 desc
=> "env substitution",
1637 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1638 exp_links
=> ["node-add-me"],
1641 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1645 desc
=> "reset list to current value",
1648 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1649 exp_links
=> ["three"],
1650 not_exp_links
=> ["two", "one"],
1653 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1654 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1655 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1659 desc
=> "test empty SYMLINK+ (empty override)",
1662 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1663 exp_links
=> ["right"],
1664 not_exp_links
=> ["wrong"],
1667 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1668 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1669 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1673 desc
=> "test multi matches",
1676 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1677 exp_links
=> ["right", "before"],
1680 KERNEL=="ttyACM*", SYMLINK+="before"
1681 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1685 desc
=> "test multi matches 2",
1688 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1689 exp_links
=> ["right", "before"],
1690 not_exp_links
=> ["nomatch"],
1693 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1694 KERNEL=="ttyACM*", SYMLINK+="before"
1695 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1699 desc
=> "test multi matches 3",
1702 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1703 exp_links
=> ["right"],
1704 not_exp_links
=> ["nomatch", "wrong1", "wrong2"],
1707 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1708 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1709 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1710 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1714 desc
=> "test multi matches 4",
1717 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1718 exp_links
=> ["right"],
1719 not_exp_links
=> ["nomatch", "wrong1", "wrong2", "wrong3"],
1722 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1723 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1724 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1725 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1726 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1730 desc
=> "test multi matches 5",
1733 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1734 exp_links
=> ["found"],
1735 not_exp_name
=> "bad",
1738 KERNEL=="sda", TAG="foo"
1739 TAGS=="|foo", SYMLINK+="found"
1740 TAGS=="|aaa", SYMLINK+="bad"
1744 desc
=> "test multi matches 6",
1747 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1748 exp_links
=> ["found"],
1749 not_exp_name
=> "bad",
1752 KERNEL=="sda", TAG=""
1753 TAGS=="|foo", SYMLINK+="found"
1754 TAGS=="aaa|bbb", SYMLINK+="bad"
1758 desc
=> "test multi matches 7",
1761 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1762 exp_links
=> ["found"],
1763 not_exp_name
=> "bad",
1766 KERNEL=="sda", TAG="foo"
1767 TAGS=="foo||bar", SYMLINK+="found"
1768 TAGS=="aaa||bbb", SYMLINK+="bad"
1772 desc
=> "test multi matches 8",
1775 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1776 exp_links
=> ["found"],
1777 not_exp_name
=> "bad",
1780 KERNEL=="sda", TAG=""
1781 TAGS=="foo||bar", SYMLINK+="found"
1782 TAGS=="aaa|bbb", SYMLINK+="bad"
1786 desc
=> "test multi matches 9",
1789 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1790 exp_links
=> ["found"],
1791 not_exp_name
=> "bad",
1794 KERNEL=="sda", TAG="foo"
1795 TAGS=="foo|", SYMLINK+="found"
1796 TAGS=="aaa|", SYMLINK+="bad"
1800 desc
=> "test multi matches 10",
1803 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1804 exp_links
=> ["found"],
1805 not_exp_name
=> "bad",
1808 KERNEL=="sda", TAG=""
1809 TAGS=="foo|", SYMLINK+="found"
1810 TAGS=="aaa|bbb", SYMLINK+="bad"
1814 desc
=> "test multi matches 11",
1817 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1818 exp_links
=> ["found"],
1819 not_exp_name
=> "bad",
1822 KERNEL=="sda", TAG="c"
1823 TAGS=="foo||bar||c", SYMLINK+="found"
1824 TAGS=="aaa||bbb||ccc", SYMLINK+="bad"
1828 desc
=> "IMPORT parent test",
1831 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1832 exp_links
=> ["parent"],
1835 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1836 exp_links
=> ["parentenv-parent_right"],
1838 sleep_us
=> 500000, # Serialized! We need to sleep here after adding sda
1840 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1841 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1842 KERNEL=="sda", SYMLINK+="parent"
1846 desc
=> "GOTO test",
1849 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1850 exp_links
=> ["right"],
1851 not_exp_test
=> ["wrong", "wrong2"],
1854 KERNEL=="sda1", GOTO="TEST"
1855 KERNEL=="sda1", SYMLINK+="wrong"
1856 KERNEL=="sda1", GOTO="BAD"
1857 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1858 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1859 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1864 desc
=> "GOTO label does not exist",
1867 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1868 exp_links
=> ["right"],
1871 KERNEL=="sda1", GOTO="does-not-exist"
1872 KERNEL=="sda1", SYMLINK+="right",
1877 desc
=> "SYMLINK+ compare test",
1880 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1881 exp_links
=> ["right", "link"],
1882 not_exp_links
=> ["wrong"],
1885 KERNEL=="sda1", SYMLINK+="link"
1886 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1887 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1891 desc
=> "invalid key operation",
1894 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1895 exp_links
=> ["yes"],
1896 not_exp_links
=> ["no"],
1899 KERNEL="sda1", SYMLINK+="no"
1900 KERNEL=="sda1", SYMLINK+="yes"
1904 desc
=> "operator chars in attribute",
1907 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1908 exp_links
=> ["yes"],
1911 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1915 desc
=> "overlong comment line",
1918 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1919 exp_links
=> ["yes"],
1920 not_exp_links
=> ["no"],
1923 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1924 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1925 KERNEL=="sda1", SYMLINK+=="no"
1926 KERNEL=="sda1", SYMLINK+="yes"
1930 desc
=> "magic subsys/kernel lookup",
1933 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1934 exp_links
=> ["00:16:41:e2:8d:ff"],
1937 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1941 desc
=> "TEST absolute path",
1944 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1945 exp_links
=> ["there"],
1946 not_exp_links
=> ["notthere"],
1949 TEST=="/etc/machine-id", SYMLINK+="there"
1950 TEST!="/etc/machine-id", SYMLINK+="notthere"
1954 desc
=> "TEST subsys/kernel lookup",
1957 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1958 exp_links
=> ["yes"],
1961 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1965 desc
=> "TEST relative path",
1968 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1969 exp_links
=> ["relative"],
1972 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1976 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1979 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1980 exp_links
=> ["found-subdir"],
1983 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1987 desc
=> "TEST MODE=0000",
1990 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1991 exp_perms
=> "0:0:0000",
1992 exp_rem_error
=> "yes",
1995 KERNEL=="sda", MODE="0000"
1999 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
2002 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2003 exp_perms
=> "1:1:0400",
2006 KERNEL=="sda", MODE="666"
2007 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
2011 desc
=> "TEST PROGRAM feeds MODE with overflow",
2014 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2015 exp_perms
=> "0:0:0440",
2016 exp_rem_error
=> "yes",
2019 KERNEL=="sda", MODE="440"
2020 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
2024 desc
=> "magic [subsys/sysname] attribute substitution",
2027 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2028 exp_links
=> ["sda-8741C4G-end"],
2029 exp_perms
=> "0:0:0600",
2032 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
2036 desc
=> "builtin path_id",
2039 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2040 exp_links
=> ["disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0"],
2043 KERNEL=="sda", IMPORT{builtin}="path_id"
2044 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
2048 desc
=> "add and match tag",
2051 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2052 exp_links
=> ["found"],
2053 not_exp_links
=> ["bad"],
2056 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
2057 TAGS=="green", SYMLINK+="found"
2058 TAGS=="blue", SYMLINK+="bad"
2062 desc
=> "don't crash with lots of tags",
2065 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2066 exp_links
=> ["found"],
2068 rules
=> $rules_10k_tags . <<EOF
2069 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
2073 desc
=> "continuations",
2076 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2077 exp_links
=> ["found"],
2078 not_exp_name
=> "bad",
2080 rules
=> $rules_10k_tags_continuation . <<EOF
2081 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="bad"
2083 # comment in continuation
2085 # space before comment
2087 # spaces before and after token are dropped
2092 TAGS=="hoge1", TAGS=="hoge2", TAGS=="hoge3", TAGS=="hoge4", SYMLINK+="found"
2096 desc
=> "continuations with empty line",
2099 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2100 exp_links
=> ["found"],
2101 not_exp_name
=> "bad",
2105 # empty line finishes continuation
2106 KERNEL=="sda", TAG+="foo" \\
2108 KERNEL=="sdb", TAG+="hoge"
2109 KERNEL=="sda", TAG+="aaa" \\
2110 KERNEL=="sdb", TAG+="bbb"
2111 TAGS=="foo", SYMLINK+="found"
2112 TAGS=="aaa", SYMLINK+="bad"
2116 desc
=> "continuations with white only line",
2119 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2120 exp_links
=> ["found"],
2121 not_exp_name
=> "bad",
2124 # space only line finishes continuation
2125 KERNEL=="sda", TAG+="foo" \\
2127 KERNEL=="sdb", TAG+="hoge"
2128 KERNEL=="sda", TAG+="aaa" \\
2129 KERNEL=="sdb", TAG+="bbb"
2130 TAGS=="foo", SYMLINK+="found"
2131 TAGS=="aaa", SYMLINK+="bad"
2135 desc
=> "multiple devices",
2138 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
2139 exp_links
=> ["part-1"],
2142 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
2143 exp_links
=> ["part-5"],
2146 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
2147 exp_links
=> ["part-6"],
2150 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7",
2151 exp_links
=> ["part-7"],
2154 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8",
2155 exp_links
=> ["part-8"],
2158 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9",
2159 exp_links
=> ["part-9"],
2162 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10",
2163 exp_links
=> ["part-10"],
2167 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n"
2171 desc
=> "multiple devices, same link name, positive prio",
2175 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
2176 exp_links
=> ["part-1"],
2177 not_exp_links
=> ["partition"],
2180 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
2181 exp_links
=> ["part-5"],
2182 not_exp_links
=> ["partition"],
2185 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
2186 not_exp_links
=> ["partition"],
2187 exp_links
=> ["part-6"],
2190 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7",
2191 exp_links
=> ["part-7", "partition"],
2194 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8",
2195 not_exp_links
=> ["partition"],
2196 exp_links
=> ["part-8"],
2199 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9",
2200 not_exp_links
=> ["partition"],
2201 exp_links
=> ["part-9"],
2204 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10",
2205 not_exp_links
=> ["partition"],
2206 exp_links
=> ["part-10"],
2210 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n"
2211 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition"
2212 KERNEL=="*7", OPTIONS+="link_priority=10"
2216 desc
=> "multiple devices, same link name, negative prio",
2219 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
2220 exp_links
=> ["part-1"],
2221 not_exp_links
=> ["partition"],
2224 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
2225 exp_links
=> ["part-5"],
2226 not_exp_links
=> ["partition"],
2229 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
2230 not_exp_links
=> ["partition"],
2231 exp_links
=> ["part-6"],
2234 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7",
2235 exp_links
=> ["part-7", "partition"],
2238 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8",
2239 not_exp_links
=> ["partition"],
2240 exp_links
=> ["part-8"],
2243 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9",
2244 not_exp_links
=> ["partition"],
2245 exp_links
=> ["part-9"],
2248 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10",
2249 not_exp_links
=> ["partition"],
2250 exp_links
=> ["part-10"],
2254 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n"
2255 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition"
2256 KERNEL!="*7", OPTIONS+="link_priority=-10"
2260 desc
=> "multiple devices, same link name, positive prio, sleep",
2263 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
2264 exp_links
=> ["part-1"],
2265 not_exp_links
=> ["partition"],
2268 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
2269 exp_links
=> ["part-5"],
2270 not_exp_links
=> ["partition"],
2273 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
2274 not_exp_links
=> ["partition"],
2275 exp_links
=> ["part-6"],
2278 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7",
2279 exp_links
=> ["part-7", "partition"],
2282 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8",
2283 not_exp_links
=> ["partition"],
2284 exp_links
=> ["part-8"],
2287 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9",
2288 not_exp_links
=> ["partition"],
2289 exp_links
=> ["part-9"],
2292 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10",
2293 not_exp_links
=> ["partition"],
2294 exp_links
=> ["part-10"],
2299 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="part-%n"
2300 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sda?*", ENV{DEVTYPE}=="partition", SYMLINK+="partition"
2301 KERNEL=="*7", OPTIONS+="link_priority=10"
2305 desc
=> 'all_block_devs',
2306 generator
=> expect_for_some
("\\/sda6\$", ["blockdev"]),
2309 SUBSYSTEM=="block", SUBSYSTEMS=="scsi", KERNEL=="sd*", SYMLINK+="blockdev"
2310 KERNEL=="sda6", OPTIONS+="link_priority=10"
2318 # create temporary rules
2319 system("mkdir", "-p", "$udev_rules_dir");
2320 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
2326 my ($action, $devpath) = @_;
2328 if ($valgrind > 0) {
2329 return system("$udev_bin_valgrind $action $devpath");
2330 } elsif ($gdb > 0) {
2331 return system("$udev_bin_gdb $action $devpath");
2332 } elsif ($strace > 0) {
2333 return system("$udev_bin_strace $action $devpath");
2335 return system("$udev_bin", "$action", "$devpath");
2343 sub permissions_test
{
2344 my($rules, $uid, $gid, $mode) = @_;
2350 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
2352 if (defined(getpwnam($1))) {
2353 $userid = int(getpwnam($1));
2357 if ($uid != $userid) { $wrong = 1; }
2360 if (defined(getgrnam($2))) {
2361 $groupid = int(getgrnam($2));
2365 if ($gid != $groupid) { $wrong = 1; }
2368 if (($mode & 07777) != oct($3)) { $wrong = 1; };
2371 print "permissions: ok\n";
2374 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
2375 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
2376 print "permissions: error\n";
2382 sub major_minor_test
{
2383 my($rules, $rdev) = @_;
2385 my $major = ($rdev >> 8) & 0xfff;
2386 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
2389 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
2391 if ($major != $1) { $wrong = 1; };
2394 if ($minor != $2) { $wrong = 1; };
2397 print "major:minor: ok\n";
2400 printf " expected major:minor is: %i:%i\n", $1, $2;
2401 printf " created major:minor is : %i:%i\n", $major, $minor;
2402 print "major:minor: error\n";
2409 system("umount \"$udev_tmpfs\" 2>/dev/null");
2411 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
2413 if (system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) {
2414 warn "unable to mount tmpfs";
2418 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
2419 # setting group and mode of udev_dev ensures the tests work
2420 # even if the parent directory has setgid bit enabled.
2421 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
2422 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
2424 if (system("mknod", $udev_dev . "/null", "c", "1", "3")) {
2425 warn "unable to create $udev_dev/null";
2429 # check if we are permitted to create block device nodes
2430 my $block_device_filename = $udev_dev . "/sda";
2431 if (system("mknod", $block_device_filename, "b", "8", "0")) {
2432 warn "unable to create $block_device_filename";
2435 unlink $block_device_filename;
2437 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
2439 system("rm", "-rf", "$udev_run");
2441 if (!mkdir($udev_run)) {
2442 warn "unable to create directory $udev_run";
2453 if (defined($device->{devnode
})) {
2454 $devnode = "$udev_dev/$device->{devnode}";
2456 $devnode = "$device->{devpath}";
2457 $devnode =~ s!.*/!$udev_dev/!;
2464 my $devnode = get_devnode
($device);
2466 my @st = lstat("$devnode");
2467 if (! (-b _
|| -c _
)) {
2468 print "add $devnode: error\n";
2469 system("tree", "$udev_dev");
2474 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
2475 $atime, $mtime, $ctime, $blksize, $blocks) = @st;
2477 if (defined($device->{exp_perms
})) {
2478 permissions_test
($device, $uid, $gid, $mode);
2480 if (defined($device->{exp_majorminor
})) {
2481 major_minor_test
($device, $rdev);
2483 print "add $devnode: ok\n";
2488 sub get_link_target
{
2492 my $dir = "$udev_dev/$link";
2493 my $tgt = readlink("$udev_dev/$link");
2494 $dir =~ s!/[^/]*$!!;
2495 $tgt = abs_path
("$dir/$tgt");
2500 sub check_link_add
{
2501 my ($link, $devnode, $err_expected) = @_;
2503 my @st = lstat("$udev_dev/$link");
2505 my $tgt = get_link_target
($link);
2507 if ($tgt ne $devnode) {
2508 print "symlink $link: error, found -> $tgt\n";
2510 system("tree", "$udev_dev");
2512 print "symlink $link: ok\n";
2516 print "symlink $link: error";
2517 if ($err_expected) {
2518 print " as expected\n";
2522 system("tree", "$udev_dev");
2530 sub check_link_nonexistent
{
2531 my ($link, $devnode, $err_expected) = @_;
2533 if ((-e
"$udev_dev/$link") || (-l
"$udev_dev/$link")) {
2534 my $tgt = get_link_target
($link);
2536 if ($tgt ne $devnode) {
2537 print "nonexistent: '$link' points to other device (ok)\n";
2540 print "nonexistent: error \'$link\' should not be there";
2541 if ($err_expected) {
2542 print " (as expected)\n";
2546 system("tree", "$udev_dev");
2553 print "nonexistent $link: ok\n";
2560 my $devnode = check_devnode
($device);
2562 if (defined($device->{exp_links
})) {
2563 foreach my $link (@
{$device->{exp_links
}}) {
2564 check_link_add
($link, $devnode,
2565 $device->{exp_add_error
});
2568 if (defined $device->{not_exp_links
}) {
2569 foreach my $link (@
{$device->{not_exp_links
}}) {
2570 check_link_nonexistent
($link, $devnode,
2571 $device->{exp_nodev_error
});
2576 sub check_remove_devnode
{
2578 my $devnode = get_devnode
($device);
2580 if (-e
"$devnode") {
2581 print "remove $devnode: error";
2583 system("tree", "$udev_dev");
2588 print "remove $devnode: ok\n";
2593 sub check_link_remove
{
2594 my ($link, $err_expected) = @_;
2596 if ((-e
"$udev_dev/$link") ||
2597 (-l
"$udev_dev/$link")) {
2598 print "remove $link: error";
2599 if ($err_expected) {
2600 print " as expected\n";
2604 system("tree", "$udev_dev");
2610 print "remove $link: ok\n";
2618 check_remove_devnode
($device);
2620 return if (!defined($device->{exp_links
}));
2622 foreach my $link (@
{$device->{exp_links
}}) {
2623 check_link_remove
($link, $device->{exp_rem_error
});
2628 my ($action, $dev, $sleep_us, $sema) = @_;
2630 # Notify main process that this worker has started
2635 usleep
($sleep_us) if defined ($sleep_us);
2636 my $rc = udev
($action, $dev->{devpath
});
2640 sub fork_and_run_udev
{
2641 my ($action, $rules, $sema) = @_;
2642 my @devices = @
{$rules->{devices
}};
2646 $sema->setval(0, 1);
2647 foreach $dev (@devices) {
2651 run_udev
($action, $dev,
2652 defined($rules->{sleep_us
}) ?
$k * $rules->{sleep_us
} : undef,
2660 # This operation waits for all workers to become ready, and
2661 # starts them off when that's the case.
2662 $sema->op(0, -($#devices + 2), 0);
2664 foreach $dev (@devices) {
2668 $pid = waitpid($dev->{pid
}, 0);
2670 print "error waiting for pid dev->{pid}\n";
2672 if (WIFEXITED
($?
)) {
2673 $rc = WEXITSTATUS
($?
);
2676 print "$udev_bin $action for $dev->{devpath} failed with code $rc\n";
2686 my ($rules, $number, $sema) = @_;
2690 my $cur_good = $good;
2691 my $cur_error = $error;
2693 if (!defined $rules->{devices
}) {
2694 $rules->{devices
} = all_block_devs
($rules->{generator
});
2696 @devices = @
{$rules->{devices
}};
2697 # For each device: exit status and devnode test for add & remove
2698 $ntests += 4 * ($#devices + 1);
2700 foreach my $dev (@devices) {
2701 $ntests += 2 * ($#{$dev->{exp_links}} + 1)
2702 + ($#{$dev->{not_exp_links}} + 1)
2703 + (defined $dev->{exp_perms
} ?
1 : 0)
2704 + (defined $dev->{exp_majorminor
} ?
1 : 0);
2706 if (defined $rules->{repeat
}) {
2707 $ntests *= $rules->{repeat
};
2709 $exp_good += $ntests;
2710 print "TEST $number: $rules->{desc}\n";
2711 create_rules
(\
$rules->{rules
});
2714 fork_and_run_udev
("add", $rules, $sema);
2716 foreach my $dev (@devices) {
2720 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
2725 fork_and_run_udev
("remove", $rules, $sema);
2727 foreach my $dev (@devices) {
2731 if (defined($rules->{repeat
}) && --($rules->{repeat
}) > 0) {
2734 printf "TEST $number: errors: %d good: %d/%d\n\n", $error-$cur_error,
2735 $good-$cur_good, $ntests;
2737 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
2744 system("rm", "-rf", "$udev_run");
2745 system("umount", "$udev_tmpfs");
2749 # only run if we have root permissions
2750 # due to mknod restrictions
2752 print "Must have root permissions to run properly.\n";
2753 exit($EXIT_TEST_SKIP);
2756 # skip the test when running in a chroot
2757 system("systemd-detect-virt", "-r", "-q");
2759 print "Running in a chroot, skipping the test.\n";
2760 exit($EXIT_TEST_SKIP);
2763 if (!udev_setup
()) {
2764 warn "Failed to set up the environment, skipping the test";
2766 exit($EXIT_TEST_SKIP);
2769 if (system($udev_bin, "check")) {
2770 warn "$udev_bin failed to set up the environment, skipping the test";
2772 exit($EXIT_TEST_SKIP);
2778 foreach my $arg (@ARGV) {
2779 if ($arg =~ m/--valgrind/) {
2781 printf("using valgrind\n");
2782 } elsif ($arg =~ m/--gdb/) {
2784 printf("using gdb\n");
2785 } elsif ($arg =~ m/--strace/) {
2787 printf("using strace\n");
2792 my $sema = IPC
::Semaphore
->new(IPC_PRIVATE
, 1, S_IRUSR
| S_IWUSR
| IPC_CREAT
);
2795 foreach my $arg (@list) {
2796 if (defined($tests[$arg-1]->{desc
})) {
2797 print "udev-test will run test number $arg:\n\n";
2798 run_test
($tests[$arg-1], $arg, $sema);
2800 print "test does not exist.\n";
2805 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
2807 foreach my $rules (@tests) {
2808 run_test
($rules, $test_num, $sema);
2814 print "$error errors occurred. $good/$exp_good good results.\n\n";