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-2012 Kay Sievers <kay.sievers@vrfy.org>
18 # Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
23 my $udev_bin = "./test-udev";
25 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
26 my $udev_dev = "test/dev";
27 my $udev_run = "test/run";
28 my $udev_rules_dir = "$udev_run/udev/rules.d";
29 my $udev_rules = "$udev_rules_dir/udev-test.rules";
34 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
36 exp_rem_error
=> "yes",
42 desc
=> "label test of scsi disc",
43 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
44 exp_name
=> "boot_disk" ,
46 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
47 KERNEL=="ttyACM0", SYMLINK+="modem"
51 desc
=> "label test of scsi disc",
52 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
53 exp_name
=> "boot_disk" ,
55 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
56 KERNEL=="ttyACM0", SYMLINK+="modem"
60 desc
=> "label test of scsi disc",
61 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
62 exp_name
=> "boot_disk" ,
64 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
65 KERNEL=="ttyACM0", SYMLINK+="modem"
69 desc
=> "label test of scsi partition",
70 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
71 exp_name
=> "boot_disk1" ,
73 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
77 desc
=> "label test of pattern match",
78 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
79 exp_name
=> "boot_disk1" ,
81 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
82 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
83 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
84 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
88 desc
=> "label test of multiple sysfs files",
89 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
90 exp_name
=> "boot_disk1" ,
92 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
93 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
97 desc
=> "label test of max sysfs files (skip invalid rule)",
98 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
99 exp_name
=> "boot_disk1" ,
101 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"
102 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
106 desc
=> "catch device by *",
107 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
108 exp_name
=> "modem/0" ,
110 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
114 desc
=> "catch device by * - take 2",
115 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
116 exp_name
=> "modem/0" ,
118 KERNEL=="*ACM1", SYMLINK+="bad"
119 KERNEL=="*ACM0", SYMLINK+="modem/%n"
123 desc
=> "catch device by ?",
124 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
125 exp_name
=> "modem/0" ,
127 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
128 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
129 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
133 desc
=> "catch device by character class",
134 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
135 exp_name
=> "modem/0" ,
137 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
138 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
139 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
143 desc
=> "replace kernel name",
144 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
145 exp_name
=> "modem" ,
147 KERNEL=="ttyACM0", SYMLINK+="modem"
151 desc
=> "Handle comment lines in config file (and replace kernel name)",
152 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
153 exp_name
=> "modem" ,
156 KERNEL=="ttyACM0", SYMLINK+="modem"
161 desc
=> "Handle comment lines in config file with whitespace (and replace kernel name)",
162 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
163 exp_name
=> "modem" ,
165 # this is a comment with whitespace before the comment
166 KERNEL=="ttyACM0", SYMLINK+="modem"
171 desc
=> "Handle whitespace only lines (and replace kernel name)",
172 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
173 exp_name
=> "whitespace" ,
178 # this is a comment with whitespace before the comment
179 KERNEL=="ttyACM0", SYMLINK+="whitespace"
186 desc
=> "Handle empty lines in config file (and replace kernel name)",
187 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
188 exp_name
=> "modem" ,
191 KERNEL=="ttyACM0", SYMLINK+="modem"
196 desc
=> "Handle backslashed multi lines in config file (and replace kernel name)",
197 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
198 exp_name
=> "modem" ,
200 KERNEL=="ttyACM0", \\
206 desc
=> "preserve backslashes, if they are not for a newline",
207 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
210 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
214 desc
=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
215 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
216 exp_name
=> "modem" ,
226 KERNEL=="ttyACM0", \\
232 desc
=> "subdirectory handling",
233 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
234 exp_name
=> "sub/direct/ory/modem" ,
236 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
240 desc
=> "parent device name match of scsi partition",
241 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
242 exp_name
=> "first_disk5" ,
244 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
248 desc
=> "test substitution chars",
249 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
250 exp_name
=> "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
252 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
256 desc
=> "import of shell-value returned from program",
257 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
258 exp_name
=> "node12345678",
260 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
261 KERNEL=="ttyACM0", SYMLINK+="modem"
265 desc
=> "sustitution of sysfs value (%s{file})",
266 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
267 exp_name
=> "disk-ATA-sda" ,
269 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
270 KERNEL=="ttyACM0", SYMLINK+="modem"
274 desc
=> "program result substitution",
275 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
276 exp_name
=> "special-device-5" ,
277 not_exp_name
=> "not" ,
279 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
280 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
284 desc
=> "program result substitution (newline removal)",
285 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
286 exp_name
=> "newline_removed" ,
288 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
292 desc
=> "program result substitution",
293 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
294 exp_name
=> "test-0:0:0:0" ,
296 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
300 desc
=> "program with lots of arguments",
301 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
304 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
308 desc
=> "program with subshell",
309 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
312 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
316 desc
=> "program arguments combined with apostrophes",
317 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
320 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
324 desc
=> "characters before the %c{N} substitution",
325 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
326 exp_name
=> "my-foo9" ,
328 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
332 desc
=> "substitute the second to last argument",
333 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
334 exp_name
=> "my-foo8" ,
336 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
340 desc
=> "test substitution by variable name",
341 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
342 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
344 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
348 desc
=> "test substitution by variable name 2",
349 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
350 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
352 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
356 desc
=> "test substitution by variable name 3",
357 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
358 exp_name
=> "850:0:0:05" ,
360 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
364 desc
=> "test substitution by variable name 4",
365 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
368 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
372 desc
=> "test substitution by variable name 5",
373 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
374 exp_name
=> "8550:0:0:0" ,
376 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
380 desc
=> "non matching SUBSYSTEMS for device with no parent",
381 devpath
=> "/devices/virtual/tty/console",
384 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
385 KERNEL=="console", SYMLINK+="TTY"
389 desc
=> "non matching SUBSYSTEMS",
390 devpath
=> "/devices/virtual/tty/console",
393 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
394 KERNEL=="console", SYMLINK+="TTY"
398 desc
=> "ATTRS match",
399 devpath
=> "/devices/virtual/tty/console",
402 KERNEL=="console", SYMLINK+="TTY"
403 ATTRS{dev}=="5:1", SYMLINK+="foo"
407 desc
=> "ATTR (empty file)",
408 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
409 exp_name
=> "empty" ,
411 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
412 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
413 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
414 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
418 desc
=> "ATTR (non-existent file)",
419 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
420 exp_name
=> "non-existent" ,
422 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
423 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
424 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
425 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
426 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
427 KERNEL=="sda", SYMLINK+="wrong"
431 desc
=> "program and bus type match",
432 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
433 exp_name
=> "scsi-0:0:0:0" ,
435 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
436 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
437 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
441 desc
=> "sysfs parent hierarchy",
442 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
443 exp_name
=> "modem" ,
445 ATTRS{idProduct}=="007b", SYMLINK+="modem"
449 desc
=> "name test with ! in the name",
450 devpath
=> "/devices/virtual/block/fake!blockdev0",
451 exp_name
=> "is/a/fake/blockdev0" ,
453 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
454 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
455 KERNEL=="ttyACM0", SYMLINK+="modem"
459 desc
=> "name test with ! in the name, but no matching rule",
460 devpath
=> "/devices/virtual/block/fake!blockdev0",
461 exp_name
=> "fake/blockdev0" ,
462 exp_rem_error
=> "yes",
464 KERNEL=="ttyACM0", SYMLINK+="modem"
468 desc
=> "KERNELS rule",
469 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
470 exp_name
=> "scsi-0:0:0:0",
472 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
473 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
474 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
475 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
476 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
480 desc
=> "KERNELS wildcard all",
481 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
482 exp_name
=> "scsi-0:0:0:0",
484 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
485 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
486 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
487 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
488 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
492 desc
=> "KERNELS wildcard partial",
493 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
494 exp_name
=> "scsi-0:0:0:0",
496 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
497 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
501 desc
=> "KERNELS wildcard partial 2",
502 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
503 exp_name
=> "scsi-0:0:0:0",
505 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
506 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
510 desc
=> "substitute attr with link target value (first match)",
511 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
512 exp_name
=> "driver-is-sd",
514 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
518 desc
=> "substitute attr with link target value (currently selected device)",
519 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
520 exp_name
=> "driver-is-ahci",
522 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
526 desc
=> "ignore ATTRS attribute whitespace",
527 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
528 exp_name
=> "ignored",
530 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
534 desc
=> "do not ignore ATTRS attribute whitespace",
535 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
536 exp_name
=> "matched-with-space",
538 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
539 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
543 desc
=> "permissions USER=bad GROUP=name",
544 devpath
=> "/devices/virtual/tty/tty33",
546 exp_perms
=> "0:0:0600",
548 KERNEL=="tty33", OWNER="bad", GROUP="name"
552 desc
=> "permissions OWNER=5000",
553 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
555 exp_perms
=> "5000::0600",
557 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000"
561 desc
=> "permissions GROUP=100",
562 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
564 exp_perms
=> ":100:0660",
566 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="100"
570 desc
=> "textual user id",
571 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
573 exp_perms
=> "nobody::0600",
575 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
579 desc
=> "textual group id",
580 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
582 exp_perms
=> ":daemon:0660",
584 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
588 desc
=> "textual user/group id",
589 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
591 exp_perms
=> "root:mail:0660",
593 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
597 desc
=> "permissions MODE=0777",
598 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
600 exp_perms
=> "::0777",
602 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
606 desc
=> "permissions OWNER=5000 GROUP=100 MODE=0777",
607 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
609 exp_perms
=> "5000:100:0777",
611 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="5000", GROUP="100", MODE="0777"
615 desc
=> "permissions OWNER to 5000",
616 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
617 exp_name
=> "ttyACM0",
618 exp_perms
=> "5000::",
620 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000"
624 desc
=> "permissions GROUP to 100",
625 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
626 exp_name
=> "ttyACM0",
627 exp_perms
=> ":100:0660",
629 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="100"
633 desc
=> "permissions MODE to 0060",
634 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
635 exp_name
=> "ttyACM0",
636 exp_perms
=> "::0060",
638 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
642 desc
=> "permissions OWNER, GROUP, MODE",
643 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
644 exp_name
=> "ttyACM0",
645 exp_perms
=> "5000:100:0777",
647 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="5000", GROUP="100", MODE="0777"
651 desc
=> "permissions only rule",
652 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
653 exp_name
=> "ttyACM0",
654 exp_perms
=> "5000:100:0777",
656 KERNEL=="ttyACM[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
657 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
658 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
662 desc
=> "multiple permissions only rule",
663 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
664 exp_name
=> "ttyACM0",
665 exp_perms
=> "3000:4000:0777",
667 SUBSYSTEM=="tty", OWNER="3000"
668 SUBSYSTEM=="tty", GROUP="4000"
669 SUBSYSTEM=="tty", MODE="0777"
670 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
671 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
675 desc
=> "permissions only rule with override at SYMLINK+ rule",
676 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
677 exp_name
=> "ttyACM0",
678 exp_perms
=> "3000:8000:0777",
680 SUBSYSTEM=="tty", OWNER="3000"
681 SUBSYSTEM=="tty", GROUP="4000"
682 SUBSYSTEM=="tty", MODE="0777"
683 KERNEL=="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
684 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="8000"
688 desc
=> "major/minor number test",
689 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
691 exp_majorminor
=> "8:0",
693 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
697 desc
=> "big major number test",
698 devpath
=> "/devices/virtual/misc/misc-fake1",
700 exp_majorminor
=> "4095:1",
702 KERNEL=="misc-fake1", SYMLINK+="node"
706 desc
=> "big major and big minor number test",
707 devpath
=> "/devices/virtual/misc/misc-fake89999",
709 exp_majorminor
=> "4095:89999",
711 KERNEL=="misc-fake89999", SYMLINK+="node"
715 desc
=> "multiple symlinks with format char",
716 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
717 exp_name
=> "symlink2-ttyACM0",
719 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
723 desc
=> "multiple symlinks with a lot of s p a c e s",
724 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
728 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
732 desc
=> "symlink creation (same directory)",
733 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
734 exp_name
=> "modem0",
736 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
740 desc
=> "multiple symlinks",
741 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
742 exp_name
=> "second-0" ,
744 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
748 desc
=> "symlink name '.'",
749 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
751 exp_add_error
=> "yes",
752 exp_rem_error
=> "yes",
754 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
758 desc
=> "symlink node to itself",
759 devpath
=> "/devices/virtual/tty/tty0",
761 exp_add_error
=> "yes",
762 exp_rem_error
=> "yes",
765 KERNEL=="tty0", SYMLINK+="tty0"
769 desc
=> "symlink %n substitution",
770 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
771 exp_name
=> "symlink0",
773 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
777 desc
=> "symlink %k substitution",
778 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
779 exp_name
=> "symlink-ttyACM0",
781 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
785 desc
=> "symlink %M:%m substitution",
786 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
787 exp_name
=> "major-166:0",
789 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
793 desc
=> "symlink %b substitution",
794 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
795 exp_name
=> "symlink-0:0:0:0",
797 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
801 desc
=> "symlink %c substitution",
802 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
805 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
809 desc
=> "symlink %c{N} substitution",
810 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
813 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
817 desc
=> "symlink %c{N+} substitution",
818 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
821 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
825 desc
=> "symlink only rule with %c{N+}",
826 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
829 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
833 desc
=> "symlink %s{filename} substitution",
834 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
837 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
841 desc
=> "program result substitution (numbered part of)",
842 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
845 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
849 desc
=> "program result substitution (numbered part of+)",
850 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
853 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
857 desc
=> "SUBSYSTEM match test",
858 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
861 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
862 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
863 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
867 desc
=> "DRIVERS 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", DRIVERS=="sd-wrong"
872 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
876 desc
=> "devnode substitution test",
877 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
880 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
884 desc
=> "parent node name substitution test",
885 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
886 exp_name
=> "sda-part-1",
888 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
892 desc
=> "udev_root substitution",
893 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
894 exp_name
=> "start-test/dev-end",
896 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
900 desc
=> "last_rule option",
901 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
904 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
905 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
909 desc
=> "negation KERNEL!=",
910 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
913 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
914 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
915 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
919 desc
=> "negation SUBSYSTEM!=",
920 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
921 exp_name
=> "not-anything",
923 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
924 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
925 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
929 desc
=> "negation PROGRAM!= exit code",
930 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
931 exp_name
=> "nonzero-program",
933 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
934 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
938 desc
=> "test for whitespace between the operator",
939 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
942 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
943 KERNEL == "sda1" , SYMLINK+ = "true"
947 desc
=> "ENV{} test",
948 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
951 ENV{ENV_KEY_TEST}="test"
952 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
953 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
954 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
958 desc
=> "ENV{} test",
959 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
962 ENV{ENV_KEY_TEST}="test"
963 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
964 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
965 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
966 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
970 desc
=> "ENV{} test (assign)",
971 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
974 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
975 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
976 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
977 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
981 desc
=> "ENV{} test (assign 2 times)",
982 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
985 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
986 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
987 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
988 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
989 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
993 desc
=> "ENV{} test (assign2)",
994 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
997 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
998 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
999 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1000 SUBSYSTEM=="block", SYMLINK+="before"
1001 ENV{PARTITION}=="true", SYMLINK+="part"
1005 desc
=> "untrusted string sanitize",
1006 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1009 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1013 desc
=> "untrusted string sanitize (don't replace utf8)",
1014 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1017 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1021 desc
=> "untrusted string sanitize (replace invalid utf8)",
1022 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1023 exp_name
=> "replaced",
1025 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1029 desc
=> "read sysfs value from parent device",
1030 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1031 exp_name
=> "serial-354172020305000",
1033 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1037 desc
=> "match against empty key string",
1038 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1041 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1042 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1043 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1044 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1048 desc
=> "check ACTION value",
1049 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1052 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1053 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1057 desc
=> "final assignment",
1058 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1060 exp_perms
=> "root:tty:0640",
1062 KERNEL=="sda", GROUP:="tty"
1063 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1067 desc
=> "final assignment 2",
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 SUBSYSTEM=="block", MODE:="640"
1074 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1078 desc
=> "env substitution",
1079 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1080 exp_name
=> "node-add-me",
1082 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1086 desc
=> "reset list to current value",
1087 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1088 exp_name
=> "three",
1089 not_exp_name
=> "two",
1091 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1092 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1093 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1097 desc
=> "test empty SYMLINK+ (empty override)",
1098 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1099 exp_name
=> "right",
1100 not_exp_name
=> "wrong",
1102 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1103 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1104 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1108 desc
=> "test multi matches",
1109 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1110 exp_name
=> "right",
1112 KERNEL=="ttyACM*", SYMLINK+="before"
1113 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1117 desc
=> "test multi matches 2",
1118 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1119 exp_name
=> "right",
1121 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1122 KERNEL=="ttyACM*", SYMLINK+="before"
1123 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1127 desc
=> "test multi matches 3",
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=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1133 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1134 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1138 desc
=> "test multi matches 4",
1139 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1140 exp_name
=> "right",
1142 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1143 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1144 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1145 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1146 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1150 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1151 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1152 exp_name
=> "parent",
1155 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1156 KERNEL=="sda", SYMLINK+="parent"
1160 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1161 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1162 exp_name
=> "parentenv-parent_right",
1165 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1169 desc
=> "GOTO test",
1170 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1171 exp_name
=> "right",
1173 KERNEL=="sda1", GOTO="TEST"
1174 KERNEL=="sda1", SYMLINK+="wrong"
1175 KERNEL=="sda1", GOTO="BAD"
1176 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1177 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1178 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1183 desc
=> "GOTO label does not exist",
1184 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1185 exp_name
=> "right",
1187 KERNEL=="sda1", GOTO="does-not-exist"
1188 KERNEL=="sda1", SYMLINK+="right",
1193 desc
=> "SYMLINK+ compare test",
1194 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1195 exp_name
=> "right",
1196 not_exp_name
=> "wrong",
1198 KERNEL=="sda1", SYMLINK+="link"
1199 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1200 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1204 desc
=> "invalid key operation",
1205 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1208 KERNEL="sda1", SYMLINK+="no"
1209 KERNEL=="sda1", SYMLINK+="yes"
1213 desc
=> "operator chars in attribute",
1214 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1217 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1221 desc
=> "overlong comment line",
1222 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1225 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1226 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1227 KERNEL=="sda1", SYMLINK+=="no"
1228 KERNEL=="sda1", SYMLINK+="yes"
1232 desc
=> "magic subsys/kernel lookup",
1233 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1234 exp_name
=> "00:16:41:e2:8d:ff",
1236 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1240 desc
=> "TEST absolute path",
1241 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1242 exp_name
=> "there",
1244 TEST=="/etc/hosts", SYMLINK+="there"
1245 TEST!="/etc/hosts", SYMLINK+="notthere"
1249 desc
=> "TEST subsys/kernel lookup",
1250 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1253 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1257 desc
=> "TEST relative path",
1258 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1259 exp_name
=> "relative",
1261 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1265 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1266 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1267 exp_name
=> "found-subdir",
1269 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1273 desc
=> "TEST MODE=0000",
1274 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1276 exp_perms
=> "0:0:0000",
1277 exp_rem_error
=> "yes",
1279 KERNEL=="sda", MODE="0000"
1283 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1284 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1286 exp_perms
=> "5000:100:0400",
1287 exp_rem_error
=> "yes",
1289 KERNEL=="sda", MODE="666"
1290 KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1294 desc
=> "TEST PROGRAM feeds MODE with overflow",
1295 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1297 exp_perms
=> "0:0:0440",
1298 exp_rem_error
=> "yes",
1300 KERNEL=="sda", MODE="440"
1301 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1305 desc
=> "magic [subsys/sysname] attribute substitution",
1306 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1307 exp_name
=> "sda-8741C4G-end",
1308 exp_perms
=> "0:0:0600",
1310 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1311 KERNEL=="sda", ENV{TESTENV}="change-envp"
1312 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1316 desc
=> "builtin path_id",
1317 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1318 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1320 KERNEL=="sda", IMPORT{builtin}="path_id"
1321 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1327 my ($action, $devpath, $rules) = @_;
1329 # create temporary rules
1330 system("mkdir", "-p", "$udev_rules_dir");
1331 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1335 if ($valgrind > 0) {
1336 system("$udev_bin_valgrind $action $devpath");
1338 system("$udev_bin", "$action", "$devpath");
1344 sub permissions_test
{
1345 my($rules, $uid, $gid, $mode) = @_;
1351 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1353 if (defined(getpwnam($1))) {
1354 $userid = int(getpwnam($1));
1358 if ($uid != $userid) { $wrong = 1; }
1361 if (defined(getgrnam($2))) {
1362 $groupid = int(getgrnam($2));
1366 if ($gid != $groupid) { $wrong = 1; }
1369 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1372 print "permissions: ok\n";
1374 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1375 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1376 print "permissions: error\n";
1382 sub major_minor_test
{
1383 my($rules, $rdev) = @_;
1385 my $major = ($rdev >> 8) & 0xfff;
1386 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1389 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1391 if ($major != $1) { $wrong = 1; };
1394 if ($minor != $2) { $wrong = 1; };
1397 print "major:minor: ok\n";
1399 printf " expected major:minor is: %i:%i\n", $1, $2;
1400 printf " created major:minor is : %i:%i\n", $major, $minor;
1401 print "major:minor: error\n";
1408 system("rm", "-rf", "$udev_dev");
1409 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1410 # setting group and mode of udev_dev ensures the tests work
1411 # even if the parent directory has setgid bit enabled.
1412 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1413 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1415 system("rm", "-rf", "$udev_run");
1419 my ($rules, $number) = @_;
1421 print "TEST $number: $rules->{desc}\n";
1422 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1424 udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1425 if (defined($rules->{not_exp_name
})) {
1426 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1427 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1428 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1434 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1435 (-l
"$udev_dev/$rules->{exp_name}")) {
1437 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1438 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1440 if (defined($rules->{exp_perms
})) {
1441 permissions_test
($rules, $uid, $gid, $mode);
1443 if (defined($rules->{exp_majorminor
})) {
1444 major_minor_test
($rules, $rdev);
1449 if ($rules->{exp_add_error
}) {
1450 print " as expected\n";
1453 system("tree", "$udev_dev");
1460 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1465 udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1466 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1467 (-l
"$udev_dev/$rules->{exp_name}")) {
1468 print "remove: error";
1469 if ($rules->{exp_rem_error
}) {
1470 print " as expected\n";
1473 system("tree", "$udev_dev");
1479 print "remove: ok\n";
1484 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1490 # only run if we have root permissions
1491 # due to mknod restrictions
1493 print "Must have root permissions to run properly.\n";
1502 foreach my $arg (@ARGV) {
1503 if ($arg =~ m/--valgrind/) {
1505 printf("using valgrind\n");
1512 foreach my $arg (@list) {
1513 if (defined($tests[$arg-1]->{desc
})) {
1514 print "udev-test will run test number $arg:\n\n";
1515 run_test
($tests[$arg-1], $arg);
1517 print "test does not exist.\n";
1522 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1524 foreach my $rules (@tests) {
1525 run_test
($rules, $test_num);
1530 print "$error errors occured\n\n";
1533 system("rm", "-rf", "$udev_dev");
1534 system("rm", "-rf", "$udev_run");