]>
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
=> "characters before the %c{N} substitution",
337 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
338 exp_name
=> "my-foo9" ,
340 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
344 desc
=> "substitute the second to last argument",
345 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
346 exp_name
=> "my-foo8" ,
348 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
352 desc
=> "test substitution by variable name",
353 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
354 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
356 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
360 desc
=> "test substitution by variable name 2",
361 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
362 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
364 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
368 desc
=> "test substitution by variable name 3",
369 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
370 exp_name
=> "850:0:0:05" ,
372 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
376 desc
=> "test substitution by variable name 4",
377 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
380 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
384 desc
=> "test substitution by variable name 5",
385 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
386 exp_name
=> "8550:0:0:0" ,
388 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
392 desc
=> "non matching SUBSYSTEMS for device with no parent",
393 devpath
=> "/devices/virtual/tty/console",
396 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
397 KERNEL=="console", SYMLINK+="TTY"
401 desc
=> "non matching SUBSYSTEMS",
402 devpath
=> "/devices/virtual/tty/console",
405 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
406 KERNEL=="console", SYMLINK+="TTY"
410 desc
=> "ATTRS match",
411 devpath
=> "/devices/virtual/tty/console",
414 KERNEL=="console", SYMLINK+="TTY"
415 ATTRS{dev}=="5:1", SYMLINK+="foo"
419 desc
=> "ATTR (empty file)",
420 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
421 exp_name
=> "empty" ,
423 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
424 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
425 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
426 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
430 desc
=> "ATTR (non-existent file)",
431 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
432 exp_name
=> "non-existent" ,
434 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
435 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
436 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
437 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
438 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
439 KERNEL=="sda", SYMLINK+="wrong"
443 desc
=> "program and bus type match",
444 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
445 exp_name
=> "scsi-0:0:0:0" ,
447 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
448 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
449 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
453 desc
=> "sysfs parent hierarchy",
454 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
455 exp_name
=> "modem" ,
457 ATTRS{idProduct}=="007b", SYMLINK+="modem"
461 desc
=> "name test with ! in the name",
462 devpath
=> "/devices/virtual/block/fake!blockdev0",
463 exp_name
=> "is/a/fake/blockdev0" ,
465 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
466 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
467 KERNEL=="ttyACM0", SYMLINK+="modem"
471 desc
=> "name test with ! in the name, but no matching rule",
472 devpath
=> "/devices/virtual/block/fake!blockdev0",
473 exp_name
=> "fake/blockdev0" ,
474 exp_rem_error
=> "yes",
476 KERNEL=="ttyACM0", SYMLINK+="modem"
480 desc
=> "KERNELS rule",
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=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
485 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
486 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
487 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
488 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
492 desc
=> "KERNELS wildcard all",
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=="*:1", SYMLINK+="no-match"
497 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
498 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
499 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
500 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
504 desc
=> "KERNELS wildcard partial",
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=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
509 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
513 desc
=> "KERNELS wildcard partial 2",
514 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
515 exp_name
=> "scsi-0:0:0:0",
517 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
518 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
522 desc
=> "substitute attr with link target value (first match)",
523 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
524 exp_name
=> "driver-is-sd",
526 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
530 desc
=> "substitute attr with link target value (currently selected device)",
531 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
532 exp_name
=> "driver-is-ahci",
534 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
538 desc
=> "ignore ATTRS attribute whitespace",
539 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
540 exp_name
=> "ignored",
542 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
546 desc
=> "do not ignore ATTRS attribute whitespace",
547 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
548 exp_name
=> "matched-with-space",
550 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
551 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
555 desc
=> "permissions USER=bad GROUP=name",
556 devpath
=> "/devices/virtual/tty/tty33",
558 exp_perms
=> "0:0:0600",
560 KERNEL=="tty33", OWNER="bad", GROUP="name"
564 desc
=> "permissions OWNER=1",
565 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
567 exp_perms
=> "1::0600",
569 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
573 desc
=> "permissions GROUP=1",
574 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
576 exp_perms
=> ":1:0660",
578 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
582 desc
=> "textual user id",
583 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
585 exp_perms
=> "nobody::0600",
587 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
591 desc
=> "textual group id",
592 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
594 exp_perms
=> ":daemon:0660",
596 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
600 desc
=> "textual user/group id",
601 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
603 exp_perms
=> "root:mail:0660",
605 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
609 desc
=> "permissions MODE=0777",
610 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
612 exp_perms
=> "::0777",
614 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
618 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
619 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
621 exp_perms
=> "1:1:0777",
623 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
627 desc
=> "permissions OWNER to 1",
628 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
629 exp_name
=> "ttyACM0",
632 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
636 desc
=> "permissions GROUP to 1",
637 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
638 exp_name
=> "ttyACM0",
639 exp_perms
=> ":1:0660",
641 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
645 desc
=> "permissions MODE to 0060",
646 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
647 exp_name
=> "ttyACM0",
648 exp_perms
=> "::0060",
650 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
654 desc
=> "permissions OWNER, GROUP, MODE",
655 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
656 exp_name
=> "ttyACM0",
657 exp_perms
=> "1:1:0777",
659 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
663 desc
=> "permissions only rule",
664 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
665 exp_name
=> "ttyACM0",
666 exp_perms
=> "1:1:0777",
668 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
669 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
670 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
674 desc
=> "multiple permissions only rule",
675 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
676 exp_name
=> "ttyACM0",
677 exp_perms
=> "1:1:0777",
679 SUBSYSTEM=="tty", OWNER="1"
680 SUBSYSTEM=="tty", GROUP="1"
681 SUBSYSTEM=="tty", MODE="0777"
682 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
683 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
687 desc
=> "permissions only rule with override at SYMLINK+ 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:2:0777",
692 SUBSYSTEM=="tty", OWNER="1"
693 SUBSYSTEM=="tty", GROUP="1"
694 SUBSYSTEM=="tty", MODE="0777"
695 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
696 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
700 desc
=> "major/minor number test",
701 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
703 exp_majorminor
=> "8:0",
705 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
709 desc
=> "big major number test",
710 devpath
=> "/devices/virtual/misc/misc-fake1",
712 exp_majorminor
=> "4095:1",
714 KERNEL=="misc-fake1", SYMLINK+="node"
718 desc
=> "big major and big minor number test",
719 devpath
=> "/devices/virtual/misc/misc-fake89999",
721 exp_majorminor
=> "4095:89999",
723 KERNEL=="misc-fake89999", SYMLINK+="node"
727 desc
=> "multiple symlinks with format char",
728 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
729 exp_name
=> "symlink2-ttyACM0",
731 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
735 desc
=> "multiple symlinks with a lot of s p a c e s",
736 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
740 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
744 desc
=> "symlink with spaces in substituted variable",
745 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
746 exp_name
=> "name-one_two_three-end",
749 ENV{WITH_WS}="one two three"
750 SYMLINK="name-\$env{WITH_WS}-end"
754 desc
=> "symlink with leading space in substituted variable",
755 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
756 exp_name
=> "name-one_two_three-end",
759 ENV{WITH_WS}=" one two three"
760 SYMLINK="name-\$env{WITH_WS}-end"
764 desc
=> "symlink with trailing space in substituted variable",
765 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
766 exp_name
=> "name-one_two_three-end",
769 ENV{WITH_WS}="one two three "
770 SYMLINK="name-\$env{WITH_WS}-end"
774 desc
=> "symlink with lots of space in substituted variable",
775 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
776 exp_name
=> "name-one_two_three-end",
779 ENV{WITH_WS}=" one two three "
780 SYMLINK="name-\$env{WITH_WS}-end"
784 desc
=> "symlink with multiple spaces in substituted variable",
785 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
786 exp_name
=> "name-one_two_three-end",
789 ENV{WITH_WS}=" one two three "
790 SYMLINK="name-\$env{WITH_WS}-end"
794 desc
=> "symlink with space and var with space, part 1",
795 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
799 ENV{WITH_WS}=" one two three "
800 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
804 desc
=> "symlink with space and var with space, part 2",
805 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
806 exp_name
=> "name-one_two_three-end",
809 ENV{WITH_WS}=" one two three "
810 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
814 desc
=> "symlink with space and var with space, part 3",
815 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
816 exp_name
=> "another_symlink",
819 ENV{WITH_WS}=" one two three "
820 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
824 desc
=> "symlink creation (same directory)",
825 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
826 exp_name
=> "modem0",
828 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
832 desc
=> "multiple symlinks",
833 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
834 exp_name
=> "second-0" ,
836 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
840 desc
=> "symlink name '.'",
841 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
843 exp_add_error
=> "yes",
844 exp_rem_error
=> "yes",
846 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
850 desc
=> "symlink node to itself",
851 devpath
=> "/devices/virtual/tty/tty0",
853 exp_add_error
=> "yes",
854 exp_rem_error
=> "yes",
857 KERNEL=="tty0", SYMLINK+="tty0"
861 desc
=> "symlink %n substitution",
862 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
863 exp_name
=> "symlink0",
865 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
869 desc
=> "symlink %k substitution",
870 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
871 exp_name
=> "symlink-ttyACM0",
873 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
877 desc
=> "symlink %M:%m substitution",
878 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
879 exp_name
=> "major-166:0",
881 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
885 desc
=> "symlink %b substitution",
886 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
887 exp_name
=> "symlink-0:0:0:0",
889 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
893 desc
=> "symlink %c substitution",
894 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
897 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
901 desc
=> "symlink %c{N} substitution",
902 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
905 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
909 desc
=> "symlink %c{N+} substitution",
910 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
913 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
917 desc
=> "symlink only rule with %c{N+}",
918 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
921 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
925 desc
=> "symlink %s{filename} substitution",
926 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
929 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
933 desc
=> "program result substitution (numbered part of)",
934 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
937 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
941 desc
=> "program result substitution (numbered part of+)",
942 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
945 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
949 desc
=> "SUBSYSTEM match test",
950 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
953 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
954 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
955 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
959 desc
=> "DRIVERS match test",
960 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
963 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
964 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
968 desc
=> "devnode substitution test",
969 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
972 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
976 desc
=> "parent node name substitution test",
977 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
978 exp_name
=> "sda-part-1",
980 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
984 desc
=> "udev_root substitution",
985 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
986 exp_name
=> "start-/dev-end",
988 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
992 desc
=> "last_rule option",
993 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
996 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
997 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1001 desc
=> "negation KERNEL!=",
1002 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1003 exp_name
=> "match",
1005 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1006 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1007 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1011 desc
=> "negation SUBSYSTEM!=",
1012 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1013 exp_name
=> "not-anything",
1015 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1016 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1017 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1021 desc
=> "negation PROGRAM!= exit code",
1022 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1023 exp_name
=> "nonzero-program",
1025 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1026 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1030 desc
=> "ENV{} test",
1031 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1034 ENV{ENV_KEY_TEST}="test"
1035 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1036 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1037 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1041 desc
=> "ENV{} test",
1042 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1045 ENV{ENV_KEY_TEST}="test"
1046 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1047 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1048 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1049 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1053 desc
=> "ENV{} test (assign)",
1054 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1057 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1058 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1059 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1060 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1064 desc
=> "ENV{} test (assign 2 times)",
1065 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1068 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1069 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1070 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1071 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1072 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1076 desc
=> "ENV{} test (assign2)",
1077 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1080 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1081 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1082 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1083 SUBSYSTEM=="block", SYMLINK+="before"
1084 ENV{PARTITION}=="true", SYMLINK+="part"
1088 desc
=> "untrusted string sanitize",
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", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1096 desc
=> "untrusted string sanitize (don't replace utf8)",
1097 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1100 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1104 desc
=> "untrusted string sanitize (replace invalid utf8)",
1105 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1106 exp_name
=> "replaced",
1108 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1112 desc
=> "read sysfs value from parent device",
1113 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1114 exp_name
=> "serial-354172020305000",
1116 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1120 desc
=> "match against empty key string",
1121 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1124 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1125 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1126 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1127 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1131 desc
=> "check ACTION value",
1132 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1135 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1136 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1140 desc
=> "final assignment",
1141 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1143 exp_perms
=> "root:tty:0640",
1145 KERNEL=="sda", GROUP:="tty"
1146 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1150 desc
=> "final assignment 2",
1151 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1153 exp_perms
=> "root:tty:0640",
1155 KERNEL=="sda", GROUP:="tty"
1156 SUBSYSTEM=="block", MODE:="640"
1157 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1161 desc
=> "env substitution",
1162 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1163 exp_name
=> "node-add-me",
1165 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1169 desc
=> "reset list to current value",
1170 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1171 exp_name
=> "three",
1172 not_exp_name
=> "two",
1174 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1175 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1176 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1180 desc
=> "test empty SYMLINK+ (empty override)",
1181 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1182 exp_name
=> "right",
1183 not_exp_name
=> "wrong",
1185 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1186 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1187 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1191 desc
=> "test multi matches",
1192 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1193 exp_name
=> "right",
1195 KERNEL=="ttyACM*", SYMLINK+="before"
1196 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1200 desc
=> "test multi matches 2",
1201 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1202 exp_name
=> "right",
1204 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1205 KERNEL=="ttyACM*", SYMLINK+="before"
1206 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1210 desc
=> "test multi matches 3",
1211 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1212 exp_name
=> "right",
1214 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1215 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1216 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1217 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1221 desc
=> "test multi matches 4",
1222 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1223 exp_name
=> "right",
1225 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1226 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1227 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1228 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1229 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1233 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1234 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1235 exp_name
=> "parent",
1238 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1239 KERNEL=="sda", SYMLINK+="parent"
1243 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1244 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1245 exp_name
=> "parentenv-parent_right",
1248 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1252 desc
=> "GOTO test",
1253 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1254 exp_name
=> "right",
1256 KERNEL=="sda1", GOTO="TEST"
1257 KERNEL=="sda1", SYMLINK+="wrong"
1258 KERNEL=="sda1", GOTO="BAD"
1259 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1260 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1261 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1266 desc
=> "GOTO label does not exist",
1267 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1268 exp_name
=> "right",
1270 KERNEL=="sda1", GOTO="does-not-exist"
1271 KERNEL=="sda1", SYMLINK+="right",
1276 desc
=> "SYMLINK+ compare 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",
1279 not_exp_name
=> "wrong",
1281 KERNEL=="sda1", SYMLINK+="link"
1282 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1283 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1287 desc
=> "invalid key operation",
1288 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1291 KERNEL="sda1", SYMLINK+="no"
1292 KERNEL=="sda1", SYMLINK+="yes"
1296 desc
=> "operator chars in attribute",
1297 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1300 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1304 desc
=> "overlong comment line",
1305 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1308 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1309 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1310 KERNEL=="sda1", SYMLINK+=="no"
1311 KERNEL=="sda1", SYMLINK+="yes"
1315 desc
=> "magic subsys/kernel lookup",
1316 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1317 exp_name
=> "00:16:41:e2:8d:ff",
1319 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1323 desc
=> "TEST absolute path",
1324 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1325 exp_name
=> "there",
1327 TEST=="/etc/machine-id", SYMLINK+="there"
1328 TEST!="/etc/machine-id", SYMLINK+="notthere"
1332 desc
=> "TEST subsys/kernel lookup",
1333 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1336 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1340 desc
=> "TEST relative path",
1341 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1342 exp_name
=> "relative",
1344 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1348 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1349 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1350 exp_name
=> "found-subdir",
1352 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1356 desc
=> "TEST MODE=0000",
1357 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1359 exp_perms
=> "0:0:0000",
1360 exp_rem_error
=> "yes",
1362 KERNEL=="sda", MODE="0000"
1366 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1367 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1369 exp_perms
=> "1:1:0400",
1370 exp_rem_error
=> "yes",
1372 KERNEL=="sda", MODE="666"
1373 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1377 desc
=> "TEST PROGRAM feeds MODE with overflow",
1378 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1380 exp_perms
=> "0:0:0440",
1381 exp_rem_error
=> "yes",
1383 KERNEL=="sda", MODE="440"
1384 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1388 desc
=> "magic [subsys/sysname] attribute substitution",
1389 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1390 exp_name
=> "sda-8741C4G-end",
1391 exp_perms
=> "0:0:0600",
1393 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1394 KERNEL=="sda", ENV{TESTENV}="change-envp"
1395 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1399 desc
=> "builtin path_id",
1400 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1401 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1403 KERNEL=="sda", IMPORT{builtin}="path_id"
1404 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1408 desc
=> "add and match tag",
1409 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1410 exp_name
=> "found",
1411 not_exp_name
=> "bad" ,
1413 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1414 TAGS=="green", SYMLINK+="found"
1415 TAGS=="blue", SYMLINK+="bad"
1419 desc
=> "don't crash with lots of tags",
1420 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1421 exp_name
=> "found",
1422 rules
=> $rules_10k_tags . <<EOF
1423 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
1429 my ($action, $devpath, $rules) = @_;
1431 # create temporary rules
1432 system("mkdir", "-p", "$udev_rules_dir");
1433 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1437 if ($valgrind > 0) {
1438 return system("$udev_bin_valgrind $action $devpath");
1439 } elsif ($gdb > 0) {
1440 return system("$udev_bin_gdb $action $devpath");
1441 } elsif ($strace > 0) {
1442 return system("$udev_bin_strace $action $devpath");
1444 return system("$udev_bin", "$action", "$devpath");
1450 sub permissions_test
{
1451 my($rules, $uid, $gid, $mode) = @_;
1457 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1459 if (defined(getpwnam($1))) {
1460 $userid = int(getpwnam($1));
1464 if ($uid != $userid) { $wrong = 1; }
1467 if (defined(getgrnam($2))) {
1468 $groupid = int(getgrnam($2));
1472 if ($gid != $groupid) { $wrong = 1; }
1475 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1478 print "permissions: ok\n";
1480 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1481 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1482 print "permissions: error\n";
1488 sub major_minor_test
{
1489 my($rules, $rdev) = @_;
1491 my $major = ($rdev >> 8) & 0xfff;
1492 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1495 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1497 if ($major != $1) { $wrong = 1; };
1500 if ($minor != $2) { $wrong = 1; };
1503 print "major:minor: ok\n";
1505 printf " expected major:minor is: %i:%i\n", $1, $2;
1506 printf " created major:minor is : %i:%i\n", $major, $minor;
1507 print "major:minor: error\n";
1514 system("umount", $udev_tmpfs);
1516 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
1517 system("mount", "-o", "rw,mode=755,nosuid,noexec,nodev", "-t", "tmpfs", "tmpfs", $udev_tmpfs) && die "unable to mount tmpfs";
1519 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1520 # setting group and mode of udev_dev ensures the tests work
1521 # even if the parent directory has setgid bit enabled.
1522 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1523 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1525 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
1527 system("rm", "-rf", "$udev_run");
1531 my ($rules, $number) = @_;
1534 print "TEST $number: $rules->{desc}\n";
1535 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1537 $rc = udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1539 print "$udev_bin add failed with code $rc\n";
1542 if (defined($rules->{not_exp_name
})) {
1543 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1544 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1545 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1551 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1552 (-l
"$udev_dev/$rules->{exp_name}")) {
1554 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1555 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1557 if (defined($rules->{exp_perms
})) {
1558 permissions_test
($rules, $uid, $gid, $mode);
1560 if (defined($rules->{exp_majorminor
})) {
1561 major_minor_test
($rules, $rdev);
1566 if ($rules->{exp_add_error
}) {
1567 print " as expected\n";
1570 system("tree", "$udev_dev");
1577 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1582 $rc = udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1584 print "$udev_bin remove failed with code $rc\n";
1587 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1588 (-l
"$udev_dev/$rules->{exp_name}")) {
1589 print "remove: error";
1590 if ($rules->{exp_rem_error
}) {
1591 print " as expected\n";
1594 system("tree", "$udev_dev");
1600 print "remove: ok\n";
1605 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1611 # only run if we have root permissions
1612 # due to mknod restrictions
1614 print "Must have root permissions to run properly.\n";
1615 exit($EXIT_TEST_SKIP);
1618 # skip the test when running in a chroot
1619 system("systemd-detect-virt", "-r", "-q");
1621 print "Running in a chroot, skipping the test.\n";
1622 exit($EXIT_TEST_SKIP);
1625 # skip the test when running in a container
1626 system("systemd-detect-virt", "-c", "-q");
1628 print "Running in a container, skipping the test.\n";
1629 exit($EXIT_TEST_SKIP);
1637 foreach my $arg (@ARGV) {
1638 if ($arg =~ m/--valgrind/) {
1640 printf("using valgrind\n");
1641 } elsif ($arg =~ m/--gdb/) {
1643 printf("using gdb\n");
1644 } elsif ($arg =~ m/--strace/) {
1646 printf("using strace\n");
1653 foreach my $arg (@list) {
1654 if (defined($tests[$arg-1]->{desc
})) {
1655 print "udev-test will run test number $arg:\n\n";
1656 run_test
($tests[$arg-1], $arg);
1658 print "test does not exist.\n";
1663 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1665 foreach my $rules (@tests) {
1666 run_test
($rules, $test_num);
1671 print "$error errors occurred\n\n";
1674 system("rm", "-rf", "$udev_run");
1675 system("umount", "$udev_tmpfs");