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:0660",
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::0660",
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::0660",
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 => "ignore remove event test",
983 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
985 exp_rem_error => "yes",
987 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OPTIONS="ignore_remove"
991 desc => "SUBSYSTEM match test",
993 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
996 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
997 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
998 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
1002 desc => "DRIVERS match 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", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
1008 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
1012 desc => "temporary node creation test",
1014 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1017 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1021 desc => "parent node name substitution test sequence 1/2 (keep)",
1023 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1024 exp_name => "main_device",
1026 exp_rem_error => "yes",
1028 SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="main_device"
1032 desc => "parent node name substitution test sequence 2/2 (clean)",
1034 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1035 exp_name => "main_device-part-1",
1038 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1042 desc => "udev_root substitution",
1044 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1045 exp_name => "start-udev-root-end",
1047 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1051 desc => "last_rule option",
1053 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1056 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1057 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1061 desc => "negation KERNEL!=",
1063 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1064 exp_name => "match",
1066 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1067 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1068 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1072 desc => "negation SUBSYSTEM!=",
1074 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1075 exp_name => "not-anything",
1077 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1078 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1079 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1083 desc => "negation PROGRAM!= exit code",
1085 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1086 exp_name => "nonzero-program",
1088 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1089 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1093 desc => "test for whitespace between the operator",
1095 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1098 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1099 KERNEL == "sda1" , SYMLINK+ = "true"
1103 desc => "ENV{} test",
1105 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1108 ENV{ENV_KEY_TEST}="test"
1109 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1110 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1111 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1115 desc => "ENV{} test",
1117 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1120 ENV{ENV_KEY_TEST}="test"
1121 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1122 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1123 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1124 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1128 desc => "ENV{} test (assign)",
1130 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1133 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1134 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1135 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1136 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1140 desc => "ENV{} test (assign 2 times)",
1142 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1145 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1146 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1147 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1148 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1149 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1153 desc => "ENV{} test (assign2)",
1155 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1158 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1159 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1160 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1161 SUBSYSTEM=="block", SYMLINK+="before"
1162 ENV{PARTITION}=="true", SYMLINK+="part"
1166 desc => "untrusted string sanitize",
1168 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1171 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", SYMLINK+="sane"
1175 desc => "untrusted string sanitize (don't replace utf8)",
1177 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1180 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1184 desc => "untrusted string sanitize (replace invalid utf8)",
1186 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1187 exp_name => "replaced",
1189 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1193 desc => "read sysfs value from parent device",
1195 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1196 exp_name => "serial-354172020305000",
1198 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1202 desc => "match against empty key string",
1204 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1207 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1208 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1209 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1210 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1214 desc => "check ACTION value",
1216 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1219 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1220 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1224 desc => "test RUN key remove",
1226 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1227 exp_name => "testsymlink2",
1228 exp_target => "ok2",
1230 KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2"
1231 KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2"
1235 desc => "final assignment",
1237 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1239 exp_perms => "root:tty:0640",
1241 KERNEL=="sda", GROUP:="tty"
1242 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1246 desc => "final assignment 2",
1248 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1250 exp_perms => "root:tty:0640",
1252 KERNEL=="sda", GROUP:="tty"
1253 SUBSYSTEM=="block", MODE:="640"
1254 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1258 desc => "env substitution",
1260 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1261 exp_name => "node-add-me",
1263 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1267 desc => "reset list to current value",
1269 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1270 exp_name => "three",
1271 not_exp_name => "two",
1273 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1274 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1275 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1279 desc => "test empty NAME",
1281 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1282 exp_name => "<none>",
1283 not_exp_name => "ttyACM0",
1284 exp_add_error => "yes",
1286 KERNEL=="ttyACM[0-9]*", NAME=""
1290 desc => "test empty SYMLINK+ (empty override)",
1292 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1293 exp_name => "right",
1294 not_exp_name => "wrong",
1296 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1297 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1298 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1302 desc => "test multi matches",
1304 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1305 exp_name => "right",
1307 KERNEL=="ttyACM*", SYMLINK+="before"
1308 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1312 desc => "test multi matches 2",
1314 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1315 exp_name => "right",
1317 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1318 KERNEL=="ttyACM*", SYMLINK+="before"
1319 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1323 desc => "test multi matches 3",
1325 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1326 exp_name => "right",
1328 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1329 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1330 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1331 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1335 desc => "test multi matches 4",
1337 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1338 exp_name => "right",
1340 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1341 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1342 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1343 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1344 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1348 desc => "IMPORT parent test sequence 1/2 (keep)",
1350 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1351 exp_name => "parent",
1354 KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1355 KERNEL=="sda", SYMLINK+="parent"
1359 desc => "IMPORT parent test sequence 2/2 (keep)",
1361 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1362 exp_name => "parentenv-parent_right",
1365 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1369 desc => "GOTO test",
1371 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1372 exp_name => "right",
1374 KERNEL=="sda1", GOTO="TEST"
1375 KERNEL=="sda1", SYMLINK+="wrong"
1376 KERNEL=="sda1", GOTO="BAD"
1377 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1378 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1379 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1384 desc => "GOTO label does not exist",
1386 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1387 exp_name => "right",
1389 KERNEL=="sda1", GOTO="does-not-exist"
1390 KERNEL=="sda1", SYMLINK+="right",
1395 desc => "SYMLINK+ compare test",
1397 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1398 exp_name => "right",
1399 not_exp_name => "wrong",
1401 KERNEL=="sda1", SYMLINK+="link"
1402 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1403 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1407 desc => "invalid key operation",
1409 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1412 KERNEL="sda1", SYMLINK+="no"
1413 KERNEL=="sda1", SYMLINK+="yes"
1417 desc => "operator chars in attribute",
1419 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1422 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1426 desc => "overlong comment line",
1428 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1431 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1432 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1433 KERNEL=="sda1", SYMLINK+=="no"
1434 KERNEL=="sda1", SYMLINK+="yes"
1438 desc => "magic subsys/kernel lookup",
1440 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1441 exp_name => "00:16:41:e2:8d:ff",
1443 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1447 desc => "TEST absolute path",
1449 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1450 exp_name => "there",
1452 TEST=="/etc/hosts", SYMLINK+="there"
1453 TEST!="/etc/hosts", SYMLINK+="notthere"
1457 desc => "TEST subsys/kernel lookup",
1459 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1462 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1466 desc => "TEST relative path",
1468 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1469 exp_name => "relative",
1471 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1475 desc => "TEST wildcard substitution (find queue/nr_requests)",
1477 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1478 exp_name => "found-subdir",
1480 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1484 desc => "TEST MODE=0000",
1486 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1488 exp_perms => "0:0:0000",
1489 exp_rem_error => "yes",
1491 KERNEL=="sda", MODE="0000"
1495 desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
1497 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1499 exp_perms => "5000:100:0400",
1500 exp_rem_error => "yes",
1502 KERNEL=="sda", MODE="666"
1503 KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1507 desc => "TEST PROGRAM feeds MODE with overflow",
1509 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1511 exp_perms => "0:0:0660",
1512 exp_rem_error => "yes",
1514 KERNEL=="sda", MODE="440"
1515 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1519 desc => "magic [subsys/sysname] attribute substitution",
1521 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1522 exp_name => "sda-8741C4G-end",
1523 exp_perms => "0:0:0660",
1525 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1526 KERNEL=="sda", ENV{TESTENV}="change-envp"
1527 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
1533 $ENV{SYSFS_PATH} = $sysfs;
1534 $ENV{UDEV_CONFIG_FILE} = $udev_conf;
1537 my ($action, $subsys, $devpath, $rules) = @_;
1539 $ENV{DEVPATH} = $devpath;
1541 # create temporary rules
1542 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1546 $ENV{ACTION} = $action;
1547 $ENV{SUBSYSTEM} = $subsys;
1548 if ($valgrind > 0) {
1549 system("$udev_bin_valgrind");
1551 system("$udev_bin");
1557 sub permissions_test {
1558 my($rules, $uid, $gid, $mode) = @_;
1564 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1566 if (defined(getpwnam($1))) {
1567 $userid = int(getpwnam($1));
1571 if ($uid != $userid) { $wrong = 1; }
1574 if (defined(getgrnam($2))) {
1575 $groupid = int(getgrnam($2));
1579 if ($gid != $groupid) { $wrong = 1; }
1582 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1585 print "permissions: ok\n";
1587 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1588 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1589 print "permissions: error\n";
1595 sub major_minor_test {
1596 my($rules, $rdev) = @_;
1598 my $major = ($rdev >> 8) & 0xfff;
1599 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1602 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
1604 if ($major != $1) { $wrong = 1; };
1607 if ($minor != $2) { $wrong = 1; };
1610 print "major:minor: ok\n";
1612 printf " expected major:minor is: %i:%i\n", $1, $2;
1613 printf " created major:minor is : %i:%i\n", $major, $minor;
1614 print "major:minor: error\n";
1623 my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`;
1625 if ($output =~ m/(.*)-> (.*)/) {
1626 if ($2 eq $rules->{exp_target}) {
1627 print "symlink: ok\n";
1629 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
1630 print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n";
1631 print "symlink: error";
1632 if ($rules->{exp_add_error}) {
1633 print " as expected\n";
1641 print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
1642 print "symlink: not created";
1643 if ($rules->{exp_add_error}) {
1644 print " as expected\n";
1653 sub make_udev_root {
1654 system("rm -rf $udev_root");
1655 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1656 # setting group and mode of udev_root ensures the tests work
1657 # even if the parent directory has setgid bit enabled.
1658 chown (0, 0, $udev_root) || die "unable to chown $udev_root\n";
1659 chmod (0755, $udev_root) || die "unable to chmod $udev_root\n";
1663 my ($rules, $number) = @_;
1665 print "TEST $number: $rules->{desc}\n";
1667 if ($rules->{exp_target}) {
1668 print "device \'$rules->{devpath}\' expecting link '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
1670 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1674 udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
1675 if (defined($rules->{not_exp_name})) {
1676 if ((-e "$PWD/$udev_root$rules->{not_exp_name}") ||
1677 (-l "$PWD/$udev_root$rules->{not_exp_name}")) {
1678 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1684 if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
1685 (-l "$PWD/$udev_root$rules->{exp_name}")) {
1687 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1688 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}");
1690 if (defined($rules->{exp_perms})) {
1691 permissions_test($rules, $uid, $gid, $mode);
1693 if (defined($rules->{exp_majorminor})) {
1694 major_minor_test($rules, $rdev);
1696 if (defined($rules->{exp_target})) {
1697 symlink_test($rules);
1702 if ($rules->{exp_add_error}) {
1703 print " as expected\n";
1706 system("tree $udev_root");
1713 if (defined($rules->{option}) && $rules->{option} eq "keep") {
1718 udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
1719 if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
1720 (-l "$PWD/$udev_root$rules->{exp_name}")) {
1721 print "remove: error";
1722 if ($rules->{exp_rem_error}) {
1723 print " as expected\n";
1726 system("tree $udev_root");
1732 print "remove: ok\n";
1737 if (defined($rules->{option}) && $rules->{option} eq "clean") {
1743 # only run if we have root permissions
1744 # due to mknod restrictions
1746 print "Must have root permissions to run properly.\n";
1753 # create config file
1754 open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
1755 print CONF "udev_root=\"$udev_root\"\n";
1756 print CONF "udev_rules=\"$PWD\"\n";
1757 print CONF "udev_log=\"err\"\n";
1763 foreach my $arg (@ARGV) {
1764 if ($arg =~ m/--valgrind/) {
1766 printf("using valgrind\n");
1773 foreach my $arg (@list) {
1774 if (defined($tests[$arg-1]->{desc})) {
1775 print "udev-test will run test number $arg:\n\n";
1776 run_test($tests[$arg-1], $arg);
1778 print "test does not exist.\n";
1783 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1785 foreach my $rules (@tests) {
1786 run_test($rules, $test_num);
1791 print "$error errors occured\n\n";
1794 system("rm -rf $udev_root");
1795 unlink($udev_rules);