]>
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);
26 my $udev_bin = "./test-udev";
30 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin";
31 my $udev_bin_gdb = "gdb --args $udev_bin";
32 my $udev_bin_strace = "strace -efile $udev_bin";
33 my $udev_run = "test/run";
34 my $udev_tmpfs = "test/tmpfs";
35 my $udev_sys = "${udev_tmpfs}/sys";
36 my $udev_dev = "${udev_tmpfs}/dev";
37 my $udev_rules_dir = "$udev_run/udev/rules.d";
38 my $udev_rules = "$udev_rules_dir/udev-test.rules";
39 my $EXIT_TEST_SKIP = 77;
41 my $rules_10k_tags = "";
42 for (my $i = 1; $i <= 10000; ++$i) {
43 $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n";
46 my $rules_10k_tags_continuation = "KERNEL==\"sda\", \\\n";
47 for (my $i = 1; $i < 10000; ++$i) {
48 $rules_10k_tags_continuation .= 'TAG+="test' . $i . "\",\\\n";
50 $rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n";
57 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
58 exp_rem_error
=> "yes",
61 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
62 exp_rem_error
=> "yes",
69 desc
=> "label test of scsi disc",
72 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
73 exp_name
=> "boot_disk" ,
76 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
77 KERNEL=="ttyACM0", SYMLINK+="modem"
81 desc
=> "label test of scsi disc",
84 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
85 exp_name
=> "boot_disk" ,
88 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
89 KERNEL=="ttyACM0", SYMLINK+="modem"
93 desc
=> "label test of scsi disc",
96 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
97 exp_name
=> "boot_disk" ,
100 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
101 KERNEL=="ttyACM0", SYMLINK+="modem"
105 desc
=> "label test of scsi partition",
108 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
109 exp_name
=> "boot_disk1" ,
112 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
116 desc
=> "label test of pattern match",
119 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
120 exp_name
=> "boot_disk1" ,
123 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
124 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
125 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
126 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
130 desc
=> "label test of multiple sysfs files",
133 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
134 exp_name
=> "boot_disk1" ,
137 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
138 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
142 desc
=> "label test of max sysfs files (skip invalid rule)",
145 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
146 exp_name
=> "boot_disk1" ,
149 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"
150 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
154 desc
=> "catch device by *",
157 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
158 exp_name
=> "modem/0" ,
161 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
165 desc
=> "catch device by * - take 2",
168 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
169 exp_name
=> "modem/0" ,
172 KERNEL=="*ACM1", SYMLINK+="bad"
173 KERNEL=="*ACM0", SYMLINK+="modem/%n"
177 desc
=> "catch device by ?",
180 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
181 exp_name
=> "modem/0" ,
184 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
185 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
186 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
190 desc
=> "catch device by character class",
193 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
194 exp_name
=> "modem/0" ,
197 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
198 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
199 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
203 desc
=> "replace kernel name",
206 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
207 exp_name
=> "modem" ,
210 KERNEL=="ttyACM0", SYMLINK+="modem"
214 desc
=> "Handle comment lines in config file (and replace kernel name)",
217 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
218 exp_name
=> "modem" ,
222 KERNEL=="ttyACM0", SYMLINK+="modem"
227 desc
=> "Handle comment lines in config file with whitespace (and replace kernel name)",
230 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
231 exp_name
=> "modem" ,
234 # this is a comment with whitespace before the comment
235 KERNEL=="ttyACM0", SYMLINK+="modem"
240 desc
=> "Handle whitespace only lines (and replace kernel name)",
243 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
244 exp_name
=> "whitespace" ,
250 # this is a comment with whitespace before the comment
251 KERNEL=="ttyACM0", SYMLINK+="whitespace"
258 desc
=> "Handle empty lines in config file (and replace kernel name)",
261 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
262 exp_name
=> "modem" ,
266 KERNEL=="ttyACM0", SYMLINK+="modem"
271 desc
=> "Handle backslashed multi lines in config file (and replace kernel name)",
274 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
275 exp_name
=> "modem" ,
278 KERNEL=="ttyACM0", \\
284 desc
=> "preserve backslashes, if they are not for a newline",
287 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
291 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
295 desc
=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
298 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
299 exp_name
=> "modem" ,
310 KERNEL=="ttyACM0", \\
316 desc
=> "subdirectory handling",
319 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
320 exp_name
=> "sub/direct/ory/modem" ,
323 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
327 desc
=> "parent device name match of scsi partition",
330 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
331 exp_name
=> "first_disk5" ,
334 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
338 desc
=> "test substitution chars",
341 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
342 exp_name
=> "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
345 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
349 desc
=> "import of shell-value returned from program",
352 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
353 exp_name
=> "node12345678",
356 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
357 KERNEL=="ttyACM0", SYMLINK+="modem"
361 desc
=> "sustitution of sysfs value (%s{file})",
364 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
365 exp_name
=> "disk-ATA-sda" ,
368 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
369 KERNEL=="ttyACM0", SYMLINK+="modem"
373 desc
=> "program result substitution",
376 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
377 exp_name
=> "special-device-5" ,
378 not_exp_name
=> "not" ,
381 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
382 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
386 desc
=> "program result substitution (newline removal)",
389 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
390 exp_name
=> "newline_removed" ,
393 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
397 desc
=> "program result substitution",
400 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
401 exp_name
=> "test-0:0:0:0" ,
404 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
408 desc
=> "program with lots of arguments",
411 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
415 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
419 desc
=> "program with subshell",
422 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
426 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
430 desc
=> "program arguments combined with apostrophes",
433 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
437 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
441 desc
=> "program arguments combined with escaped double quotes, part 1",
444 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
448 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
452 desc
=> "program arguments combined with escaped double quotes, part 2",
455 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
459 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}"
463 desc
=> "program arguments combined with escaped double quotes, part 3",
466 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
470 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
474 desc
=> "characters before the %c{N} substitution",
477 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
478 exp_name
=> "my-foo9" ,
481 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
485 desc
=> "substitute the second to last argument",
488 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
489 exp_name
=> "my-foo8" ,
492 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
496 desc
=> "test substitution by variable name",
499 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
500 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
503 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
507 desc
=> "test substitution by variable name 2",
510 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
511 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
514 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
518 desc
=> "test substitution by variable name 3",
521 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
522 exp_name
=> "850:0:0:05" ,
525 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
529 desc
=> "test substitution by variable name 4",
532 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
536 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
540 desc
=> "test substitution by variable name 5",
543 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
544 exp_name
=> "8550:0:0:0" ,
547 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
551 desc
=> "non matching SUBSYSTEMS for device with no parent",
554 devpath
=> "/devices/virtual/tty/console",
558 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
559 KERNEL=="console", SYMLINK+="TTY"
563 desc
=> "non matching SUBSYSTEMS",
566 devpath
=> "/devices/virtual/tty/console",
570 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
571 KERNEL=="console", SYMLINK+="TTY"
575 desc
=> "ATTRS match",
578 devpath
=> "/devices/virtual/tty/console",
582 KERNEL=="console", SYMLINK+="TTY"
583 ATTRS{dev}=="5:1", SYMLINK+="foo"
587 desc
=> "ATTR (empty file)",
590 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
591 exp_name
=> "empty" ,
594 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
595 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
596 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
597 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
601 desc
=> "ATTR (non-existent file)",
604 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
605 exp_name
=> "non-existent" ,
608 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
609 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
610 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
611 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
612 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
613 KERNEL=="sda", SYMLINK+="wrong"
617 desc
=> "program and bus type match",
620 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
621 exp_name
=> "scsi-0:0:0:0" ,
624 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
625 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
626 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
630 desc
=> "sysfs parent hierarchy",
633 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
634 exp_name
=> "modem" ,
637 ATTRS{idProduct}=="007b", SYMLINK+="modem"
641 desc
=> "name test with ! in the name",
644 devpath
=> "/devices/virtual/block/fake!blockdev0",
645 devnode
=> "fake/blockdev0",
646 exp_name
=> "is/a/fake/blockdev0" ,
649 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
650 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
651 KERNEL=="ttyACM0", SYMLINK+="modem"
655 desc
=> "name test with ! in the name, but no matching rule",
658 devpath
=> "/devices/virtual/block/fake!blockdev0",
659 devnode
=> "fake/blockdev0",
660 exp_rem_error
=> "yes",
663 KERNEL=="ttyACM0", SYMLINK+="modem"
667 desc
=> "KERNELS rule",
670 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
671 exp_name
=> "scsi-0:0:0:0",
674 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
675 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
676 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
677 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
678 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
682 desc
=> "KERNELS wildcard all",
685 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
686 exp_name
=> "scsi-0:0:0:0",
689 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
690 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
691 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
692 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
693 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
697 desc
=> "KERNELS wildcard partial",
700 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
701 exp_name
=> "scsi-0:0:0:0",
704 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
705 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
709 desc
=> "KERNELS wildcard partial 2",
712 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
713 exp_name
=> "scsi-0:0:0:0",
716 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
717 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
721 desc
=> "substitute attr with link target value (first match)",
724 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
725 exp_name
=> "driver-is-sd",
728 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
732 desc
=> "substitute attr with link target value (currently selected device)",
735 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
736 exp_name
=> "driver-is-ahci",
739 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
743 desc
=> "ignore ATTRS attribute whitespace",
746 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
747 exp_name
=> "ignored",
750 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
754 desc
=> "do not ignore ATTRS attribute whitespace",
757 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
758 exp_name
=> "matched-with-space",
761 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
762 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
766 desc
=> "permissions USER=bad GROUP=name",
769 devpath
=> "/devices/virtual/tty/tty33",
770 exp_perms
=> "0:0:0600",
773 KERNEL=="tty33", OWNER="bad", GROUP="name"
777 desc
=> "permissions OWNER=1",
780 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
782 exp_perms
=> "1::0600",
785 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
789 desc
=> "permissions GROUP=1",
792 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
794 exp_perms
=> ":1:0660",
797 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
801 desc
=> "textual user id",
804 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
806 exp_perms
=> "daemon::0600",
809 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="daemon"
813 desc
=> "textual group id",
816 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
818 exp_perms
=> ":daemon:0660",
821 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
825 desc
=> "textual user/group id",
828 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
830 exp_perms
=> "root:audio:0660",
833 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="audio"
837 desc
=> "permissions MODE=0777",
840 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
842 exp_perms
=> "::0777",
845 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
849 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
852 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
854 exp_perms
=> "1:1:0777",
857 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
861 desc
=> "permissions OWNER to 1",
864 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
868 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
872 desc
=> "permissions GROUP to 1",
875 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
876 exp_perms
=> ":1:0660",
879 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
883 desc
=> "permissions MODE to 0060",
886 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
887 exp_perms
=> "::0060",
890 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
894 desc
=> "permissions OWNER, GROUP, MODE",
897 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
898 exp_perms
=> "1:1:0777",
901 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
905 desc
=> "permissions only rule",
908 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
909 exp_perms
=> "1:1:0777",
912 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
913 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
914 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
918 desc
=> "multiple permissions only rule",
921 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
922 exp_perms
=> "1:1:0777",
925 SUBSYSTEM=="tty", OWNER="1"
926 SUBSYSTEM=="tty", GROUP="1"
927 SUBSYSTEM=="tty", MODE="0777"
928 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
929 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
933 desc
=> "permissions only rule with override at SYMLINK+ rule",
936 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
937 exp_perms
=> "1:2:0777",
940 SUBSYSTEM=="tty", OWNER="1"
941 SUBSYSTEM=="tty", GROUP="1"
942 SUBSYSTEM=="tty", MODE="0777"
943 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
944 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
948 desc
=> "major/minor number test",
951 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
953 exp_majorminor
=> "8:0",
956 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
960 desc
=> "big major number test",
963 devpath
=> "/devices/virtual/misc/misc-fake1",
965 exp_majorminor
=> "4095:1",
968 KERNEL=="misc-fake1", SYMLINK+="node"
972 desc
=> "big major and big minor number test",
975 devpath
=> "/devices/virtual/misc/misc-fake89999",
977 exp_majorminor
=> "4095:89999",
980 KERNEL=="misc-fake89999", SYMLINK+="node"
984 desc
=> "multiple symlinks with format char",
987 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
988 exp_name
=> "symlink2-ttyACM0",
991 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
995 desc
=> "multiple symlinks with a lot of s p a c e s",
998 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1000 not_exp_name
=> " ",
1003 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
1007 desc
=> "symlink with spaces in substituted variable",
1010 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1011 exp_name
=> "name-one_two_three-end",
1012 not_exp_name
=> " ",
1015 ENV{WITH_WS}="one two three"
1016 SYMLINK="name-\$env{WITH_WS}-end"
1020 desc
=> "symlink with leading space in substituted variable",
1023 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1024 exp_name
=> "name-one_two_three-end",
1025 not_exp_name
=> " ",
1028 ENV{WITH_WS}=" one two three"
1029 SYMLINK="name-\$env{WITH_WS}-end"
1033 desc
=> "symlink with trailing space in substituted variable",
1036 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1037 exp_name
=> "name-one_two_three-end",
1038 not_exp_name
=> " ",
1041 ENV{WITH_WS}="one two three "
1042 SYMLINK="name-\$env{WITH_WS}-end"
1046 desc
=> "symlink with lots of space in substituted variable",
1049 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1050 exp_name
=> "name-one_two_three-end",
1051 not_exp_name
=> " ",
1054 ENV{WITH_WS}=" one two three "
1055 SYMLINK="name-\$env{WITH_WS}-end"
1059 desc
=> "symlink with multiple spaces in substituted variable",
1062 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1063 exp_name
=> "name-one_two_three-end",
1064 not_exp_name
=> " ",
1067 ENV{WITH_WS}=" one two three "
1068 SYMLINK="name-\$env{WITH_WS}-end"
1072 desc
=> "symlink with space and var with space, part 1",
1075 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1076 exp_name
=> "first",
1077 not_exp_name
=> " ",
1080 ENV{WITH_WS}=" one two three "
1081 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
1085 desc
=> "symlink with space and var with space, part 2",
1088 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1089 exp_name
=> "name-one_two_three-end",
1090 not_exp_name
=> " ",
1093 ENV{WITH_WS}=" one two three "
1094 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
1098 desc
=> "symlink with space and var with space, part 3",
1101 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1102 exp_name
=> "another_symlink",
1103 not_exp_name
=> " ",
1106 ENV{WITH_WS}=" one two three "
1107 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
1111 desc
=> "symlink creation (same directory)",
1114 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1115 exp_name
=> "modem0",
1118 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
1122 desc
=> "multiple symlinks",
1125 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1126 exp_name
=> "second-0" ,
1129 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
1133 desc
=> "symlink name '.'",
1136 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1138 exp_add_error
=> "yes",
1139 exp_rem_error
=> "yes",
1142 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
1146 desc
=> "symlink node to itself",
1149 devpath
=> "/devices/virtual/tty/tty0",
1151 exp_add_error
=> "yes",
1152 exp_rem_error
=> "yes",
1156 KERNEL=="tty0", SYMLINK+="tty0"
1160 desc
=> "symlink %n substitution",
1163 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1164 exp_name
=> "symlink0",
1167 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
1171 desc
=> "symlink %k substitution",
1174 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1175 exp_name
=> "symlink-ttyACM0",
1178 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
1182 desc
=> "symlink %M:%m substitution",
1185 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1186 exp_name
=> "major-166:0",
1189 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
1193 desc
=> "symlink %b substitution",
1196 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1197 exp_name
=> "symlink-0:0:0:0",
1200 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
1204 desc
=> "symlink %c substitution",
1207 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1211 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
1215 desc
=> "symlink %c{N} substitution",
1218 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1222 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
1226 desc
=> "symlink %c{N+} substitution",
1229 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1233 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
1237 desc
=> "symlink only rule with %c{N+}",
1240 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1244 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
1248 desc
=> "symlink %s{filename} substitution",
1251 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1252 exp_name
=> "166:0",
1255 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
1259 desc
=> "program result substitution (numbered part of)",
1262 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
1263 exp_name
=> "link1",
1266 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
1270 desc
=> "program result substitution (numbered part of+)",
1273 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
1274 exp_name
=> "link4",
1277 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
1281 desc
=> "SUBSYSTEM match test",
1284 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1288 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
1289 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
1290 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
1294 desc
=> "DRIVERS match test",
1297 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1301 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
1302 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
1306 desc
=> "devnode substitution test",
1309 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1313 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1317 desc
=> "parent node name substitution test",
1320 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1321 exp_name
=> "sda-part-1",
1324 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1328 desc
=> "udev_root substitution",
1331 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1332 exp_name
=> "start-/dev-end",
1335 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1339 desc
=> "last_rule option",
1342 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1346 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1347 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1351 desc
=> "negation KERNEL!=",
1354 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1355 exp_name
=> "match",
1358 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1359 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1360 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1364 desc
=> "negation SUBSYSTEM!=",
1367 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1368 exp_name
=> "not-anything",
1371 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1372 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1373 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1377 desc
=> "negation PROGRAM!= exit code",
1380 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1381 exp_name
=> "nonzero-program",
1384 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1385 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1389 desc
=> "ENV{} test",
1392 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1396 ENV{ENV_KEY_TEST}="test"
1397 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1398 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1399 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1403 desc
=> "ENV{} test",
1406 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1410 ENV{ENV_KEY_TEST}="test"
1411 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1412 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1413 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1414 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1418 desc
=> "ENV{} test (assign)",
1421 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1425 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1426 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1427 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1428 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1432 desc
=> "ENV{} test (assign 2 times)",
1435 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1439 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1440 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1441 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1442 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1443 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1447 desc
=> "ENV{} test (assign2)",
1450 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1454 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1455 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1456 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1457 SUBSYSTEM=="block", SYMLINK+="before"
1458 ENV{PARTITION}=="true", SYMLINK+="part"
1462 desc
=> "untrusted string sanitize",
1465 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1469 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1473 desc
=> "untrusted string sanitize (don't replace utf8)",
1476 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1480 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1484 desc
=> "untrusted string sanitize (replace invalid utf8)",
1487 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1488 exp_name
=> "replaced",
1491 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1495 desc
=> "read sysfs value from parent device",
1498 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1499 exp_name
=> "serial-354172020305000",
1502 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1506 desc
=> "match against empty key string",
1509 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1513 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1514 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1515 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1516 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1520 desc
=> "check ACTION value",
1523 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1527 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1528 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1532 desc
=> "final assignment",
1535 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1537 exp_perms
=> "root:tty:0640",
1540 KERNEL=="sda", GROUP:="tty"
1541 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1545 desc
=> "final assignment 2",
1548 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1550 exp_perms
=> "root:tty:0640",
1553 KERNEL=="sda", GROUP:="tty"
1554 SUBSYSTEM=="block", MODE:="640"
1555 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1559 desc
=> "env substitution",
1562 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1563 exp_name
=> "node-add-me",
1566 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1570 desc
=> "reset list to current value",
1573 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1574 exp_name
=> "three",
1575 not_exp_name
=> "two",
1578 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1579 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1580 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1584 desc
=> "test empty SYMLINK+ (empty override)",
1587 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1588 exp_name
=> "right",
1589 not_exp_name
=> "wrong",
1592 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1593 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1594 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1598 desc
=> "test multi matches",
1601 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1602 exp_name
=> "right",
1605 KERNEL=="ttyACM*", SYMLINK+="before"
1606 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1610 desc
=> "test multi matches 2",
1613 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1614 exp_name
=> "right",
1617 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1618 KERNEL=="ttyACM*", SYMLINK+="before"
1619 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1623 desc
=> "test multi matches 3",
1626 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1627 exp_name
=> "right",
1630 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1631 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1632 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1633 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1637 desc
=> "test multi matches 4",
1640 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1641 exp_name
=> "right",
1644 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1645 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1646 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1647 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1648 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1652 desc
=> "test multi matches 5",
1655 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1656 exp_name
=> "found",
1657 not_exp_name
=> "bad",
1660 KERNEL=="sda", TAG="foo"
1661 TAGS=="|foo", SYMLINK+="found"
1662 TAGS=="|aaa", SYMLINK+="bad"
1666 desc
=> "test multi matches 6",
1669 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1670 exp_name
=> "found",
1671 not_exp_name
=> "bad",
1674 KERNEL=="sda", TAG=""
1675 TAGS=="|foo", SYMLINK+="found"
1676 TAGS=="aaa|bbb", SYMLINK+="bad"
1680 desc
=> "test multi matches 7",
1683 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1684 exp_name
=> "found",
1685 not_exp_name
=> "bad",
1688 KERNEL=="sda", TAG="foo"
1689 TAGS=="foo||bar", SYMLINK+="found"
1690 TAGS=="aaa||bbb", SYMLINK+="bad"
1694 desc
=> "test multi matches 8",
1697 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1698 exp_name
=> "found",
1699 not_exp_name
=> "bad",
1702 KERNEL=="sda", TAG=""
1703 TAGS=="foo||bar", SYMLINK+="found"
1704 TAGS=="aaa|bbb", SYMLINK+="bad"
1708 desc
=> "test multi matches 9",
1711 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1712 exp_name
=> "found",
1713 not_exp_name
=> "bad",
1716 KERNEL=="sda", TAG="foo"
1717 TAGS=="foo|", SYMLINK+="found"
1718 TAGS=="aaa|", SYMLINK+="bad"
1722 desc
=> "test multi matches 10",
1725 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1726 exp_name
=> "found",
1727 not_exp_name
=> "bad",
1730 KERNEL=="sda", TAG=""
1731 TAGS=="foo|", SYMLINK+="found"
1732 TAGS=="aaa|bbb", SYMLINK+="bad"
1736 desc
=> "test multi matches 11",
1739 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1740 exp_name
=> "found",
1741 not_exp_name
=> "bad",
1744 KERNEL=="sda", TAG="c"
1745 TAGS=="foo||bar||c", SYMLINK+="found"
1746 TAGS=="aaa||bbb||ccc", SYMLINK+="bad"
1750 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1753 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1754 exp_name
=> "parent",
1758 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1759 KERNEL=="sda", SYMLINK+="parent"
1763 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1766 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1767 exp_name
=> "parentenv-parent_right",
1771 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1775 desc
=> "GOTO test",
1778 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1779 exp_name
=> "right",
1782 KERNEL=="sda1", GOTO="TEST"
1783 KERNEL=="sda1", SYMLINK+="wrong"
1784 KERNEL=="sda1", GOTO="BAD"
1785 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1786 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1787 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1792 desc
=> "GOTO label does not exist",
1795 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1796 exp_name
=> "right",
1799 KERNEL=="sda1", GOTO="does-not-exist"
1800 KERNEL=="sda1", SYMLINK+="right",
1805 desc
=> "SYMLINK+ compare test",
1808 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1809 exp_name
=> "right",
1810 not_exp_name
=> "wrong",
1813 KERNEL=="sda1", SYMLINK+="link"
1814 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1815 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1819 desc
=> "invalid key operation",
1822 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1826 KERNEL="sda1", SYMLINK+="no"
1827 KERNEL=="sda1", SYMLINK+="yes"
1831 desc
=> "operator chars in attribute",
1834 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1838 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1842 desc
=> "overlong comment line",
1845 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1849 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1850 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1851 KERNEL=="sda1", SYMLINK+=="no"
1852 KERNEL=="sda1", SYMLINK+="yes"
1856 desc
=> "magic subsys/kernel lookup",
1859 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1860 exp_name
=> "00:16:41:e2:8d:ff",
1863 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1867 desc
=> "TEST absolute path",
1870 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1871 exp_name
=> "there",
1874 TEST=="/etc/machine-id", SYMLINK+="there"
1875 TEST!="/etc/machine-id", SYMLINK+="notthere"
1879 desc
=> "TEST subsys/kernel lookup",
1882 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1886 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1890 desc
=> "TEST relative path",
1893 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1894 exp_name
=> "relative",
1897 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1901 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1904 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1905 exp_name
=> "found-subdir",
1908 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1912 desc
=> "TEST MODE=0000",
1915 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1916 exp_perms
=> "0:0:0000",
1917 exp_rem_error
=> "yes",
1920 KERNEL=="sda", MODE="0000"
1924 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1927 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1928 exp_perms
=> "1:1:0400",
1929 exp_rem_error
=> "yes",
1932 KERNEL=="sda", MODE="666"
1933 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1937 desc
=> "TEST PROGRAM feeds MODE with overflow",
1940 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1941 exp_perms
=> "0:0:0440",
1942 exp_rem_error
=> "yes",
1945 KERNEL=="sda", MODE="440"
1946 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1950 desc
=> "magic [subsys/sysname] attribute substitution",
1953 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1954 exp_name
=> "sda-8741C4G-end",
1955 exp_perms
=> "0:0:0600",
1958 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1959 KERNEL=="sda", ENV{TESTENV}="change-envp"
1960 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1964 desc
=> "builtin path_id",
1967 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1968 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1971 KERNEL=="sda", IMPORT{builtin}="path_id"
1972 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1976 desc
=> "add and match tag",
1979 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1980 exp_name
=> "found",
1981 not_exp_name
=> "bad" ,
1984 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1985 TAGS=="green", SYMLINK+="found"
1986 TAGS=="blue", SYMLINK+="bad"
1990 desc
=> "don't crash with lots of tags",
1993 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1994 exp_name
=> "found",
1996 rules
=> $rules_10k_tags . <<EOF
1997 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
2001 desc
=> "continuations",
2004 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2005 exp_name
=> "found",
2006 not_exp_name
=> "bad",
2008 rules
=> $rules_10k_tags_continuation . <<EOF
2009 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="bad"
2011 # comment in continuation
2013 # space before comment
2015 # spaces before and after token are dropped
2020 TAGS=="hoge1", TAGS=="hoge2", TAGS=="hoge3", TAGS=="hoge4", SYMLINK+="found"
2024 desc
=> "continuations with empty line",
2027 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2028 exp_name
=> "found",
2029 not_exp_name
=> "bad",
2033 # empty line finishes continuation
2034 KERNEL=="sda", TAG+="foo" \\
2036 KERNEL=="sdb", TAG+="hoge"
2037 KERNEL=="sda", TAG+="aaa" \\
2038 KERNEL=="sdb", TAG+="bbb"
2039 TAGS=="foo", SYMLINK+="found"
2040 TAGS=="aaa", SYMLINK+="bad"
2044 desc
=> "continuations with white only line",
2047 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
2048 exp_name
=> "found",
2049 not_exp_name
=> "bad",
2052 # space only line finishes continuation
2053 KERNEL=="sda", TAG+="foo" \\
2055 KERNEL=="sdb", TAG+="hoge"
2056 KERNEL=="sda", TAG+="aaa" \\
2057 KERNEL=="sdb", TAG+="bbb"
2058 TAGS=="foo", SYMLINK+="found"
2059 TAGS=="aaa", SYMLINK+="bad"
2067 # create temporary rules
2068 system("mkdir", "-p", "$udev_rules_dir");
2069 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
2075 my ($action, $devpath) = @_;
2077 if ($valgrind > 0) {
2078 return system("$udev_bin_valgrind $action $devpath");
2079 } elsif ($gdb > 0) {
2080 return system("$udev_bin_gdb $action $devpath");
2081 } elsif ($strace > 0) {
2082 return system("$udev_bin_strace $action $devpath");
2084 return system("$udev_bin", "$action", "$devpath");
2090 sub permissions_test
{
2091 my($rules, $uid, $gid, $mode) = @_;
2097 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
2099 if (defined(getpwnam($1))) {
2100 $userid = int(getpwnam($1));
2104 if ($uid != $userid) { $wrong = 1; }
2107 if (defined(getgrnam($2))) {
2108 $groupid = int(getgrnam($2));
2112 if ($gid != $groupid) { $wrong = 1; }
2115 if (($mode & 07777) != oct($3)) { $wrong = 1; };
2118 print "permissions: ok\n";
2120 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
2121 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
2122 print "permissions: error\n";
2128 sub major_minor_test
{
2129 my($rules, $rdev) = @_;
2131 my $major = ($rdev >> 8) & 0xfff;
2132 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
2135 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
2137 if ($major != $1) { $wrong = 1; };
2140 if ($minor != $2) { $wrong = 1; };
2143 print "major:minor: ok\n";
2145 printf " expected major:minor is: %i:%i\n", $1, $2;
2146 printf " created major:minor is : %i:%i\n", $major, $minor;
2147 print "major:minor: error\n";
2154 system("umount", $udev_tmpfs);
2156 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
2158 if (system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) {
2159 warn "unable to mount tmpfs";
2163 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
2164 # setting group and mode of udev_dev ensures the tests work
2165 # even if the parent directory has setgid bit enabled.
2166 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
2167 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
2169 if (system("mknod", $udev_dev . "/null", "c", "1", "3")) {
2170 warn "unable to create $udev_dev/null";
2174 # check if we are permitted to create block device nodes
2175 my $block_device_filename = $udev_dev . "/sda";
2176 if (system("mknod", $block_device_filename, "b", "8", "0")) {
2177 warn "unable to create $block_device_filename";
2180 unlink $block_device_filename;
2182 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
2184 system("rm", "-rf", "$udev_run");
2186 if (!mkdir($udev_run)) {
2187 warn "unable to create directory $udev_run";
2198 if (defined($device->{devnode
})) {
2199 $devnode = "$udev_dev/$device->{devnode}";
2201 $devnode = "$device->{devpath}";
2202 $devnode =~ s!.*/!$udev_dev/!;
2209 my $devnode = get_devnode
($device);
2211 my @st = lstat("$devnode");
2212 if (! (-b _
|| -c _
)) {
2213 print "add $devnode: error\n";
2214 system("tree", "$udev_dev");
2219 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
2220 $atime, $mtime, $ctime, $blksize, $blocks) = @st;
2222 if (defined($device->{exp_perms
})) {
2223 permissions_test
($device, $uid, $gid, $mode);
2225 if (defined($device->{exp_majorminor
})) {
2226 major_minor_test
($device, $rdev);
2228 print "add $devnode: ok\n";
2235 if (defined($device->{not_exp_name
})) {
2236 if ((-e
"$udev_dev/$device->{not_exp_name}") ||
2237 (-l
"$udev_dev/$device->{not_exp_name}")) {
2238 print "nonexistent: error \'$device->{not_exp_name}\' not expected to be there\n";
2244 my $devnode = check_devnode
($device);
2246 print "device \'$device->{devpath}\' expecting node/link \'$device->{exp_name}\'\n";
2247 return if (!defined($device->{exp_name
}));
2249 if ((-e
"$udev_dev/$device->{exp_name}") ||
2250 (-l
"$udev_dev/$device->{exp_name}")) {
2251 print "add $device->{devpath}: ok\n";
2253 print "add $device->{devpath}: error";
2254 if ($device->{exp_add_error
}) {
2255 print " as expected\n";
2258 system("tree", "$udev_dev");
2266 sub check_remove_devnode
{
2268 my $devnode = get_devnode
($device);
2270 if (-e
"$devnode") {
2271 print "remove $devnode: error";
2273 system("tree", "$udev_dev");
2278 print "remove $devnode: ok\n";
2285 check_remove_devnode
($device);
2287 return if (!defined($device->{exp_name
}));
2289 if ((-e
"$udev_dev/$device->{exp_name}") ||
2290 (-l
"$udev_dev/$device->{exp_name}")) {
2291 print "remove $device->{exp_name}: error";
2292 if ($device->{exp_rem_error
}) {
2293 print " as expected\n";
2296 system("tree", "$udev_dev");
2302 print "remove $device->{exp_name}: ok\n";
2307 my ($action, $dev, $sleep_us, $sema) = @_;
2309 # Notify main process that this worker has started
2314 usleep
($sleep_us) if defined ($sleep_us);
2315 my $rc = udev
($action, $dev->{devpath
});
2319 sub fork_and_run_udev
{
2320 my ($action, $rules, $sema) = @_;
2321 my @devices = @
{$rules->{devices
}};
2325 $sema->setval(0, 1);
2326 foreach $dev (@devices) {
2330 run_udev
($action, $dev,
2331 defined($rules->{sleep_us
}) ?
$k * $rules->{sleep_us
} : undef,
2339 # This operation waits for all workers to become ready, and
2340 # starts them off when that's the case.
2341 $sema->op(0, -($#devices + 2), 0);
2343 foreach $dev (@devices) {
2347 $pid = waitpid($dev->{pid
}, 0);
2349 print "error waiting for pid dev->{pid}\n";
2352 if (WIFEXITED
($?
)) {
2353 $rc = WEXITSTATUS
($?
);
2356 print "$udev_bin $action for $dev->{devpath} failed with code $rc\n";
2364 my ($rules, $number, $sema) = @_;
2366 my @devices = @
{$rules->{devices
}};
2368 print "TEST $number: $rules->{desc}\n";
2369 create_rules
(\
$rules->{rules
});
2371 fork_and_run_udev
("add", $rules, $sema);
2373 foreach my $dev (@devices) {
2377 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
2382 fork_and_run_udev
("remove", $rules, $sema);
2384 foreach my $dev (@devices) {
2390 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
2397 system("rm", "-rf", "$udev_run");
2398 system("umount", "$udev_tmpfs");
2402 # only run if we have root permissions
2403 # due to mknod restrictions
2405 print "Must have root permissions to run properly.\n";
2406 exit($EXIT_TEST_SKIP);
2409 # skip the test when running in a chroot
2410 system("systemd-detect-virt", "-r", "-q");
2412 print "Running in a chroot, skipping the test.\n";
2413 exit($EXIT_TEST_SKIP);
2416 if (!udev_setup
()) {
2417 warn "Failed to set up the environment, skipping the test";
2419 exit($EXIT_TEST_SKIP);
2422 if (system($udev_bin, "check")) {
2423 warn "$udev_bin failed to set up the environment, skipping the test";
2425 exit($EXIT_TEST_SKIP);
2431 foreach my $arg (@ARGV) {
2432 if ($arg =~ m/--valgrind/) {
2434 printf("using valgrind\n");
2435 } elsif ($arg =~ m/--gdb/) {
2437 printf("using gdb\n");
2438 } elsif ($arg =~ m/--strace/) {
2440 printf("using strace\n");
2445 my $sema = IPC
::Semaphore
->new(IPC_PRIVATE
, 1, S_IRUSR
| S_IWUSR
| IPC_CREAT
);
2448 foreach my $arg (@list) {
2449 if (defined($tests[$arg-1]->{desc
})) {
2450 print "udev-test will run test number $arg:\n\n";
2451 run_test
($tests[$arg-1], $arg, $sema);
2453 print "test does not exist.\n";
2458 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
2460 foreach my $rules (@tests) {
2461 run_test
($rules, $test_num, $sema);
2467 print "$error errors occurred\n\n";