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 reads the config, 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.
18 # Kay Sievers <kay.sievers@vrfy.org>, 2003
20 # Modified April 9, 2004 by Leann Ogasawara <ogasawara@osdl.org>
21 # - expanded @tests array to add more symlinks and permissions tests
22 # - some of the symlinks tests also test lack of node creation
23 # - added symlink_test() function
24 # - moved permissions and major_minor tests into their own functions
31 my $udev_bin = "../udev";
32 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
33 my $udev_db = ".udevdb";
34 my $perm = "udev.permissions";
35 my $main_conf = "udev-test.conf";
36 my $conf_tmp = "udev-test.rules";
38 # uncomment following line to run udev with valgrind.
39 # Should make this a runtime option to the script someday...
40 #my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev";
44 desc => "label test of scsi disc",
46 devpath => "/block/sda",
47 exp_name => "boot_disk" ,
49 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
50 KERNEL="ttyUSB0", NAME="visor"
54 desc => "label test of scsi partition",
56 devpath => "/block/sda/sda1",
57 exp_name => "boot_disk1" ,
59 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="boot_disk%n"
63 desc => "label test of pattern match",
65 devpath => "/block/sda/sda1",
66 exp_name => "boot_disk1" ,
68 BUS="scsi", SYSFS{vendor}="?IBM-ESXS", NAME="boot_disk%n-1"
69 BUS="scsi", SYSFS{vendor}="IBM-ESXS?", NAME="boot_disk%n-2"
70 BUS="scsi", SYSFS{vendor}="IBM-ES??", NAME="boot_disk%n"
71 BUS="scsi", SYSFS{vendor}="IBM-ESXSS", NAME="boot_disk%n-3"
75 desc => "label test of multiple sysfs files",
77 devpath => "/block/sda/sda1",
78 exp_name => "boot_disk1" ,
80 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_diskX%n"
81 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", NAME="boot_disk%n"
85 desc => "label test of max sysfs files",
87 devpath => "/block/sda/sda1",
88 exp_name => "boot_disk1" ,
90 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="2", SYSFS{queue_depth}="32", NAME="boot_diskXX%n"
91 BUS="scsi", SYSFS{vendor}="IBM-ESXS", SYSFS{model}="ST336605LW !#", SYSFS{scsi_level}="4", SYSFS{rev}="B245", SYSFS{type}="0", NAME="boot_disk%n"
95 desc => "catch device by *",
97 devpath => "/class/tty/ttyUSB0",
98 exp_name => "visor/0" ,
100 KERNEL="ttyUSB*", NAME="visor/%n"
104 desc => "catch device by * - take 2",
106 devpath => "/class/tty/ttyUSB0",
107 exp_name => "visor/0" ,
109 KERNEL="*USB1", NAME="bad"
110 KERNEL="*USB0", NAME="visor/%n"
114 desc => "catch device by ?",
116 devpath => "/class/tty/ttyUSB0",
117 exp_name => "visor/0" ,
119 KERNEL="ttyUSB??*", NAME="visor/%n-1"
120 KERNEL="ttyUSB??", NAME="visor/%n-2"
121 KERNEL="ttyUSB?", NAME="visor/%n"
125 desc => "catch device by character class",
127 devpath => "/class/tty/ttyUSB0",
128 exp_name => "visor/0" ,
130 KERNEL="ttyUSB[A-Z]*", NAME="visor/%n-1"
131 KERNEL="ttyUSB?[0-9]", NAME="visor/%n-2"
132 KERNEL="ttyUSB[0-9]*", NAME="visor/%n"
136 desc => "replace kernel name",
138 devpath => "/class/tty/ttyUSB0",
139 exp_name => "visor" ,
141 KERNEL="ttyUSB0", NAME="visor"
145 desc => "Handle comment lines in config file (and replace kernel name)",
147 devpath => "/class/tty/ttyUSB0",
148 exp_name => "visor" ,
151 KERNEL="ttyUSB0", NAME="visor"
156 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
158 devpath => "/class/tty/ttyUSB0",
159 exp_name => "visor" ,
161 # this is a comment with whitespace before the comment
162 KERNEL="ttyUSB0", NAME="visor"
167 desc => "Handle whitespace only lines (and replace kernel name)",
169 devpath => "/class/tty/ttyUSB0",
170 exp_name => "whitespace" ,
175 # this is a comment with whitespace before the comment
176 KERNEL="ttyUSB0", NAME="whitespace"
183 desc => "Handle empty lines in config file (and replace kernel name)",
185 devpath => "/class/tty/ttyUSB0",
186 exp_name => "visor" ,
189 KERNEL="ttyUSB0", NAME="visor"
194 desc => "subdirectory handling",
196 devpath => "/class/tty/ttyUSB0",
197 exp_name => "sub/direct/ory/visor" ,
199 KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
203 desc => "place on bus of scsi partition",
205 devpath => "/block/sda/sda3",
206 exp_name => "first_disk3" ,
208 BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
212 desc => "test NAME substitution chars",
214 devpath => "/block/sda/sda3",
215 exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
217 BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
221 desc => "test NAME substitution chars (with length limit)",
223 devpath => "/block/sda/sda3",
224 exp_name => "M8-m3-n3-b0:0-sIBM" ,
226 BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
230 desc => "old style SYSFS_ attribute",
232 devpath => "/block/sda",
235 BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="good"
239 desc => "sustitution of sysfs value (%s{file})",
241 devpath => "/block/sda",
242 exp_name => "disk-IBM-ESXS-sda" ,
244 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k"
245 KERNEL="ttyUSB0", NAME="visor"
249 desc => "program result substitution",
251 devpath => "/block/sda/sda3",
252 exp_name => "special-device-3" ,
254 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="-special-*", NAME="%c-1-%n"
255 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c-2-%n"
256 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n"
257 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n"
258 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n"
262 desc => "program result substitution (no argument should be subsystem)",
264 devpath => "/block/sda/sda3",
265 exp_name => "subsys_block" ,
267 BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block"
271 desc => "program result substitution (newline removal)",
273 devpath => "/block/sda/sda3",
274 exp_name => "newline_removed" ,
276 BUS="scsi", PROGRAM="/bin/echo test", RESULT="test", NAME="newline_removed"
280 desc => "program result substitution",
282 devpath => "/block/sda/sda3",
283 exp_name => "test-0:0:0:0" ,
285 BUS="scsi", PROGRAM="/bin/echo -n test-%b", RESULT="test-0:0*", NAME="%c"
289 desc => "program with escaped format char (tricky: callout returns format char!)",
291 devpath => "/block/sda/sda3",
292 exp_name => "escape-3" ,
294 BUS="scsi", PROGRAM="/bin/echo -n escape-%%n", KERNEL="sda3", NAME="%c"
298 desc => "program with lots of arguments",
300 devpath => "/block/sda/sda3",
303 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}"
307 desc => "program with subshell",
309 devpath => "/block/sda/sda3",
312 BUS="scsi", PROGRAM="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL="sda3", NAME="%c{7}"
316 desc => "program arguments combined with apostrophes",
318 devpath => "/block/sda/sda3",
321 BUS="scsi", PROGRAM="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL="sda3", NAME="%c{5}"
325 desc => "characters before the %c{N} substitution",
327 devpath => "/block/sda/sda3",
328 exp_name => "my-foo9" ,
330 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{7}"
334 desc => "substitute the second to last argument",
336 devpath => "/block/sda/sda3",
337 exp_name => "my-foo8" ,
339 BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="my-%c{6}"
343 desc => "invalid program for device with no bus",
345 devpath => "/class/tty/console",
348 BUS="scsi", PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
349 KERNEL="console", NAME="TTY"
353 desc => "valid program for device with no bus",
355 devpath => "/class/tty/console",
358 PROGRAM="/bin/echo -n foo", RESULT="foo", NAME="foo"
359 KERNEL="console", NAME="TTY"
363 desc => "invalid label for device with no bus",
365 devpath => "/class/tty/console",
368 BUS="foo", SYSFS{dev}="5:1", NAME="foo"
369 KERNEL="console", NAME="TTY"
373 desc => "valid label for device with no bus",
375 devpath => "/class/tty/console",
378 SYSFS{dev}="5:1", NAME="foo"
379 KERNEL="console", NAME="TTY"
383 desc => "program and bus type match",
385 devpath => "/block/sda",
386 exp_name => "scsi-0:0:0:0" ,
388 BUS="usb", PROGRAM="/bin/echo -n usb-%b", NAME="%c"
389 BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", NAME="%c"
390 BUS="foo", PROGRAM="/bin/echo -n foo-%b", NAME="%c"
394 desc => "create all possible partitions",
396 devpath => "/block/sda",
397 exp_name => "boot_disk15" ,
399 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME{all_partitions}="boot_disk"
403 desc => "sysfs parent hierarchy",
405 devpath => "/class/tty/ttyUSB0",
406 exp_name => "visor" ,
408 SYSFS{idProduct}="2008", NAME="visor"
412 desc => "name test with ! in the name",
414 devpath => "/block/rd!c0d0",
415 exp_name => "rd/c0d0" ,
417 BUS="scsi", NAME="%k"
418 KERNEL="ttyUSB0", NAME="visor"
422 desc => "name test with ! in the name, but no matching rule",
424 devpath => "/block/rd!c0d0",
425 exp_name => "rd/c0d0" ,
427 KERNEL="ttyUSB0", NAME="visor"
431 desc => "name test with ! in the name for a partition",
433 devpath => "/block/cciss!c0d0/cciss!c0d0p1",
434 exp_name => "cciss/c0d0p1" ,
436 BUS="scsi", NAME="%k"
437 KERNEL="ttyUSB0", NAME="visor"
443 devpath => "/block/sda",
444 exp_name => "scsi-0:0:0:0",
446 BUS="usb", ID="0:0:0:0", NAME="not-scsi"
447 BUS="scsi", ID="0:0:0:1", NAME="no-match"
448 BUS="scsi", ID=":0", NAME="short-id"
449 BUS="scsi", ID="/0:0:0:0", NAME="no-match"
450 BUS="scsi", ID="0:0:0:0", NAME="scsi-0:0:0:0"
454 desc => "ID wildcard all",
456 devpath => "/block/sda",
457 exp_name => "scsi-0:0:0:0",
459 BUS="scsi", ID="*:1", NAME="no-match"
460 BUS="scsi", ID="*:0:1", NAME="no-match"
461 BUS="scsi", ID="*:0:0:1", NAME="no-match"
462 BUS="scsi", ID="*", NAME="scsi-0:0:0:0"
463 BUS="scsi", ID="0:0:0:0", NAME="bad"
467 desc => "ID wildcard partial",
469 devpath => "/block/sda",
470 exp_name => "scsi-0:0:0:0",
472 BUS="scsi", ID="*:0", NAME="scsi-0:0:0:0"
473 BUS="scsi", ID="0:0:0:0", NAME="bad"
477 desc => "ID wildcard partial 2",
479 devpath => "/block/sda",
480 exp_name => "scsi-0:0:0:0",
482 BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0"
483 BUS="scsi", ID="0:0:0:0", NAME="bad"
487 desc => "ignore SYSFS attribute whitespace",
489 devpath => "/block/sda",
490 exp_name => "ignored",
492 BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored"
496 desc => "do not ignore SYSFS attribute whitespace",
498 devpath => "/block/sda",
499 exp_name => "matched-with-space",
501 BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore"
502 BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space"
506 desc => "permissions test",
508 devpath => "/block/sda",
510 exp_perms => "5000::0444",
512 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", MODE="0444"
516 desc => "permissions ttyUSB0:root:uucp:0660",
518 devpath => "/class/tty/ttyUSB0",
519 exp_name => "ttyUSB0",
520 exp_perms => "0:14:0660",
522 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n"
526 desc => "permissions tty0::root:0444",
528 devpath => "/class/tty/tty0",
530 exp_perms => "0:0:0444",
532 KERNEL="tty0", NAME="tty0"
536 desc => "permissions tty1:root::0555",
538 devpath => "/class/tty/tty1",
540 exp_perms => "0:0:0555",
542 KERNEL="tty1", NAME="tty1"
546 desc => "permissions tty2:::0777",
548 devpath => "/class/tty/tty2",
550 exp_perms => "0:0:0777",
552 KERNEL="tty2", NAME="tty2"
556 desc => "permissions tty3::: (default mode applied)",
558 devpath => "/class/tty/tty3",
560 exp_perms => "0:0:600",
562 KERNEL="tty3", NAME="tty3"
566 desc => "permissions i2c-300:root:sys:0744",
568 devpath => "/class/i2c-dev/i2c-300",
569 exp_name => "i2c-300",
570 exp_perms => "0:3:0744",
572 KERNEL="i2c-300", NAME="i2c-300"
576 desc => "permissions i2c-fake1:root:7:0007",
578 devpath => "/class/i2c-dev/i2c-fake1",
579 exp_name => "i2c-fake1",
580 exp_perms => "0:7:0007",
582 KERNEL="i2c-fake1", NAME="i2c-fake1"
586 desc => "permissions ttyS[01]:0:5:0700",
588 devpath => "/class/tty/ttyS1",
590 exp_perms => "0:5:0700",
592 KERNEL="ttyS1", NAME="ttyS1"
596 desc => "permissions ttyS[4-9]:tty:5:0060",
598 devpath => "/class/tty/ttyS7",
600 exp_perms => "0:5:0060",
602 KERNEL="ttyS7", NAME="ttyS7"
606 desc => "permissions tty4:0:5:0707",
608 devpath => "/class/tty/tty4",
610 exp_perms => "0:5:0707",
612 KERNEL="tty4", NAME="tty4"
616 desc => "permissions tty4?:0:5:0007",
618 devpath => "/class/tty/tty44",
620 exp_perms => "0:5:0007",
622 KERNEL="tty44", NAME="tty44"
626 desc => "permissions tty3[!3]:::0467",
628 devpath => "/class/tty/tty35",
630 exp_perms => "0:0:0467",
632 KERNEL="tty35", NAME="tty35"
636 desc => "permissions tty33:bad:name:0500",
638 devpath => "/class/tty/tty33",
640 exp_perms => "0:0:0500",
642 KERNEL="tty33", NAME="tty33"
646 desc => "permissions rtc:0:users:0600",
648 devpath => "/class/misc/rtc",
649 exp_name => "misc/rtc",
650 exp_perms => "0:100:0600",
652 KERNEL="rtc", NAME="misc/rtc"
656 desc => "permissions misc:0:users:0600",
658 devpath => "/class/misc/psaux",
659 exp_name => "misc/psaux",
660 exp_perms => "0:100:0600",
662 KERNEL="psaux", NAME="misc/psaux"
666 desc => "permissions set OWNER=5000",
668 devpath => "/block/sda",
670 exp_perms => "5000::0600",
672 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000"
676 desc => "permissions set GROUP=100",
678 devpath => "/block/sda",
680 exp_perms => ":100:0600",
682 BUS="scsi", KERNEL="sda", NAME="node", GROUP="100"
686 desc => "permissions set mode=0777",
688 devpath => "/block/sda",
690 exp_perms => "::0777",
692 BUS="scsi", KERNEL="sda", NAME="node", MODE="0777"
696 desc => "permissions set OWNER=5000 GROUP=100 MODE=0777",
698 devpath => "/block/sda",
700 exp_perms => "5000:100:0777",
702 BUS="scsi", KERNEL="sda", NAME="node", OWNER="5000", GROUP="100", MODE="0777"
706 desc => "permissions override OWNER to 5000",
708 devpath => "/class/tty/ttyUSB0",
709 exp_name => "ttyUSB0",
710 exp_perms => "5000:14:0660",
712 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000"
716 desc => "permissions override GROUP to 100",
718 devpath => "/class/tty/ttyUSB0",
719 exp_name => "ttyUSB0",
720 exp_perms => ":100:0660",
722 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="100"
726 desc => "permissions override MODE to 0060",
728 devpath => "/class/tty/ttyUSB0",
729 exp_name => "ttyUSB0",
730 exp_perms => ":14:0060",
732 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", MODE="0060"
736 desc => "permissions override OWNER, GROUP, MODE",
738 devpath => "/class/tty/ttyUSB0",
739 exp_name => "ttyUSB0",
740 exp_perms => "5000:100:0777",
742 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777"
746 desc => "major/minor number test",
748 devpath => "/block/sda",
750 exp_majorminor => "8:0",
752 BUS="scsi", KERNEL="sda", NAME="node"
756 desc => "big minor number test",
758 devpath => "/class/i2c-dev/i2c-300",
760 exp_majorminor => "89:300",
762 KERNEL="i2c-300", NAME="node"
766 desc => "big major number test",
768 devpath => "/class/i2c-dev/i2c-fake1",
770 exp_majorminor => "4095:1",
772 KERNEL="i2c-fake1", NAME="node"
776 desc => "big major and big minor number test",
778 devpath => "/class/i2c-dev/i2c-fake2",
780 exp_majorminor => "4094:89999",
782 KERNEL="i2c-fake2", NAME="node"
786 desc => "multiple symlinks with format char",
788 devpath => "/class/tty/ttyUSB0",
789 exp_name => "symlink2-ttyUSB0",
790 exp_target => "ttyUSB0",
792 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
796 desc => "symlink creation (same directory)",
798 devpath => "/class/tty/ttyUSB0",
799 exp_name => "visor0",
800 exp_target => "ttyUSB0",
802 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="visor%n"
806 desc => "symlink creation (relative link forward)",
808 devpath => "/block/sda/sda2",
809 exp_name => "1/2/symlink" ,
810 exp_target => "a/b/node",
812 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
816 desc => "symlink creation (relative link back and forward)",
818 devpath => "/block/sda/sda2",
819 exp_name => "1/2/c/d/symlink" ,
820 exp_target => "../../a/b/node",
822 BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
826 desc => "multiple symlinks",
828 devpath => "/class/tty/ttyUSB0",
829 exp_name => "second-0" ,
830 exp_target => "visor" ,
832 KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
836 desc => "symlink only rule",
838 devpath => "/block/sda",
839 exp_name => "symlink-only2",
840 exp_target => "link",
842 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1"
843 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2"
844 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
848 desc => "symlink name empty",
850 devpath => "/block/sda",
852 exp_target => "link",
855 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK=""
859 desc => "symlink name '.'",
861 devpath => "/block/sda",
863 exp_target => "link",
866 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="."
870 desc => "symlink to empty name",
872 devpath => "/block/sda",
873 exp_name => "symlink",
877 BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink"
881 desc => "symlink and name empty",
883 devpath => "/block/sda",
888 BUS="scsi", KERNEL="sda", NAME="", SYMLINK=""
892 desc => "symlink node to itself",
894 devpath => "/class/tty/tty0",
896 exp_target => "link",
898 KERNEL="tty0", NAME="link", SYMLINK="link"
902 desc => "symlink %n substitution",
904 devpath => "/class/tty/ttyUSB0",
905 exp_name => "symlink0",
906 exp_target => "ttyUSB0",
908 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink%n"
912 desc => "symlink %k substitution",
914 devpath => "/class/tty/ttyUSB0",
915 exp_name => "symlink-ttyUSB0",
916 exp_target => "ttyUSB0",
918 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink-%k"
922 desc => "symlink %M:%m substitution",
924 devpath => "/class/tty/ttyUSB0",
925 exp_name => "major-188:0",
926 exp_target => "ttyUSB0",
928 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="major-%M:%m"
932 desc => "symlink %b substitution",
934 devpath => "/block/sda",
935 exp_name => "symlink-0:0:0:0",
936 exp_target => "node",
938 BUS="scsi", KERNEL="sda", NAME="node", SYMLINK="symlink-%b"
942 desc => "symlink %c substitution",
944 devpath => "/class/tty/ttyUSB0",
946 exp_target => "ttyUSB0",
948 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo test" NAME="ttyUSB%n", SYMLINK="%c"
952 desc => "symlink %c{N} substitution",
954 devpath => "/class/tty/ttyUSB0",
956 exp_target => "ttyUSB0",
958 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2}"
962 desc => "symlink %c{N+} substitution",
964 devpath => "/class/tty/ttyUSB0",
966 exp_target => "ttyUSB0",
968 KERNEL="ttyUSB[0-9]*", PROGRAM="/bin/echo symlink test this" NAME="ttyUSB%n", SYMLINK="%c{2+}"
972 desc => "symlink only rule with %c{N+}",
974 devpath => "/block/sda",
976 exp_target => "link",
978 BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo link test this" SYMLINK="%c{2+}"
979 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
983 desc => "symlink %s{filename} substitution",
985 devpath => "/class/tty/ttyUSB0",
987 exp_target => "ttyUSB0",
989 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%s{dev}"
993 desc => "symlink %Ns{filename} substitution",
995 devpath => "/class/tty/ttyUSB0",
997 exp_target => "ttyUSB0",
999 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%3s{dev}"
1003 desc => "symlink with '%' in name",
1005 devpath => "/class/tty/ttyUSB0",
1006 exp_name => "percent%sign",
1007 exp_target => "ttyUSB0",
1009 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="percent%%sign"
1013 desc => "symlink with '%' in name",
1015 devpath => "/class/tty/ttyUSB0",
1016 exp_name => "%ttyUSB0_name",
1017 exp_target => "ttyUSB0",
1019 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="%%%k_name"
1023 desc => "program result substitution (numbered part of)",
1025 devpath => "/block/sda/sda3",
1026 exp_name => "link1",
1027 exp_target => "node",
1029 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2} %c{3}"
1033 desc => "program result substitution (numbered part of+)",
1035 devpath => "/block/sda/sda3",
1036 exp_name => "link4",
1037 exp_target => "node",
1039 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}"
1043 desc => "enumeration char test (single test)",
1045 devpath => "/block/sda",
1046 exp_name => "cdrom",
1048 KERNEL="sda", NAME="cdrom%e"
1052 desc => "enumeration char test sequence (1/5 keep)",
1054 devpath => "/block/sda",
1055 exp_name => "cdrom",
1058 KERNEL="sda", NAME="cdrom%e"
1062 desc => "enumeration char test sequence 2/5 (keep)",
1064 devpath => "/block/sda/sda1",
1068 KERNEL="sda1", NAME="enum%e"
1072 desc => "enumeration char test sequence 3/5 (keep)",
1074 devpath => "/block/sda/sda2",
1075 exp_name => "cdrom1",
1078 KERNEL="sda2", NAME="cdrom%e"
1082 desc => "enumeration char test sequence 4/5 (keep)",
1084 devpath => "/block/sda/sda3",
1085 exp_name => "enum1",
1088 KERNEL="sda3", NAME="enum%e"
1092 desc => "enumeration char test sequence 5/5 (clean)",
1094 devpath => "/block/sda/sda4",
1095 exp_name => "cdrom2",
1098 KERNEL="sda4", NAME="cdrom%e"
1102 desc => "enumeration char test after cleanup (single test)",
1104 devpath => "/block/sda",
1105 exp_name => "cdrom",
1107 KERNEL="sda", NAME="cdrom%e"
1111 desc => "ignore remove event test",
1113 devpath => "/block/sda",
1117 BUS="scsi", KERNEL="sda", NAME{ignore_remove}="node"
1121 desc => "ignore remove event test (with all partitions)",
1123 devpath => "/block/sda",
1124 exp_name => "node14",
1128 BUS="scsi", KERNEL="sda", NAME{ignore_remove, all_partitions}="node"
1132 desc => "SUBSYSTEM match test",
1134 devpath => "/block/sda",
1137 BUS="scsi", KERNEL="sda", NAME="should_not_match", SUBSYSTEM="vc"
1138 BUS="scsi", KERNEL="sda", NAME="node", SUBSYSTEM="block"
1139 BUS="scsi", KERNEL="sda", NAME="should_not_match2", SUBSYSTEM="vc"
1143 desc => "DRIVER match test",
1145 devpath => "/block/sda",
1148 BUS="scsi", KERNEL="sda", NAME="should_not_match", DRIVER="sd-wrong"
1149 BUS="scsi", KERNEL="sda", NAME="node", DRIVER="sd"
1155 $ENV{UDEV_TEST} = "yes";
1156 $ENV{SYSFS_PATH} = $sysfs;
1157 $ENV{UDEV_CONFIG_FILE} = $main_conf;
1158 $ENV{UDEV_NO_DEVD} = "yes";
1162 my ($action, $subsys, $devpath, $config) = @_;
1164 $ENV{DEVPATH} = $devpath;
1166 # create temporary config
1167 open CONF, ">$conf_tmp" || die "unable to create config file: $conf_tmp";
1168 print CONF $$config;
1171 $ENV{ACTION} = $action;
1172 system("$udev_bin $subsys");
1177 sub permissions_test {
1178 my($config, $uid, $gid, $mode) = @_;
1181 $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1183 if ($uid != $1) { $wrong = 1; };
1186 if ($gid != $2) { $wrong = 1; };
1189 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1192 print "permissions: ok ";
1194 printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3);
1195 printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1200 sub major_minor_test {
1201 my($config, $rdev) = @_;
1203 my $major = ($rdev >> 8) & 0xfff;
1204 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1207 $config->{exp_majorminor} =~ m/^(.*):(.*)$/;
1209 if ($major != $1) { $wrong = 1; };
1212 if ($minor != $2) { $wrong = 1; };
1215 print "major:minor: ok ";
1217 printf "expected major:minor is: %i:%i\n", $1, $2;
1218 printf "created major:minor is : %i:%i\n", $major, $minor;
1219 print "major:minor: error ";
1227 my $output = `ls -l $PWD/$udev_root$config->{exp_name}`;
1229 if ($output =~ m/(.*)-> (.*)/) {
1230 if ($2 eq $config->{exp_target}) {
1231 print "symlink: ok ";
1233 print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1234 print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n";
1235 if ($config->{exp_error}) {
1236 print "as expected ";
1242 print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
1243 print "symlink: not created ";
1244 if ($config->{exp_error}) {
1245 print "as expected ";
1253 my ($config, $number) = @_;
1255 print "TEST $number: $config->{desc}\n";
1257 if ($config->{exp_target}) {
1258 print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n";
1260 print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n";
1264 udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
1265 if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1266 (-l "$PWD/$udev_root$config->{exp_name}")) {
1268 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1269 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}");
1271 if (defined($config->{exp_perms})) {
1272 permissions_test($config, $uid, $gid, $mode);
1274 if (defined($config->{exp_majorminor})) {
1275 major_minor_test($config, $rdev);
1277 if (defined($config->{exp_target})) {
1278 symlink_test($config);
1282 print "add: error ";
1283 if ($config->{exp_error}) {
1284 print "as expected ";
1287 system("tree $udev_root");
1293 if (defined($config->{option}) && $config->{option} eq "keep") {
1298 udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
1299 if ((-e "$PWD/$udev_root$config->{exp_name}") ||
1300 (-l "$PWD/$udev_root$config->{exp_name}")) {
1301 print "remove: error ";
1302 if ($config->{exp_error}) {
1303 print "as expected\n\n";
1306 system("tree $udev_root");
1311 print "remove: ok\n\n";
1314 if (defined($config->{option}) && $config->{option} eq "clear") {
1315 system("rm -rf $udev_db");
1316 system("rm -rf $udev_root");
1317 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1322 # only run if we have root permissions
1323 # due to mknod restrictions
1325 print "Must have root permissions to run properly.\n";
1330 system("rm -rf $udev_root");
1331 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1333 # create initial config file
1334 open CONF, ">$main_conf" || die "unable to create config file: $main_conf";
1335 print CONF "udev_root=\"$udev_root\"\n";
1336 print CONF "udev_db=\"$udev_db\"\n";
1337 print CONF "udev_rules=\"$conf_tmp\"\n";
1338 print CONF "udev_permissions=\"$perm\"\n";
1345 $test_num = $ARGV[0];
1347 if (defined($tests[$test_num-1]->{desc})) {
1348 print "udev-test will run test number $test_num only:\n\n";
1349 run_test($tests[$test_num-1], $test_num);
1351 print "test does not exist.\n";
1355 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1357 foreach my $config (@tests) {
1358 run_test($config, $test_num);
1363 print "$error errors occured\n\n";
1366 system("rm -rf $udev_db");
1367 system("rm -rf $udev_root");