]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/udev-test.pl
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@vrfy.org>
18 # Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
23 my $udev_bin = "./test-udev";
27 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin";
28 my $udev_bin_gdb = "gdb --args $udev_bin";
29 my $udev_bin_strace = "strace -efile $udev_bin";
30 my $udev_run = "test/run";
31 my $udev_tmpfs = "test/tmpfs";
32 my $udev_sys = "${udev_tmpfs}/sys";
33 my $udev_dev = "${udev_tmpfs}/dev";
34 my $udev_rules_dir = "$udev_run/udev/rules.d";
35 my $udev_rules = "$udev_rules_dir/udev-test.rules";
36 my $EXIT_TEST_SKIP = 77;
38 my $rules_10k_tags = "";
39 for (my $i = 1; $i <= 10000; ++$i) {
40 $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n";
46 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
48 exp_rem_error
=> "yes",
54 desc
=> "label test of scsi disc",
55 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
56 exp_name
=> "boot_disk" ,
58 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
59 KERNEL=="ttyACM0", SYMLINK+="modem"
63 desc
=> "label test of scsi disc",
64 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
65 exp_name
=> "boot_disk" ,
67 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
68 KERNEL=="ttyACM0", SYMLINK+="modem"
72 desc
=> "label test of scsi disc",
73 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
74 exp_name
=> "boot_disk" ,
76 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
77 KERNEL=="ttyACM0", SYMLINK+="modem"
81 desc
=> "label test of scsi partition",
82 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
83 exp_name
=> "boot_disk1" ,
85 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
89 desc
=> "label test of pattern match",
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", SYMLINK+="boot_disk%n-1"
94 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
95 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
96 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
100 desc
=> "label test of multiple sysfs files",
101 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
102 exp_name
=> "boot_disk1" ,
104 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
105 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
109 desc
=> "label test of max sysfs files (skip invalid rule)",
110 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
111 exp_name
=> "boot_disk1" ,
113 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"
114 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
118 desc
=> "catch device by *",
119 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
120 exp_name
=> "modem/0" ,
122 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
126 desc
=> "catch device by * - take 2",
127 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
128 exp_name
=> "modem/0" ,
130 KERNEL=="*ACM1", SYMLINK+="bad"
131 KERNEL=="*ACM0", SYMLINK+="modem/%n"
135 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",
146 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
147 exp_name
=> "modem/0" ,
149 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
150 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
151 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
155 desc
=> "replace kernel name",
156 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
157 exp_name
=> "modem" ,
159 KERNEL=="ttyACM0", SYMLINK+="modem"
163 desc
=> "Handle comment lines in config file (and replace kernel name)",
164 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
165 exp_name
=> "modem" ,
168 KERNEL=="ttyACM0", SYMLINK+="modem"
173 desc
=> "Handle comment lines in config file with whitespace (and replace kernel name)",
174 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
175 exp_name
=> "modem" ,
177 # this is a comment with whitespace before the comment
178 KERNEL=="ttyACM0", SYMLINK+="modem"
183 desc
=> "Handle whitespace only lines (and replace kernel name)",
184 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
185 exp_name
=> "whitespace" ,
190 # this is a comment with whitespace before the comment
191 KERNEL=="ttyACM0", SYMLINK+="whitespace"
198 desc
=> "Handle empty lines in config file (and replace kernel name)",
199 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
200 exp_name
=> "modem" ,
203 KERNEL=="ttyACM0", SYMLINK+="modem"
208 desc
=> "Handle backslashed multi lines in config file (and replace kernel name)",
209 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
210 exp_name
=> "modem" ,
212 KERNEL=="ttyACM0", \\
218 desc
=> "preserve backslashes, if they are not for a newline",
219 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
222 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
226 desc
=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
227 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
228 exp_name
=> "modem" ,
238 KERNEL=="ttyACM0", \\
244 desc
=> "subdirectory handling",
245 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
246 exp_name
=> "sub/direct/ory/modem" ,
248 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
252 desc
=> "parent device name match of scsi partition",
253 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
254 exp_name
=> "first_disk5" ,
256 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
260 desc
=> "test substitution chars",
261 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
262 exp_name
=> "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
264 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
268 desc
=> "import of shell-value returned from program",
269 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
270 exp_name
=> "node12345678",
272 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
273 KERNEL=="ttyACM0", SYMLINK+="modem"
277 desc
=> "sustitution of sysfs value (%s{file})",
278 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
279 exp_name
=> "disk-ATA-sda" ,
281 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
282 KERNEL=="ttyACM0", SYMLINK+="modem"
286 desc
=> "program result substitution",
287 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
288 exp_name
=> "special-device-5" ,
289 not_exp_name
=> "not" ,
291 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
292 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
296 desc
=> "program result substitution (newline removal)",
297 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
298 exp_name
=> "newline_removed" ,
300 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
304 desc
=> "program result substitution",
305 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
306 exp_name
=> "test-0:0:0:0" ,
308 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
312 desc
=> "program with lots of arguments",
313 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
316 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
320 desc
=> "program with subshell",
321 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
324 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
328 desc
=> "program arguments combined with apostrophes",
329 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
332 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
336 desc
=> "program arguments combined with escaped double quotes, part 1",
337 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
340 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
344 desc
=> "program arguments combined with escaped double quotes, part 2",
345 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
348 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}"
352 desc
=> "program arguments combined with escaped double quotes, part 3",
353 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
356 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
360 desc
=> "characters before the %c{N} substitution",
361 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
362 exp_name
=> "my-foo9" ,
364 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
368 desc
=> "substitute the second to last argument",
369 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
370 exp_name
=> "my-foo8" ,
372 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
376 desc
=> "test substitution by variable name",
377 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
378 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
380 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
384 desc
=> "test substitution by variable name 2",
385 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
386 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
388 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
392 desc
=> "test substitution by variable name 3",
393 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
394 exp_name
=> "850:0:0:05" ,
396 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
400 desc
=> "test substitution by variable name 4",
401 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
404 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
408 desc
=> "test substitution by variable name 5",
409 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
410 exp_name
=> "8550:0:0:0" ,
412 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
416 desc
=> "non matching SUBSYSTEMS for device with no parent",
417 devpath
=> "/devices/virtual/tty/console",
420 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
421 KERNEL=="console", SYMLINK+="TTY"
425 desc
=> "non matching SUBSYSTEMS",
426 devpath
=> "/devices/virtual/tty/console",
429 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
430 KERNEL=="console", SYMLINK+="TTY"
434 desc
=> "ATTRS match",
435 devpath
=> "/devices/virtual/tty/console",
438 KERNEL=="console", SYMLINK+="TTY"
439 ATTRS{dev}=="5:1", SYMLINK+="foo"
443 desc
=> "ATTR (empty file)",
444 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
445 exp_name
=> "empty" ,
447 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
448 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
449 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
450 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
454 desc
=> "ATTR (non-existent file)",
455 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
456 exp_name
=> "non-existent" ,
458 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
459 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
460 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
461 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
462 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
463 KERNEL=="sda", SYMLINK+="wrong"
467 desc
=> "program and bus type match",
468 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
469 exp_name
=> "scsi-0:0:0:0" ,
471 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
472 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
473 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
477 desc
=> "sysfs parent hierarchy",
478 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
479 exp_name
=> "modem" ,
481 ATTRS{idProduct}=="007b", SYMLINK+="modem"
485 desc
=> "name test with ! in the name",
486 devpath
=> "/devices/virtual/block/fake!blockdev0",
487 exp_name
=> "is/a/fake/blockdev0" ,
489 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
490 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
491 KERNEL=="ttyACM0", SYMLINK+="modem"
495 desc
=> "name test with ! in the name, but no matching rule",
496 devpath
=> "/devices/virtual/block/fake!blockdev0",
497 exp_name
=> "fake/blockdev0" ,
498 exp_rem_error
=> "yes",
500 KERNEL=="ttyACM0", SYMLINK+="modem"
504 desc
=> "KERNELS rule",
505 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
506 exp_name
=> "scsi-0:0:0:0",
508 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
509 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
510 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
511 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
512 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
516 desc
=> "KERNELS wildcard all",
517 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
518 exp_name
=> "scsi-0:0:0:0",
520 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
521 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
522 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
523 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
524 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
528 desc
=> "KERNELS wildcard partial",
529 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
530 exp_name
=> "scsi-0:0:0:0",
532 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
533 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
537 desc
=> "KERNELS wildcard partial 2",
538 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
539 exp_name
=> "scsi-0:0:0:0",
541 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
542 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
546 desc
=> "substitute attr with link target value (first match)",
547 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
548 exp_name
=> "driver-is-sd",
550 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
554 desc
=> "substitute attr with link target value (currently selected device)",
555 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
556 exp_name
=> "driver-is-ahci",
558 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
562 desc
=> "ignore ATTRS attribute whitespace",
563 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
564 exp_name
=> "ignored",
566 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
570 desc
=> "do not ignore ATTRS attribute whitespace",
571 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
572 exp_name
=> "matched-with-space",
574 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
575 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
579 desc
=> "permissions USER=bad GROUP=name",
580 devpath
=> "/devices/virtual/tty/tty33",
582 exp_perms
=> "0:0:0600",
584 KERNEL=="tty33", OWNER="bad", GROUP="name"
588 desc
=> "permissions OWNER=1",
589 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
591 exp_perms
=> "1::0600",
593 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
597 desc
=> "permissions GROUP=1",
598 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
600 exp_perms
=> ":1:0660",
602 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
606 desc
=> "textual user id",
607 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
609 exp_perms
=> "nobody::0600",
611 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
615 desc
=> "textual group id",
616 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
618 exp_perms
=> ":daemon:0660",
620 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
624 desc
=> "textual user/group id",
625 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
627 exp_perms
=> "root:mail:0660",
629 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
633 desc
=> "permissions MODE=0777",
634 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
636 exp_perms
=> "::0777",
638 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
642 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
643 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
645 exp_perms
=> "1:1:0777",
647 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
651 desc
=> "permissions OWNER to 1",
652 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
653 exp_name
=> "ttyACM0",
656 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
660 desc
=> "permissions GROUP to 1",
661 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
662 exp_name
=> "ttyACM0",
663 exp_perms
=> ":1:0660",
665 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
669 desc
=> "permissions MODE to 0060",
670 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
671 exp_name
=> "ttyACM0",
672 exp_perms
=> "::0060",
674 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
678 desc
=> "permissions OWNER, GROUP, MODE",
679 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
680 exp_name
=> "ttyACM0",
681 exp_perms
=> "1:1:0777",
683 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
687 desc
=> "permissions only rule",
688 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
689 exp_name
=> "ttyACM0",
690 exp_perms
=> "1:1:0777",
692 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
693 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
694 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
698 desc
=> "multiple permissions only rule",
699 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
700 exp_name
=> "ttyACM0",
701 exp_perms
=> "1:1:0777",
703 SUBSYSTEM=="tty", OWNER="1"
704 SUBSYSTEM=="tty", GROUP="1"
705 SUBSYSTEM=="tty", MODE="0777"
706 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
707 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
711 desc
=> "permissions only rule with override at SYMLINK+ rule",
712 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
713 exp_name
=> "ttyACM0",
714 exp_perms
=> "1:2:0777",
716 SUBSYSTEM=="tty", OWNER="1"
717 SUBSYSTEM=="tty", GROUP="1"
718 SUBSYSTEM=="tty", MODE="0777"
719 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
720 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
724 desc
=> "major/minor number test",
725 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
727 exp_majorminor
=> "8:0",
729 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
733 desc
=> "big major number test",
734 devpath
=> "/devices/virtual/misc/misc-fake1",
736 exp_majorminor
=> "4095:1",
738 KERNEL=="misc-fake1", SYMLINK+="node"
742 desc
=> "big major and big minor number test",
743 devpath
=> "/devices/virtual/misc/misc-fake89999",
745 exp_majorminor
=> "4095:89999",
747 KERNEL=="misc-fake89999", SYMLINK+="node"
751 desc
=> "multiple symlinks with format char",
752 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
753 exp_name
=> "symlink2-ttyACM0",
755 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
759 desc
=> "multiple symlinks with a lot of s p a c e s",
760 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
764 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
768 desc
=> "symlink with spaces in substituted variable",
769 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
770 exp_name
=> "name-one_two_three-end",
773 ENV{WITH_WS}="one two three"
774 SYMLINK="name-\$env{WITH_WS}-end"
778 desc
=> "symlink with leading space in substituted variable",
779 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
780 exp_name
=> "name-one_two_three-end",
783 ENV{WITH_WS}=" one two three"
784 SYMLINK="name-\$env{WITH_WS}-end"
788 desc
=> "symlink with trailing space in substituted variable",
789 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
790 exp_name
=> "name-one_two_three-end",
793 ENV{WITH_WS}="one two three "
794 SYMLINK="name-\$env{WITH_WS}-end"
798 desc
=> "symlink with lots of space in substituted variable",
799 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
800 exp_name
=> "name-one_two_three-end",
803 ENV{WITH_WS}=" one two three "
804 SYMLINK="name-\$env{WITH_WS}-end"
808 desc
=> "symlink with multiple spaces in substituted variable",
809 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
810 exp_name
=> "name-one_two_three-end",
813 ENV{WITH_WS}=" one two three "
814 SYMLINK="name-\$env{WITH_WS}-end"
818 desc
=> "symlink with space and var with space, part 1",
819 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
823 ENV{WITH_WS}=" one two three "
824 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
828 desc
=> "symlink with space and var with space, part 2",
829 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
830 exp_name
=> "name-one_two_three-end",
833 ENV{WITH_WS}=" one two three "
834 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
838 desc
=> "symlink with space and var with space, part 3",
839 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
840 exp_name
=> "another_symlink",
843 ENV{WITH_WS}=" one two three "
844 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
848 desc
=> "symlink creation (same directory)",
849 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
850 exp_name
=> "modem0",
852 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
856 desc
=> "multiple symlinks",
857 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
858 exp_name
=> "second-0" ,
860 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
864 desc
=> "symlink name '.'",
865 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
867 exp_add_error
=> "yes",
868 exp_rem_error
=> "yes",
870 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
874 desc
=> "symlink node to itself",
875 devpath
=> "/devices/virtual/tty/tty0",
877 exp_add_error
=> "yes",
878 exp_rem_error
=> "yes",
881 KERNEL=="tty0", SYMLINK+="tty0"
885 desc
=> "symlink %n substitution",
886 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
887 exp_name
=> "symlink0",
889 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
893 desc
=> "symlink %k substitution",
894 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
895 exp_name
=> "symlink-ttyACM0",
897 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
901 desc
=> "symlink %M:%m substitution",
902 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
903 exp_name
=> "major-166:0",
905 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
909 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",
913 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
917 desc
=> "symlink %c substitution",
918 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
921 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
925 desc
=> "symlink %c{N} substitution",
926 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
929 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
933 desc
=> "symlink %c{N+} substitution",
934 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
937 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
941 desc
=> "symlink only rule with %c{N+}",
942 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
945 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
949 desc
=> "symlink %s{filename} substitution",
950 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
953 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
957 desc
=> "program result substitution (numbered part of)",
958 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
961 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
965 desc
=> "program result substitution (numbered part of+)",
966 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
969 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
973 desc
=> "SUBSYSTEM match test",
974 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
977 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
978 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
979 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
983 desc
=> "DRIVERS match test",
984 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
987 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
988 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
992 desc
=> "devnode substitution 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", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1000 desc
=> "parent node name substitution test",
1001 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1002 exp_name
=> "sda-part-1",
1004 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1008 desc
=> "udev_root substitution",
1009 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1010 exp_name
=> "start-/dev-end",
1012 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1016 desc
=> "last_rule option",
1017 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1020 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1021 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1025 desc
=> "negation KERNEL!=",
1026 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1027 exp_name
=> "match",
1029 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1030 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1031 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1035 desc
=> "negation SUBSYSTEM!=",
1036 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1037 exp_name
=> "not-anything",
1039 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1040 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1041 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1045 desc
=> "negation PROGRAM!= exit code",
1046 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1047 exp_name
=> "nonzero-program",
1049 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1050 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1054 desc
=> "ENV{} test",
1055 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1058 ENV{ENV_KEY_TEST}="test"
1059 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1060 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1061 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1065 desc
=> "ENV{} test",
1066 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1069 ENV{ENV_KEY_TEST}="test"
1070 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1071 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1072 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1073 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1077 desc
=> "ENV{} test (assign)",
1078 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1081 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1082 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1083 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1084 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1088 desc
=> "ENV{} test (assign 2 times)",
1089 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1092 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1093 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1094 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1095 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1096 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1100 desc
=> "ENV{} test (assign2)",
1101 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1104 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1105 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1106 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1107 SUBSYSTEM=="block", SYMLINK+="before"
1108 ENV{PARTITION}=="true", SYMLINK+="part"
1112 desc
=> "untrusted string sanitize",
1113 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1116 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1120 desc
=> "untrusted string sanitize (don't replace utf8)",
1121 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1124 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1128 desc
=> "untrusted string sanitize (replace invalid utf8)",
1129 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1130 exp_name
=> "replaced",
1132 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1136 desc
=> "read sysfs value from parent device",
1137 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1138 exp_name
=> "serial-354172020305000",
1140 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1144 desc
=> "match against empty key string",
1145 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1148 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1149 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1150 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1151 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1155 desc
=> "check ACTION value",
1156 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1159 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1160 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1164 desc
=> "final assignment",
1165 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1167 exp_perms
=> "root:tty:0640",
1169 KERNEL=="sda", GROUP:="tty"
1170 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1174 desc
=> "final assignment 2",
1175 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1177 exp_perms
=> "root:tty:0640",
1179 KERNEL=="sda", GROUP:="tty"
1180 SUBSYSTEM=="block", MODE:="640"
1181 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1185 desc
=> "env substitution",
1186 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1187 exp_name
=> "node-add-me",
1189 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1193 desc
=> "reset list to current value",
1194 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1195 exp_name
=> "three",
1196 not_exp_name
=> "two",
1198 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1199 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1200 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1204 desc
=> "test empty SYMLINK+ (empty override)",
1205 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1206 exp_name
=> "right",
1207 not_exp_name
=> "wrong",
1209 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1210 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1211 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1215 desc
=> "test multi matches",
1216 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1217 exp_name
=> "right",
1219 KERNEL=="ttyACM*", SYMLINK+="before"
1220 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1224 desc
=> "test multi matches 2",
1225 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1226 exp_name
=> "right",
1228 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1229 KERNEL=="ttyACM*", SYMLINK+="before"
1230 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1234 desc
=> "test multi matches 3",
1235 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1236 exp_name
=> "right",
1238 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1239 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1240 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1241 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1245 desc
=> "test multi matches 4",
1246 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1247 exp_name
=> "right",
1249 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1250 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1251 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1252 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1253 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1257 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1258 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1259 exp_name
=> "parent",
1262 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1263 KERNEL=="sda", SYMLINK+="parent"
1267 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1268 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1269 exp_name
=> "parentenv-parent_right",
1272 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1276 desc
=> "GOTO test",
1277 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1278 exp_name
=> "right",
1280 KERNEL=="sda1", GOTO="TEST"
1281 KERNEL=="sda1", SYMLINK+="wrong"
1282 KERNEL=="sda1", GOTO="BAD"
1283 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1284 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1285 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1290 desc
=> "GOTO label does not exist",
1291 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1292 exp_name
=> "right",
1294 KERNEL=="sda1", GOTO="does-not-exist"
1295 KERNEL=="sda1", SYMLINK+="right",
1300 desc
=> "SYMLINK+ compare test",
1301 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1302 exp_name
=> "right",
1303 not_exp_name
=> "wrong",
1305 KERNEL=="sda1", SYMLINK+="link"
1306 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1307 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1311 desc
=> "invalid key operation",
1312 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1315 KERNEL="sda1", SYMLINK+="no"
1316 KERNEL=="sda1", SYMLINK+="yes"
1320 desc
=> "operator chars in attribute",
1321 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1324 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1328 desc
=> "overlong comment line",
1329 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1332 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1333 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1334 KERNEL=="sda1", SYMLINK+=="no"
1335 KERNEL=="sda1", SYMLINK+="yes"
1339 desc
=> "magic subsys/kernel lookup",
1340 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1341 exp_name
=> "00:16:41:e2:8d:ff",
1343 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1347 desc
=> "TEST absolute path",
1348 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1349 exp_name
=> "there",
1351 TEST=="/etc/machine-id", SYMLINK+="there"
1352 TEST!="/etc/machine-id", SYMLINK+="notthere"
1356 desc
=> "TEST subsys/kernel lookup",
1357 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1360 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1364 desc
=> "TEST relative path",
1365 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1366 exp_name
=> "relative",
1368 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1372 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1373 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1374 exp_name
=> "found-subdir",
1376 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1380 desc
=> "TEST MODE=0000",
1381 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1383 exp_perms
=> "0:0:0000",
1384 exp_rem_error
=> "yes",
1386 KERNEL=="sda", MODE="0000"
1390 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1391 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1393 exp_perms
=> "1:1:0400",
1394 exp_rem_error
=> "yes",
1396 KERNEL=="sda", MODE="666"
1397 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1401 desc
=> "TEST PROGRAM feeds MODE with overflow",
1402 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1404 exp_perms
=> "0:0:0440",
1405 exp_rem_error
=> "yes",
1407 KERNEL=="sda", MODE="440"
1408 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1412 desc
=> "magic [subsys/sysname] attribute substitution",
1413 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1414 exp_name
=> "sda-8741C4G-end",
1415 exp_perms
=> "0:0:0600",
1417 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1418 KERNEL=="sda", ENV{TESTENV}="change-envp"
1419 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1423 desc
=> "builtin path_id",
1424 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1425 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1427 KERNEL=="sda", IMPORT{builtin}="path_id"
1428 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1432 desc
=> "add and match tag",
1433 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1434 exp_name
=> "found",
1435 not_exp_name
=> "bad" ,
1437 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1438 TAGS=="green", SYMLINK+="found"
1439 TAGS=="blue", SYMLINK+="bad"
1443 desc
=> "don't crash with lots of tags",
1444 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1445 exp_name
=> "found",
1446 rules
=> $rules_10k_tags . <<EOF
1447 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
1453 my ($action, $devpath, $rules) = @_;
1455 # create temporary rules
1456 system("mkdir", "-p", "$udev_rules_dir");
1457 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1461 if ($valgrind > 0) {
1462 return system("$udev_bin_valgrind $action $devpath");
1463 } elsif ($gdb > 0) {
1464 return system("$udev_bin_gdb $action $devpath");
1465 } elsif ($strace > 0) {
1466 return system("$udev_bin_strace $action $devpath");
1468 return system("$udev_bin", "$action", "$devpath");
1474 sub permissions_test
{
1475 my($rules, $uid, $gid, $mode) = @_;
1481 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1483 if (defined(getpwnam($1))) {
1484 $userid = int(getpwnam($1));
1488 if ($uid != $userid) { $wrong = 1; }
1491 if (defined(getgrnam($2))) {
1492 $groupid = int(getgrnam($2));
1496 if ($gid != $groupid) { $wrong = 1; }
1499 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1502 print "permissions: ok\n";
1504 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1505 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1506 print "permissions: error\n";
1512 sub major_minor_test
{
1513 my($rules, $rdev) = @_;
1515 my $major = ($rdev >> 8) & 0xfff;
1516 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1519 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1521 if ($major != $1) { $wrong = 1; };
1524 if ($minor != $2) { $wrong = 1; };
1527 print "major:minor: ok\n";
1529 printf " expected major:minor is: %i:%i\n", $1, $2;
1530 printf " created major:minor is : %i:%i\n", $major, $minor;
1531 print "major:minor: error\n";
1538 system("umount", $udev_tmpfs);
1540 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
1541 system("mount", "-o", "rw,mode=755,nosuid,noexec,nodev", "-t", "tmpfs", "tmpfs", $udev_tmpfs) && die "unable to mount tmpfs";
1543 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1544 # setting group and mode of udev_dev ensures the tests work
1545 # even if the parent directory has setgid bit enabled.
1546 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1547 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1549 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
1551 system("rm", "-rf", "$udev_run");
1555 my ($rules, $number) = @_;
1558 print "TEST $number: $rules->{desc}\n";
1559 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1561 $rc = udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1563 print "$udev_bin add failed with code $rc\n";
1566 if (defined($rules->{not_exp_name
})) {
1567 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1568 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1569 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1575 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1576 (-l
"$udev_dev/$rules->{exp_name}")) {
1578 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1579 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1581 if (defined($rules->{exp_perms
})) {
1582 permissions_test
($rules, $uid, $gid, $mode);
1584 if (defined($rules->{exp_majorminor
})) {
1585 major_minor_test
($rules, $rdev);
1590 if ($rules->{exp_add_error
}) {
1591 print " as expected\n";
1594 system("tree", "$udev_dev");
1601 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1606 $rc = udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1608 print "$udev_bin remove failed with code $rc\n";
1611 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1612 (-l
"$udev_dev/$rules->{exp_name}")) {
1613 print "remove: error";
1614 if ($rules->{exp_rem_error
}) {
1615 print " as expected\n";
1618 system("tree", "$udev_dev");
1624 print "remove: ok\n";
1629 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1635 # only run if we have root permissions
1636 # due to mknod restrictions
1638 print "Must have root permissions to run properly.\n";
1639 exit($EXIT_TEST_SKIP);
1642 # skip the test when running in a chroot
1643 system("systemd-detect-virt", "-r", "-q");
1645 print "Running in a chroot, skipping the test.\n";
1646 exit($EXIT_TEST_SKIP);
1649 # skip the test when running in a container
1650 system("systemd-detect-virt", "-c", "-q");
1652 print "Running in a container, skipping the test.\n";
1653 exit($EXIT_TEST_SKIP);
1661 foreach my $arg (@ARGV) {
1662 if ($arg =~ m/--valgrind/) {
1664 printf("using valgrind\n");
1665 } elsif ($arg =~ m/--gdb/) {
1667 printf("using gdb\n");
1668 } elsif ($arg =~ m/--strace/) {
1670 printf("using strace\n");
1677 foreach my $arg (@list) {
1678 if (defined($tests[$arg-1]->{desc
})) {
1679 print "udev-test will run test number $arg:\n\n";
1680 run_test
($tests[$arg-1], $arg);
1682 print "test does not exist.\n";
1687 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1689 foreach my $rules (@tests) {
1690 run_test
($rules, $test_num);
1695 print "$error errors occurred\n\n";
1698 system("rm", "-rf", "$udev_run");
1699 system("umount", "$udev_tmpfs");