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-2011 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";
35 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
37 exp_rem_error => "yes",
43 desc => "label test of scsi disc",
44 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
45 exp_name => "boot_disk" ,
47 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
48 KERNEL=="ttyACM0", SYMLINK+="modem"
52 desc => "label test of scsi disc",
53 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
54 exp_name => "boot_disk" ,
56 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
57 KERNEL=="ttyACM0", SYMLINK+="modem"
61 desc => "label test of scsi disc",
62 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
63 exp_name => "boot_disk" ,
65 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
66 KERNEL=="ttyACM0", SYMLINK+="modem"
70 desc => "label test of scsi partition",
71 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
72 exp_name => "boot_disk1" ,
74 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
78 desc => "label test of pattern match",
79 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
80 exp_name => "boot_disk1" ,
82 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
83 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
84 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
85 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
89 desc => "label test of multiple sysfs files",
90 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
91 exp_name => "boot_disk1" ,
93 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
94 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
98 desc => "label test of max sysfs files (skip invalid rule)",
99 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
100 exp_name => "boot_disk1" ,
102 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"
103 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
107 desc => "catch device by *",
108 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
109 exp_name => "modem/0" ,
111 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
115 desc => "catch device by * - take 2",
116 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
117 exp_name => "modem/0" ,
119 KERNEL=="*ACM1", SYMLINK+="bad"
120 KERNEL=="*ACM0", SYMLINK+="modem/%n"
124 desc => "catch device by ?",
125 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
126 exp_name => "modem/0" ,
128 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
129 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
130 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
134 desc => "catch device by character class",
135 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
136 exp_name => "modem/0" ,
138 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
139 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
140 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
144 desc => "replace kernel name",
145 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
146 exp_name => "modem" ,
148 KERNEL=="ttyACM0", SYMLINK+="modem"
152 desc => "Handle comment lines in config file (and replace kernel name)",
153 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
154 exp_name => "modem" ,
157 KERNEL=="ttyACM0", SYMLINK+="modem"
162 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
163 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
164 exp_name => "modem" ,
166 # this is a comment with whitespace before the comment
167 KERNEL=="ttyACM0", SYMLINK+="modem"
172 desc => "Handle whitespace only lines (and replace kernel name)",
173 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
174 exp_name => "whitespace" ,
179 # this is a comment with whitespace before the comment
180 KERNEL=="ttyACM0", SYMLINK+="whitespace"
187 desc => "Handle empty lines in config file (and replace kernel name)",
188 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
189 exp_name => "modem" ,
192 KERNEL=="ttyACM0", SYMLINK+="modem"
197 desc => "Handle backslashed multi lines in config file (and replace kernel name)",
198 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
199 exp_name => "modem" ,
201 KERNEL=="ttyACM0", \\
207 desc => "preserve backslashes, if they are not for a newline",
208 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
211 KERNEL=="ttyACM0", PROGRAM=="@rootprefix@/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
215 desc => "Handle stupid 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" ,
227 KERNEL=="ttyACM0", \\
233 desc => "subdirectory handling",
234 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
235 exp_name => "sub/direct/ory/modem" ,
237 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
241 desc => "parent device name match of scsi partition",
242 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
243 exp_name => "first_disk5" ,
245 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
249 desc => "test substitution chars",
250 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
251 exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
253 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
257 desc => "import of shell-value file",
258 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
259 exp_name => "subdir/err/node" ,
261 SUBSYSTEMS=="scsi", IMPORT{file}="udev-test.conf", SYMLINK+="subdir/%E{udev_log}/node"
262 KERNEL=="ttyACM0", SYMLINK+="modem"
266 desc => "import of shell-value returned from program",
267 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
268 exp_name => "node12345678",
270 SUBSYSTEMS=="scsi", IMPORT{program}="@rootprefix@/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
271 KERNEL=="ttyACM0", SYMLINK+="modem"
275 desc => "sustitution of sysfs value (%s{file})",
276 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
277 exp_name => "disk-ATA-sda" ,
279 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
280 KERNEL=="ttyACM0", SYMLINK+="modem"
284 desc => "program result substitution",
285 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
286 exp_name => "special-device-5" ,
287 not_exp_name => "not" ,
289 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
290 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
294 desc => "program result substitution (newline removal)",
295 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
296 exp_name => "newline_removed" ,
298 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
302 desc => "program result substitution",
303 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
304 exp_name => "test-0:0:0:0" ,
306 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
310 desc => "program with lots of arguments",
311 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
314 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
318 desc => "program with subshell",
319 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
322 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
326 desc => "program arguments combined with apostrophes",
327 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
330 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
334 desc => "characters before the %c{N} substitution",
335 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
336 exp_name => "my-foo9" ,
338 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
342 desc => "substitute the second to last argument",
343 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
344 exp_name => "my-foo8" ,
346 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
350 desc => "test substitution by variable name",
351 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
352 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
354 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
358 desc => "test substitution by variable name 2",
359 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
360 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
362 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
366 desc => "test substitution by variable name 3",
367 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
368 exp_name => "850:0:0:05" ,
370 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
374 desc => "test substitution by variable name 4",
375 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
378 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
382 desc => "test substitution by variable name 5",
383 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
384 exp_name => "8550:0:0:0" ,
386 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
390 desc => "non matching SUBSYSTEMS for device with no parent",
391 devpath => "/devices/virtual/tty/console",
394 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
395 KERNEL=="console", SYMLINK+="TTY"
399 desc => "non matching SUBSYSTEMS",
400 devpath => "/devices/virtual/tty/console",
403 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
404 KERNEL=="console", SYMLINK+="TTY"
408 desc => "ATTRS match",
409 devpath => "/devices/virtual/tty/console",
412 KERNEL=="console", SYMLINK+="TTY"
413 ATTRS{dev}=="5:1", SYMLINK+="foo"
417 desc => "ATTR (empty file)",
418 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
419 exp_name => "empty" ,
421 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
422 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
423 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
424 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
428 desc => "ATTR (non-existent file)",
429 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
430 exp_name => "non-existent" ,
432 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
433 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
434 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
435 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
436 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
437 KERNEL=="sda", SYMLINK+="wrong"
441 desc => "program and bus type match",
442 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
443 exp_name => "scsi-0:0:0:0" ,
445 SUBSYSTEMS=="usb", PROGRAM=="@rootprefix@/bin/echo -n usb-%b", SYMLINK+="%c"
446 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n scsi-%b", SYMLINK+="%c"
447 SUBSYSTEMS=="foo", PROGRAM=="@rootprefix@/bin/echo -n foo-%b", SYMLINK+="%c"
451 desc => "sysfs parent hierarchy",
452 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
453 exp_name => "modem" ,
455 ATTRS{idProduct}=="007b", SYMLINK+="modem"
459 desc => "name test with ! in the name",
460 devpath => "/devices/virtual/block/fake!blockdev0",
461 exp_name => "is/a/fake/blockdev0" ,
463 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
464 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
465 KERNEL=="ttyACM0", SYMLINK+="modem"
469 desc => "name test with ! in the name, but no matching rule",
470 devpath => "/devices/virtual/block/fake!blockdev0",
471 exp_name => "fake/blockdev0" ,
472 exp_rem_error => "yes",
474 KERNEL=="ttyACM0", SYMLINK+="modem"
478 desc => "KERNELS rule",
479 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
480 exp_name => "scsi-0:0:0:0",
482 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
483 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
484 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
485 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
486 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
490 desc => "KERNELS wildcard all",
491 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
492 exp_name => "scsi-0:0:0:0",
494 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
495 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
496 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
497 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
498 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
502 desc => "KERNELS wildcard partial",
503 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
504 exp_name => "scsi-0:0:0:0",
506 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
507 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
511 desc => "KERNELS wildcard partial 2",
512 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
513 exp_name => "scsi-0:0:0:0",
515 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
516 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
520 desc => "substitute attr with link target value (first match)",
521 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
522 exp_name => "driver-is-sd",
524 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
528 desc => "substitute attr with link target value (currently selected device)",
529 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
530 exp_name => "driver-is-ahci",
532 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
536 desc => "ignore ATTRS attribute whitespace",
537 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
538 exp_name => "ignored",
540 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
544 desc => "do not ignore ATTRS attribute whitespace",
545 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
546 exp_name => "matched-with-space",
548 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
549 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
553 desc => "permissions USER=bad GROUP=name",
554 devpath => "/devices/virtual/tty/tty33",
556 exp_perms => "0:0:0600",
558 KERNEL=="tty33", SYMLINK+="tty33", OWNER="bad", GROUP="name"
562 desc => "permissions OWNER=5000",
563 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
565 exp_perms => "5000::0600",
567 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000"
571 desc => "permissions GROUP=100",
572 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
574 exp_perms => ":100:0660",
576 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="100"
580 desc => "textual user id",
581 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
583 exp_perms => "nobody::0600",
585 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
589 desc => "textual group id",
590 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
592 exp_perms => ":daemon:0660",
594 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
598 desc => "textual user/group id",
599 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
601 exp_perms => "root:mail:0660",
603 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
607 desc => "permissions MODE=0777",
608 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
610 exp_perms => "::0777",
612 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
616 desc => "permissions OWNER=5000 GROUP=100 MODE=0777",
617 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
619 exp_perms => "5000:100:0777",
621 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000", GROUP="100", MODE="0777"
625 desc => "permissions OWNER to 5000",
626 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
627 exp_name => "ttyACM0",
628 exp_perms => "5000::",
630 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000"
634 desc => "permissions GROUP to 100",
635 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
636 exp_name => "ttyACM0",
637 exp_perms => ":100:0660",
639 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="100"
643 desc => "permissions MODE to 0060",
644 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
645 exp_name => "ttyACM0",
646 exp_perms => "::0060",
648 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
652 desc => "permissions OWNER, GROUP, MODE",
653 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
654 exp_name => "ttyACM0",
655 exp_perms => "5000:100:0777",
657 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000", GROUP="100", MODE="0777"
661 desc => "permissions only rule",
662 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
663 exp_name => "ttyACM0",
664 exp_perms => "5000:100:0777",
666 KERNEL=="ttyACM[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
667 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
668 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
672 desc => "multiple permissions only rule",
673 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
674 exp_name => "ttyACM0",
675 exp_perms => "3000:4000:0777",
677 SUBSYSTEM=="tty", OWNER="3000"
678 SUBSYSTEM=="tty", GROUP="4000"
679 SUBSYSTEM=="tty", MODE="0777"
680 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
681 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
685 desc => "permissions only rule with override at SYMLINK+ rule",
686 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
687 exp_name => "ttyACM0",
688 exp_perms => "3000:8000:0777",
690 SUBSYSTEM=="tty", OWNER="3000"
691 SUBSYSTEM=="tty", GROUP="4000"
692 SUBSYSTEM=="tty", MODE="0777"
693 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
694 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="8000"
698 desc => "major/minor number test",
699 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
701 exp_majorminor => "8:0",
703 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
707 desc => "big major number test",
708 devpath => "/devices/virtual/misc/misc-fake1",
710 exp_majorminor => "4095:1",
712 KERNEL=="misc-fake1", SYMLINK+="node"
716 desc => "big major and big minor number test",
717 devpath => "/devices/virtual/misc/misc-fake89999",
719 exp_majorminor => "4095:89999",
721 KERNEL=="misc-fake89999", SYMLINK+="node"
725 desc => "multiple symlinks with format char",
726 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
727 exp_name => "symlink2-ttyACM0",
729 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
733 desc => "multiple symlinks with a lot of s p a c e s",
734 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
738 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
742 desc => "symlink creation (same directory)",
743 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
744 exp_name => "modem0",
746 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
750 desc => "multiple symlinks",
751 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
752 exp_name => "second-0" ,
754 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
758 desc => "symlink name '.'",
759 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
761 exp_add_error => "yes",
762 exp_rem_error => "yes",
764 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
768 desc => "symlink node to itself",
769 devpath => "/devices/virtual/tty/tty0",
771 exp_add_error => "yes",
772 exp_rem_error => "yes",
775 KERNEL=="tty0", SYMLINK+="tty0"
779 desc => "symlink %n substitution",
780 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
781 exp_name => "symlink0",
783 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
787 desc => "symlink %k substitution",
788 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
789 exp_name => "symlink-ttyACM0",
791 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
795 desc => "symlink %M:%m substitution",
796 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
797 exp_name => "major-166:0",
799 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
803 desc => "symlink %b substitution",
804 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
805 exp_name => "symlink-0:0:0:0",
807 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
811 desc => "symlink %c substitution",
812 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
815 KERNEL=="ttyACM[0-9]*", PROGRAM=="@rootprefix@/bin/echo test", SYMLINK+="%c"
819 desc => "symlink %c{N} substitution",
820 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
823 KERNEL=="ttyACM[0-9]*", PROGRAM=="@rootprefix@/bin/echo symlink test this", SYMLINK+="%c{2}"
827 desc => "symlink %c{N+} substitution",
828 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
831 KERNEL=="ttyACM[0-9]*", PROGRAM=="@rootprefix@/bin/echo symlink test this", SYMLINK+="%c{2+}"
835 desc => "symlink only rule with %c{N+}",
836 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
839 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="@rootprefix@/bin/echo link test this" SYMLINK+="%c{2+}"
843 desc => "symlink %s{filename} substitution",
844 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
847 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
851 desc => "program result substitution (numbered part of)",
852 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
855 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
859 desc => "program result substitution (numbered part of+)",
860 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
863 SUBSYSTEMS=="scsi", PROGRAM=="@rootprefix@/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
867 desc => "SUBSYSTEM match test",
868 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
871 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
872 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
873 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
877 desc => "DRIVERS match test",
878 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
881 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
882 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
886 desc => "devnode substitution test",
887 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
890 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
894 desc => "parent node name substitution test",
895 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
896 exp_name => "sda-part-1",
898 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
902 desc => "udev_root substitution",
903 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
904 exp_name => "start-udev-root-end",
906 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
910 desc => "last_rule option",
911 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
914 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
915 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
919 desc => "negation KERNEL!=",
920 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
923 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
924 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
925 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
929 desc => "negation SUBSYSTEM!=",
930 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
931 exp_name => "not-anything",
933 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
934 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
935 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
939 desc => "negation PROGRAM!= exit code",
940 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
941 exp_name => "nonzero-program",
943 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
944 KERNEL=="sda1", PROGRAM!="@rootprefix@/bin/false", SYMLINK+="nonzero-program"
948 desc => "test for whitespace between the operator",
949 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
952 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
953 KERNEL == "sda1" , SYMLINK+ = "true"
957 desc => "ENV{} test",
958 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
961 ENV{ENV_KEY_TEST}="test"
962 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
963 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
964 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
968 desc => "ENV{} test",
969 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
972 ENV{ENV_KEY_TEST}="test"
973 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
974 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
975 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
976 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
980 desc => "ENV{} test (assign)",
981 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
984 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
985 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
986 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
987 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
991 desc => "ENV{} test (assign 2 times)",
992 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
995 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
996 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
997 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
998 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
999 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1003 desc => "ENV{} test (assign2)",
1004 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1007 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1008 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1009 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1010 SUBSYSTEM=="block", SYMLINK+="before"
1011 ENV{PARTITION}=="true", SYMLINK+="part"
1015 desc => "untrusted string sanitize",
1016 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1019 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="@rootprefix@/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1023 desc => "untrusted string sanitize (don't replace utf8)",
1024 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1027 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="@rootprefix@/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1031 desc => "untrusted string sanitize (replace invalid utf8)",
1032 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1033 exp_name => "replaced",
1035 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="@rootprefix@/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1039 desc => "read sysfs value from parent device",
1040 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1041 exp_name => "serial-354172020305000",
1043 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1047 desc => "match against empty key string",
1048 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1051 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1052 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1053 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1054 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1058 desc => "check ACTION value",
1059 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1062 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1063 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1067 desc => "final assignment",
1068 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1070 exp_perms => "root:tty:0640",
1072 KERNEL=="sda", GROUP:="tty"
1073 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1077 desc => "final assignment 2",
1078 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1080 exp_perms => "root:tty:0640",
1082 KERNEL=="sda", GROUP:="tty"
1083 SUBSYSTEM=="block", MODE:="640"
1084 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1088 desc => "env substitution",
1089 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1090 exp_name => "node-add-me",
1092 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1096 desc => "reset list to current value",
1097 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1098 exp_name => "three",
1099 not_exp_name => "two",
1101 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1102 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1103 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1107 desc => "test empty SYMLINK+ (empty override)",
1108 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1109 exp_name => "right",
1110 not_exp_name => "wrong",
1112 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1113 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1114 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1118 desc => "test multi matches",
1119 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1120 exp_name => "right",
1122 KERNEL=="ttyACM*", SYMLINK+="before"
1123 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1127 desc => "test multi matches 2",
1128 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1129 exp_name => "right",
1131 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1132 KERNEL=="ttyACM*", SYMLINK+="before"
1133 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1137 desc => "test multi matches 3",
1138 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1139 exp_name => "right",
1141 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1142 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1143 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1144 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1148 desc => "test multi matches 4",
1149 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1150 exp_name => "right",
1152 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1153 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1154 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1155 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1156 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1160 desc => "IMPORT parent test sequence 1/2 (keep)",
1161 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1162 exp_name => "parent",
1165 KERNEL=="sda", IMPORT{program}="@rootprefix@/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1166 KERNEL=="sda", SYMLINK+="parent"
1170 desc => "IMPORT parent test sequence 2/2 (keep)",
1171 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1172 exp_name => "parentenv-parent_right",
1175 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1179 desc => "GOTO test",
1180 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1181 exp_name => "right",
1183 KERNEL=="sda1", GOTO="TEST"
1184 KERNEL=="sda1", SYMLINK+="wrong"
1185 KERNEL=="sda1", GOTO="BAD"
1186 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1187 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1188 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1193 desc => "GOTO label does not exist",
1194 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1195 exp_name => "right",
1197 KERNEL=="sda1", GOTO="does-not-exist"
1198 KERNEL=="sda1", SYMLINK+="right",
1203 desc => "SYMLINK+ compare test",
1204 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1205 exp_name => "right",
1206 not_exp_name => "wrong",
1208 KERNEL=="sda1", SYMLINK+="link"
1209 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1210 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1214 desc => "invalid key operation",
1215 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1218 KERNEL="sda1", SYMLINK+="no"
1219 KERNEL=="sda1", SYMLINK+="yes"
1223 desc => "operator chars in attribute",
1224 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1227 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1231 desc => "overlong comment line",
1232 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1235 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1236 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1237 KERNEL=="sda1", SYMLINK+=="no"
1238 KERNEL=="sda1", SYMLINK+="yes"
1242 desc => "magic subsys/kernel lookup",
1243 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1244 exp_name => "00:16:41:e2:8d:ff",
1246 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1250 desc => "TEST absolute path",
1251 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1252 exp_name => "there",
1254 TEST=="/etc/hosts", SYMLINK+="there"
1255 TEST!="/etc/hosts", SYMLINK+="notthere"
1259 desc => "TEST subsys/kernel lookup",
1260 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1263 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1267 desc => "TEST relative path",
1268 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1269 exp_name => "relative",
1271 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1275 desc => "TEST wildcard substitution (find queue/nr_requests)",
1276 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1277 exp_name => "found-subdir",
1279 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1283 desc => "TEST MODE=0000",
1284 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1286 exp_perms => "0:0:0000",
1287 exp_rem_error => "yes",
1289 KERNEL=="sda", MODE="0000"
1293 desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
1294 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1296 exp_perms => "5000:100:0400",
1297 exp_rem_error => "yes",
1299 KERNEL=="sda", MODE="666"
1300 KERNEL=="sda", PROGRAM=="@rootprefix@/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1304 desc => "TEST PROGRAM feeds MODE with overflow",
1305 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1307 exp_perms => "0:0:0440",
1308 exp_rem_error => "yes",
1310 KERNEL=="sda", MODE="440"
1311 KERNEL=="sda", PROGRAM=="@rootprefix@/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1315 desc => "magic [subsys/sysname] attribute substitution",
1316 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1317 exp_name => "sda-8741C4G-end",
1318 exp_perms => "0:0:0600",
1320 KERNEL=="sda", PROGRAM="@rootprefix@/bin/true create-envp"
1321 KERNEL=="sda", ENV{TESTENV}="change-envp"
1322 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
1326 desc => "builtin path_id",
1327 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1328 exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1330 KERNEL=="sda", IMPORT{builtin}="path_id"
1331 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1337 $ENV{UDEV_CONFIG_FILE} = $udev_conf;
1340 my ($action, $devpath, $rules) = @_;
1342 # create temporary rules
1343 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1347 if ($valgrind > 0) {
1348 system("$udev_bin_valgrind $action $devpath");
1350 system("$udev_bin $action $devpath");
1356 sub permissions_test {
1357 my($rules, $uid, $gid, $mode) = @_;
1363 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1365 if (defined(getpwnam($1))) {
1366 $userid = int(getpwnam($1));
1370 if ($uid != $userid) { $wrong = 1; }
1373 if (defined(getgrnam($2))) {
1374 $groupid = int(getgrnam($2));
1378 if ($gid != $groupid) { $wrong = 1; }
1381 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1384 print "permissions: ok\n";
1386 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1387 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1388 print "permissions: error\n";
1394 sub major_minor_test {
1395 my($rules, $rdev) = @_;
1397 my $major = ($rdev >> 8) & 0xfff;
1398 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1401 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
1403 if ($major != $1) { $wrong = 1; };
1406 if ($minor != $2) { $wrong = 1; };
1409 print "major:minor: ok\n";
1411 printf " expected major:minor is: %i:%i\n", $1, $2;
1412 printf " created major:minor is : %i:%i\n", $major, $minor;
1413 print "major:minor: error\n";
1419 sub make_udev_root {
1420 system("rm -rf $udev_root");
1421 mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
1422 # setting group and mode of udev_root ensures the tests work
1423 # even if the parent directory has setgid bit enabled.
1424 chown (0, 0, $udev_root) || die "unable to chown $udev_root\n";
1425 chmod (0755, $udev_root) || die "unable to chmod $udev_root\n";
1429 my ($rules, $number) = @_;
1431 print "TEST $number: $rules->{desc}\n";
1432 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1434 udev("add", $rules->{devpath}, \$rules->{rules});
1435 if (defined($rules->{not_exp_name})) {
1436 if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") ||
1437 (-l "$PWD/$udev_root/$rules->{not_exp_name}")) {
1438 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1444 if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
1445 (-l "$PWD/$udev_root/$rules->{exp_name}")) {
1447 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1448 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}");
1450 if (defined($rules->{exp_perms})) {
1451 permissions_test($rules, $uid, $gid, $mode);
1453 if (defined($rules->{exp_majorminor})) {
1454 major_minor_test($rules, $rdev);
1459 if ($rules->{exp_add_error}) {
1460 print " as expected\n";
1463 system("tree $udev_root");
1470 if (defined($rules->{option}) && $rules->{option} eq "keep") {
1475 udev("remove", $rules->{devpath}, \$rules->{rules});
1476 if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
1477 (-l "$PWD/$udev_root/$rules->{exp_name}")) {
1478 print "remove: error";
1479 if ($rules->{exp_rem_error}) {
1480 print " as expected\n";
1483 system("tree $udev_root");
1489 print "remove: ok\n";
1494 if (defined($rules->{option}) && $rules->{option} eq "clean") {
1500 # only run if we have root permissions
1501 # due to mknod restrictions
1503 print "Must have root permissions to run properly.\n";
1510 # create config file
1511 open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
1512 print CONF "udev_root=\"$udev_root\"\n";
1513 print CONF "udev_run=\"$udev_root/.udev\"\n";
1514 print CONF "udev_sys=\"$sysfs\"\n";
1515 print CONF "udev_rules=\"$PWD\"\n";
1516 print CONF "udev_log=\"err\"\n";
1522 foreach my $arg (@ARGV) {
1523 if ($arg =~ m/--valgrind/) {
1525 printf("using valgrind\n");
1532 foreach my $arg (@list) {
1533 if (defined($tests[$arg-1]->{desc})) {
1534 print "udev-test will run test number $arg:\n\n";
1535 run_test($tests[$arg-1], $arg);
1537 print "test does not exist.\n";
1542 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1544 foreach my $rules (@tests) {
1545 run_test($rules, $test_num);
1550 print "$error errors occured\n\n";
1553 system("rm -rf $udev_root");
1554 unlink($udev_rules);