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 (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
18 # Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
24 my $sysfs = "test/sys/";
25 my $udev_bin = "udev/test-udev";
27 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
28 my $udev_root = "udev-root/";
29 my $udev_conf = "udev-test.conf";
30 my $udev_rules = "udev-test.rules";
36 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
38 exp_rem_error => "yes",
44 desc => "label test of scsi disc",
46 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
47 exp_name => "boot_disk" ,
49 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
50 KERNEL=="ttyACM0", SYMLINK+="modem"
54 desc => "label test of scsi disc",
56 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
57 exp_name => "boot_disk" ,
59 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
60 KERNEL=="ttyACM0", SYMLINK+="modem"
64 desc => "label test of scsi disc",
66 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
67 exp_name => "boot_disk" ,
69 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
70 KERNEL=="ttyACM0", SYMLINK+="modem"
74 desc => "label test of scsi partition",
76 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
77 exp_name => "boot_disk1" ,
79 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
83 desc => "label test of pattern match",
85 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
86 exp_name => "boot_disk1" ,
88 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
89 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
90 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
91 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
95 desc => "label test of multiple sysfs files",
97 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
98 exp_name => "boot_disk1" ,
100 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
101 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
105 desc => "label test of max sysfs files (skip invalid rule)",
107 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
108 exp_name => "boot_disk1" ,
110 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"
111 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
115 desc => "catch device by *",
117 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
118 exp_name => "modem/0" ,
120 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
124 desc => "catch device by * - take 2",
126 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
127 exp_name => "modem/0" ,
129 KERNEL=="*ACM1", SYMLINK+="bad"
130 KERNEL=="*ACM0", SYMLINK+="modem/%n"
134 desc => "catch device by ?",
136 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
137 exp_name => "modem/0" ,
139 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
140 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
141 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
145 desc => "catch device by character class",
147 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
148 exp_name => "modem/0" ,
150 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
151 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
152 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
156 desc => "replace kernel name",
158 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
159 exp_name => "modem" ,
161 KERNEL=="ttyACM0", SYMLINK+="modem"
165 desc => "Handle comment lines in config file (and replace kernel name)",
167 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
168 exp_name => "modem" ,
171 KERNEL=="ttyACM0", SYMLINK+="modem"
176 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
178 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
179 exp_name => "modem" ,
181 # this is a comment with whitespace before the comment
182 KERNEL=="ttyACM0", SYMLINK+="modem"
187 desc => "Handle whitespace only lines (and replace kernel name)",
189 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
190 exp_name => "whitespace" ,
195 # this is a comment with whitespace before the comment
196 KERNEL=="ttyACM0", SYMLINK+="whitespace"
203 desc => "Handle empty lines in config file (and replace kernel name)",
205 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
206 exp_name => "modem" ,
209 KERNEL=="ttyACM0", SYMLINK+="modem"
214 desc => "Handle backslashed multi lines in config file (and replace kernel name)",
216 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
217 exp_name => "modem" ,
219 KERNEL=="ttyACM0", \\
225 desc => "preserve backslashes, if they are not for a newline",
227 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
230 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
234 desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
236 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
237 exp_name => "modem" ,
247 KERNEL=="ttyACM0", \\
253 desc => "subdirectory handling",
255 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
256 exp_name => "sub/direct/ory/modem" ,
258 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
262 desc => "parent device name match of scsi partition",
264 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
265 exp_name => "first_disk5" ,
267 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
271 desc => "test substitution chars",
273 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
274 exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
276 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
280 desc => "import of shell-value file",
282 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
283 exp_name => "subdir/err/node" ,
285 SUBSYSTEMS=="scsi", IMPORT{file}="udev-test.conf", SYMLINK+="subdir/%E{udev_log}/node"
286 KERNEL=="ttyACM0", SYMLINK+="modem"
290 desc => "import of shell-value returned from program",
292 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
293 exp_name => "node12345678",
295 SUBSYSTEMS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
296 KERNEL=="ttyACM0", SYMLINK+="modem"
300 desc => "sustitution of sysfs value (%s{file})",
302 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
303 exp_name => "disk-ATA-sda" ,
305 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
306 KERNEL=="ttyACM0", SYMLINK+="modem"
310 desc => "program result substitution",
312 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
313 exp_name => "special-device-5" ,
314 not_exp_name => "not" ,
316 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
317 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
321 desc => "program result substitution (newline removal)",
323 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
324 exp_name => "newline_removed" ,
326 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
330 desc => "program result substitution",
332 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
333 exp_name => "test-0:0:0:0" ,
335 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
339 desc => "program with lots of arguments",
341 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
344 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
348 desc => "program with subshell",
350 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
353 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
357 desc => "program arguments combined with apostrophes",
359 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
362 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
366 desc => "characters before the %c{N} substitution",
368 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
369 exp_name => "my-foo9" ,
371 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
375 desc => "substitute the second to last argument",
377 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
378 exp_name => "my-foo8" ,
380 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
384 desc => "test substitution by variable name",
386 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
387 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
389 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
393 desc => "test substitution by variable name 2",
395 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
396 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
398 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
402 desc => "test substitution by variable name 3",
404 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
405 exp_name => "850:0:0:05" ,
407 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
411 desc => "test substitution by variable name 4",
413 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
416 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
420 desc => "test substitution by variable name 5",
422 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
423 exp_name => "8550:0:0:0" ,
425 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
429 desc => "non matching SUBSYSTEMS for device with no parent",
431 devpath => "/devices/virtual/tty/console",
434 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
435 KERNEL=="console", SYMLINK+="TTY"
439 desc => "non matching SUBSYSTEMS",
441 devpath => "/devices/virtual/tty/console",
444 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
445 KERNEL=="console", SYMLINK+="TTY"
449 desc => "ATTRS match",
451 devpath => "/devices/virtual/tty/console",
454 KERNEL=="console", SYMLINK+="TTY"
455 ATTRS{dev}=="5:1", SYMLINK+="foo"
459 desc => "ATTR (empty file)",
461 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
462 exp_name => "empty" ,
464 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
465 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
466 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
467 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
471 desc => "ATTR (non-existent file)",
473 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
474 exp_name => "non-existent" ,
476 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
477 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
478 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
479 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
480 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
481 KERNEL=="sda", SYMLINK+="wrong"
485 desc => "program and bus type match",
487 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
488 exp_name => "scsi-0:0:0:0" ,
490 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
491 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
492 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
496 desc => "sysfs parent hierarchy",
498 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
499 exp_name => "modem" ,
501 ATTRS{idProduct}=="007b", SYMLINK+="modem"
505 desc => "name test with ! in the name",
507 devpath => "/devices/virtual/block/fake!blockdev0",
508 exp_name => "is/a/fake/blockdev0" ,
510 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
511 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
512 KERNEL=="ttyACM0", SYMLINK+="modem"
516 desc => "name test with ! in the name, but no matching rule",
518 devpath => "/devices/virtual/block/fake!blockdev0",
519 exp_name => "fake/blockdev0" ,
520 exp_rem_error => "yes",
522 KERNEL=="ttyACM0", SYMLINK+="modem"
526 desc => "KERNELS rule",
528 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
529 exp_name => "scsi-0:0:0:0",
531 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
532 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
533 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
534 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
535 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
539 desc => "KERNELS wildcard all",
541 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
542 exp_name => "scsi-0:0:0:0",
544 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
545 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
546 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
547 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
548 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
552 desc => "KERNELS wildcard partial",
554 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
555 exp_name => "scsi-0:0:0:0",
557 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
558 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
562 desc => "KERNELS wildcard partial 2",
564 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
565 exp_name => "scsi-0:0:0:0",
567 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
568 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
572 desc => "substitute attr with link target value (first match)",
574 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
575 exp_name => "driver-is-sd",
577 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
581 desc => "substitute attr with link target value (currently selected device)",
583 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
584 exp_name => "driver-is-ahci",
586 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
590 desc => "ignore ATTRS attribute whitespace",
592 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
593 exp_name => "ignored",
595 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
599 desc => "do not ignore ATTRS attribute whitespace",
601 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
602 exp_name => "matched-with-space",
604 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
605 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
609 desc => "permissions USER=bad GROUP=name",
611 devpath => "/devices/virtual/tty/tty33",
613 exp_perms => "0:0:0600",
615 KERNEL=="tty33", SYMLINK+="tty33", OWNER="bad", GROUP="name"
619 desc => "permissions OWNER=5000",
621 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
623 exp_perms => "5000::0600",
625 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000"
629 desc => "permissions GROUP=100",
631 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
633 exp_perms => ":100:0660",
635 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="100"
639 desc => "textual user id",
641 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
643 exp_perms => "nobody::0600",
645 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
649 desc => "textual group id",
651 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
653 exp_perms => ":daemon:0660",
655 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
659 desc => "textual user/group id",
661 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
663 exp_perms => "root:mail:0660",
665 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
669 desc => "permissions MODE=0777",
671 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
673 exp_perms => "::0777",
675 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
679 desc => "permissions OWNER=5000 GROUP=100 MODE=0777",
681 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
683 exp_perms => "5000:100:0777",
685 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000", GROUP="100", MODE="0777"
689 desc => "permissions OWNER to 5000",
691 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
692 exp_name => "ttyACM0",
693 exp_perms => "5000::",
695 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000"
699 desc => "permissions GROUP to 100",
701 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
702 exp_name => "ttyACM0",
703 exp_perms => ":100:0660",
705 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="100"
709 desc => "permissions MODE to 0060",
711 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
712 exp_name => "ttyACM0",
713 exp_perms => "::0060",
715 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
719 desc => "permissions OWNER, GROUP, MODE",
721 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
722 exp_name => "ttyACM0",
723 exp_perms => "5000:100:0777",
725 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000", GROUP="100", MODE="0777"
729 desc => "permissions only rule",
731 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
732 exp_name => "ttyACM0",
733 exp_perms => "5000:100:0777",
735 KERNEL=="ttyACM[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
736 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
737 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
741 desc => "multiple permissions only rule",
743 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
744 exp_name => "ttyACM0",
745 exp_perms => "3000:4000:0777",
747 SUBSYSTEM=="tty", OWNER="3000"
748 SUBSYSTEM=="tty", GROUP="4000"
749 SUBSYSTEM=="tty", MODE="0777"
750 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
751 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
755 desc => "permissions only rule with override at SYMLINK+ rule",
757 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
758 exp_name => "ttyACM0",
759 exp_perms => "3000:8000:0777",
761 SUBSYSTEM=="tty", OWNER="3000"
762 SUBSYSTEM=="tty", GROUP="4000"
763 SUBSYSTEM=="tty", MODE="0777"
764 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
765 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="8000"
769 desc => "major/minor number test",
771 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
773 exp_majorminor => "8:0",
775 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
779 desc => "big major number test",
781 devpath => "/devices/virtual/misc/misc-fake1",
783 exp_majorminor => "4095:1",
785 KERNEL=="misc-fake1", SYMLINK+="node"
789 desc => "big major and big minor number test",
791 devpath => "/devices/virtual/misc/misc-fake89999",
793 exp_majorminor => "4095:89999",
795 KERNEL=="misc-fake89999", SYMLINK+="node"
799 desc => "multiple symlinks with format char",
801 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
802 exp_name => "symlink2-ttyACM0",
804 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
808 desc => "multiple symlinks with a lot of s p a c e s",
810 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
814 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
818 desc => "symlink creation (same directory)",
820 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
821 exp_name => "modem0",
823 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
827 desc => "symlink creation (relative link forward)",
829 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
830 exp_name => "1/2/symlink" ,
831 exp_target => "a/b/node",
832 exp_rem_error => "yes",
834 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/symlink"
838 desc => "symlink creation (relative link back and forward)",
840 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
841 exp_name => "1/2/c/d/symlink" ,
842 exp_target => "../../a/b/node",
843 exp_rem_error => "yes",
845 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/c/d/symlink"
849 desc => "multiple symlinks",
851 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
852 exp_name => "second-0" ,
854 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
858 desc => "symlink name '.'",
860 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
862 exp_add_error => "yes",
863 exp_rem_error => "yes",
865 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
869 desc => "symlink node to itself",
871 devpath => "/devices/virtual/tty/tty0",
873 exp_add_error => "yes",
874 exp_rem_error => "yes",
877 KERNEL=="tty0", SYMLINK+="tty0"
881 desc => "symlink %n substitution",
883 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
884 exp_name => "symlink0",
886 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
890 desc => "symlink %k substitution",
892 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
893 exp_name => "symlink-ttyACM0",
895 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
899 desc => "symlink %M:%m substitution",
901 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
902 exp_name => "major-166:0",
904 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
908 desc => "symlink %b substitution",
910 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
911 exp_name => "symlink-0:0:0:0",
912 exp_target => "node",
914 SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b"
918 desc => "symlink %c substitution",
920 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
923 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
927 desc => "symlink %c{N} substitution",
929 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
932 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
936 desc => "symlink %c{N+} substitution",
938 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
941 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
945 desc => "symlink only rule with %c{N+}",
947 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
950 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
954 desc => "symlink %s{filename} substitution",
956 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
959 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
963 desc => "program result substitution (numbered part of)",
965 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
968 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
972 desc => "program result substitution (numbered part of+)",
974 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
977 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
981 desc => "SUBSYSTEM match test",
983 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
986 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
987 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
988 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
992 desc => "DRIVERS match test",
994 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
997 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
998 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
1002 desc => "temporary node creation test",
1004 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1007 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1011 desc => "parent node name substitution test sequence 1/2 (keep)",
1013 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1014 exp_name => "main_device",
1016 exp_rem_error => "yes",
1018 SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="main_device"
1022 desc => "parent node name substitution test sequence 2/2 (clean)",
1024 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1025 exp_name => "main_device-part-1",
1028 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1032 desc => "udev_root substitution",
1034 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1035 exp_name => "start-udev-root-end",
1037 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1041 desc => "last_rule option",
1043 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1046 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1047 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1051 desc => "negation KERNEL!=",
1053 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1054 exp_name => "match",
1056 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1057 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1058 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1062 desc => "negation SUBSYSTEM!=",
1064 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1065 exp_name => "not-anything",
1067 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1068 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1069 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1073 desc => "negation PROGRAM!= exit code",
1075 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1076 exp_name => "nonzero-program",
1078 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1079 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1083 desc => "test for whitespace between the operator",
1085 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1088 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1089 KERNEL == "sda1" , SYMLINK+ = "true"
1093 desc => "ENV{} test",
1095 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1098 ENV{ENV_KEY_TEST}="test"
1099 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1100 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1101 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1105 desc => "ENV{} test",
1107 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1110 ENV{ENV_KEY_TEST}="test"
1111 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1112 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1113 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1114 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1118 desc => "ENV{} test (assign)",
1120 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1123 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1124 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1125 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1126 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1130 desc => "ENV{} test (assign 2 times)",
1132 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1135 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1136 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1137 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1138 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1139 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1143 desc => "ENV{} test (assign2)",
1145 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1148 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1149 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1150 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1151 SUBSYSTEM=="block", SYMLINK+="before"
1152 ENV{PARTITION}=="true", SYMLINK+="part"
1156 desc => "untrusted string sanitize",
1158 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1161 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", SYMLINK+="sane"
1165 desc => "untrusted string sanitize (don't replace utf8)",
1167 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1170 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1174 desc => "untrusted string sanitize (replace invalid utf8)",
1176 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1177 exp_name => "replaced",
1179 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1183 desc => "read sysfs value from parent device",
1185 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1186 exp_name => "serial-354172020305000",
1188 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1192 desc => "match against empty key string",
1194 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1197 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1198 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1199 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1200 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1204 desc => "check ACTION value",
1206 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1209 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1210 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1214 desc => "test RUN key remove",
1216 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1217 exp_name => "testsymlink2",
1218 exp_target => "ok2",
1220 KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2"
1221 KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2"
1225 desc => "final assignment",
1227 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1229 exp_perms => "root:tty:0640",
1231 KERNEL=="sda", GROUP:="tty"
1232 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1236 desc => "final assignment 2",
1238 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1240 exp_perms => "root:tty:0640",
1242 KERNEL=="sda", GROUP:="tty"
1243 SUBSYSTEM=="block", MODE:="640"
1244 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1248 desc => "env substitution",
1250 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1251 exp_name => "node-add-me",
1253 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1257 desc => "reset list to current value",
1259 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1260 exp_name => "three",
1261 not_exp_name => "two",
1263 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1264 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1265 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1269 desc => "test empty SYMLINK+ (empty override)",
1271 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1272 exp_name => "right",
1273 not_exp_name => "wrong",
1275 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1276 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1277 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1281 desc => "test multi matches",
1283 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1284 exp_name => "right",
1286 KERNEL=="ttyACM*", SYMLINK+="before"
1287 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1291 desc => "test multi matches 2",
1293 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1294 exp_name => "right",
1296 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1297 KERNEL=="ttyACM*", SYMLINK+="before"
1298 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1302 desc => "test multi matches 3",
1304 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1305 exp_name => "right",
1307 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1308 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1309 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1310 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1314 desc => "test multi matches 4",
1316 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1317 exp_name => "right",
1319 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1320 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1321 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1322 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1323 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1327 desc => "IMPORT parent test sequence 1/2 (keep)",
1329 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1330 exp_name => "parent",
1333 KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1334 KERNEL=="sda", SYMLINK+="parent"
1338 desc => "IMPORT parent test sequence 2/2 (keep)",
1340 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1341 exp_name => "parentenv-parent_right",
1344 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1348 desc => "GOTO test",
1350 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1351 exp_name => "right",
1353 KERNEL=="sda1", GOTO="TEST"
1354 KERNEL=="sda1", SYMLINK+="wrong"
1355 KERNEL=="sda1", GOTO="BAD"
1356 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1357 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1358 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1363 desc => "GOTO label does not exist",
1365 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1366 exp_name => "right",
1368 KERNEL=="sda1", GOTO="does-not-exist"
1369 KERNEL=="sda1", SYMLINK+="right",
1374 desc => "SYMLINK+ compare test",
1376 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1377 exp_name => "right",
1378 not_exp_name => "wrong",
1380 KERNEL=="sda1", SYMLINK+="link"
1381 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1382 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1386 desc => "invalid key operation",
1388 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1391 KERNEL="sda1", SYMLINK+="no"
1392 KERNEL=="sda1", SYMLINK+="yes"
1396 desc => "operator chars in attribute",
1398 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1401 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1405 desc => "overlong comment line",
1407 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1410 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1411 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1412 KERNEL=="sda1", SYMLINK+=="no"
1413 KERNEL=="sda1", SYMLINK+="yes"
1417 desc => "magic subsys/kernel lookup",
1419 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1420 exp_name => "00:16:41:e2:8d:ff",
1422 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1426 desc => "TEST absolute path",
1428 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1429 exp_name => "there",
1431 TEST=="/etc/hosts", SYMLINK+="there"
1432 TEST!="/etc/hosts", SYMLINK+="notthere"
1436 desc => "TEST subsys/kernel lookup",
1438 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1441 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1445 desc => "TEST relative path",
1447 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1448 exp_name => "relative",
1450 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1454 desc => "TEST wildcard substitution (find queue/nr_requests)",
1456 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1457 exp_name => "found-subdir",
1459 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1463 desc => "TEST MODE=0000",
1465 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1467 exp_perms => "0:0:0000",
1468 exp_rem_error => "yes",
1470 KERNEL=="sda", MODE="0000"
1474 desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
1476 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1478 exp_perms => "5000:100:0400",
1479 exp_rem_error => "yes",
1481 KERNEL=="sda", MODE="666"
1482 KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1486 desc => "TEST PROGRAM feeds MODE with overflow",
1488 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1490 exp_perms => "0:0:0440",
1491 exp_rem_error => "yes",
1493 KERNEL=="sda", MODE="440"
1494 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1498 desc => "magic [subsys/sysname] attribute substitution",
1500 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1501 exp_name => "sda-8741C4G-end",
1502 exp_perms => "0:0:0600",
1504 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1505 KERNEL=="sda", ENV{TESTENV}="change-envp"
1506 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
1512 $ENV{SYSFS_PATH} = $sysfs;
1513 $ENV{UDEV_CONFIG_FILE} = $udev_conf;
1516 my ($action, $subsys, $devpath, $rules) = @_;
1518 $ENV{DEVPATH} = $devpath;
1520 # create temporary rules
1521 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1525 $ENV{ACTION} = $action;
1526 $ENV{SUBSYSTEM} = $subsys;
1527 if ($valgrind > 0) {
1528 system("$udev_bin_valgrind");
1530 system("$udev_bin");
1536 sub permissions_test {
1537 my($rules, $uid, $gid, $mode) = @_;
1543 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1545 if (defined(getpwnam($1))) {
1546 $userid = int(getpwnam($1));
1550 if ($uid != $userid) { $wrong = 1; }
1553 if (defined(getgrnam($2))) {
1554 $groupid = int(getgrnam($2));
1558 if ($gid != $groupid) { $wrong = 1; }
1561 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1564 print "permissions: ok\n";
1566 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1567 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1568 print "permissions: error\n";
1574 sub major_minor_test {
1575 my($rules, $rdev) = @_;
1577 my $major = ($rdev >> 8) & 0xfff;
1578 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1581 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
1583 if ($major != $1) { $wrong = 1; };
1586 if ($minor != $2) { $wrong = 1; };
1589 print "major:minor: ok\n";
1591 printf " expected major:minor is: %i:%i\n", $1, $2;
1592 printf " created major:minor is : %i:%i\n", $major, $minor;
1593 print "major:minor: error\n";
1602 my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`;
1604 if ($output =~ m/(.*)-> (.*)/) {
1605 if ($2 eq $rules->{exp_target}) {
1606 print "symlink: ok\n";
1608 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
1609 print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n";
1610 print "symlink: error";
1611 if ($rules->{exp_add_error}) {
1612 print " as expected\n";
1620 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
1621 print "symlink: not created";
1622 if ($rules->{exp_add_error}) {
1623 print " as expected\n";
1632 sub make_udev_root {
1633 system("rm -rf $udev_root");
1634 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1635 # setting group and mode of udev_root ensures the tests work
1636 # even if the parent directory has setgid bit enabled.
1637 chown (0, 0, $udev_root) || die "unable to chown $udev_root\n";
1638 chmod (0755, $udev_root) || die "unable to chmod $udev_root\n";
1642 my ($rules, $number) = @_;
1644 print "TEST $number: $rules->{desc}\n";
1646 if ($rules->{exp_target}) {
1647 print "device \'$rules->{devpath}\' expecting link '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
1649 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1653 udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
1654 if (defined($rules->{not_exp_name})) {
1655 if ((-e "$PWD/$udev_root$rules->{not_exp_name}") ||
1656 (-l "$PWD/$udev_root$rules->{not_exp_name}")) {
1657 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1663 if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
1664 (-l "$PWD/$udev_root$rules->{exp_name}")) {
1666 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1667 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}");
1669 if (defined($rules->{exp_perms})) {
1670 permissions_test($rules, $uid, $gid, $mode);
1672 if (defined($rules->{exp_majorminor})) {
1673 major_minor_test($rules, $rdev);
1675 if (defined($rules->{exp_target})) {
1676 symlink_test($rules);
1681 if ($rules->{exp_add_error}) {
1682 print " as expected\n";
1685 system("tree $udev_root");
1692 if (defined($rules->{option}) && $rules->{option} eq "keep") {
1697 udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
1698 if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
1699 (-l "$PWD/$udev_root$rules->{exp_name}")) {
1700 print "remove: error";
1701 if ($rules->{exp_rem_error}) {
1702 print " as expected\n";
1705 system("tree $udev_root");
1711 print "remove: ok\n";
1716 if (defined($rules->{option}) && $rules->{option} eq "clean") {
1722 # only run if we have root permissions
1723 # due to mknod restrictions
1725 print "Must have root permissions to run properly.\n";
1732 # create config file
1733 open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
1734 print CONF "udev_root=\"$udev_root\"\n";
1735 print CONF "udev_run=\"$udev_root/.udev\"\n";
1736 print CONF "udev_rules=\"$PWD\"\n";
1737 print CONF "udev_log=\"err\"\n";
1743 foreach my $arg (@ARGV) {
1744 if ($arg =~ m/--valgrind/) {
1746 printf("using valgrind\n");
1753 foreach my $arg (@list) {
1754 if (defined($tests[$arg-1]->{desc})) {
1755 print "udev-test will run test number $arg:\n\n";
1756 run_test($tests[$arg-1], $arg);
1758 print "test does not exist.\n";
1763 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1765 foreach my $rules (@tests) {
1766 run_test($rules, $test_num);
1771 print "$error errors occured\n\n";
1774 system("rm -rf $udev_root");
1775 unlink($udev_rules);