]>
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 creation (same directory)",
745 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
746 exp_name
=> "modem0",
748 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
752 desc
=> "multiple symlinks",
753 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
754 exp_name
=> "second-0" ,
756 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
760 desc
=> "symlink name '.'",
761 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
763 exp_add_error
=> "yes",
764 exp_rem_error
=> "yes",
766 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
770 desc
=> "symlink node to itself",
771 devpath
=> "/devices/virtual/tty/tty0",
773 exp_add_error
=> "yes",
774 exp_rem_error
=> "yes",
777 KERNEL=="tty0", SYMLINK+="tty0"
781 desc
=> "symlink %n substitution",
782 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
783 exp_name
=> "symlink0",
785 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
789 desc
=> "symlink %k substitution",
790 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
791 exp_name
=> "symlink-ttyACM0",
793 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
797 desc
=> "symlink %M:%m substitution",
798 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
799 exp_name
=> "major-166:0",
801 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
805 desc
=> "symlink %b substitution",
806 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
807 exp_name
=> "symlink-0:0:0:0",
809 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
813 desc
=> "symlink %c substitution",
814 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
817 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
821 desc
=> "symlink %c{N} substitution",
822 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
825 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
829 desc
=> "symlink %c{N+} substitution",
830 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
833 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
837 desc
=> "symlink only rule with %c{N+}",
838 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
841 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
845 desc
=> "symlink %s{filename} substitution",
846 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
849 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
853 desc
=> "program result substitution (numbered part of)",
854 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
857 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
861 desc
=> "program result substitution (numbered part of+)",
862 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
865 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
869 desc
=> "SUBSYSTEM match test",
870 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
873 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
874 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
875 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
879 desc
=> "DRIVERS match test",
880 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
883 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
884 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
888 desc
=> "devnode substitution test",
889 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
892 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
896 desc
=> "parent node name substitution test",
897 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
898 exp_name
=> "sda-part-1",
900 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
904 desc
=> "udev_root substitution",
905 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
906 exp_name
=> "start-/dev-end",
908 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
912 desc
=> "last_rule option",
913 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
916 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
917 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
921 desc
=> "negation KERNEL!=",
922 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
925 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
926 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
927 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
931 desc
=> "negation SUBSYSTEM!=",
932 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
933 exp_name
=> "not-anything",
935 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
936 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
937 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
941 desc
=> "negation PROGRAM!= exit code",
942 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
943 exp_name
=> "nonzero-program",
945 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
946 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
950 desc
=> "ENV{} test",
951 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
954 ENV{ENV_KEY_TEST}="test"
955 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
956 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
957 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
961 desc
=> "ENV{} test",
962 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
965 ENV{ENV_KEY_TEST}="test"
966 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
967 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
968 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
969 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
973 desc
=> "ENV{} test (assign)",
974 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
977 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
978 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
979 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
980 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
984 desc
=> "ENV{} test (assign 2 times)",
985 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
988 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
989 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
990 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
991 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
992 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
996 desc
=> "ENV{} test (assign2)",
997 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1000 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1001 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1002 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1003 SUBSYSTEM=="block", SYMLINK+="before"
1004 ENV{PARTITION}=="true", SYMLINK+="part"
1008 desc
=> "untrusted string sanitize",
1009 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1012 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1016 desc
=> "untrusted string sanitize (don't replace utf8)",
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", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1024 desc
=> "untrusted string sanitize (replace invalid utf8)",
1025 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1026 exp_name
=> "replaced",
1028 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1032 desc
=> "read sysfs value from parent device",
1033 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1034 exp_name
=> "serial-354172020305000",
1036 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1040 desc
=> "match against empty key string",
1041 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1044 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1045 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1046 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1047 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1051 desc
=> "check ACTION value",
1052 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1055 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1056 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1060 desc
=> "final assignment",
1061 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1063 exp_perms
=> "root:tty:0640",
1065 KERNEL=="sda", GROUP:="tty"
1066 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1070 desc
=> "final assignment 2",
1071 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1073 exp_perms
=> "root:tty:0640",
1075 KERNEL=="sda", GROUP:="tty"
1076 SUBSYSTEM=="block", MODE:="640"
1077 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1081 desc
=> "env substitution",
1082 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1083 exp_name
=> "node-add-me",
1085 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1089 desc
=> "reset list to current value",
1090 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1091 exp_name
=> "three",
1092 not_exp_name
=> "two",
1094 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1095 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1096 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1100 desc
=> "test empty SYMLINK+ (empty override)",
1101 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1102 exp_name
=> "right",
1103 not_exp_name
=> "wrong",
1105 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1106 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1107 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1111 desc
=> "test multi matches",
1112 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1113 exp_name
=> "right",
1115 KERNEL=="ttyACM*", SYMLINK+="before"
1116 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1120 desc
=> "test multi matches 2",
1121 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1122 exp_name
=> "right",
1124 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1125 KERNEL=="ttyACM*", SYMLINK+="before"
1126 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1130 desc
=> "test multi matches 3",
1131 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1132 exp_name
=> "right",
1134 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1135 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1136 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1137 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1141 desc
=> "test multi matches 4",
1142 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1143 exp_name
=> "right",
1145 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1146 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1147 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1148 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1149 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1153 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1154 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1155 exp_name
=> "parent",
1158 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1159 KERNEL=="sda", SYMLINK+="parent"
1163 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1164 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1165 exp_name
=> "parentenv-parent_right",
1168 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1172 desc
=> "GOTO test",
1173 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1174 exp_name
=> "right",
1176 KERNEL=="sda1", GOTO="TEST"
1177 KERNEL=="sda1", SYMLINK+="wrong"
1178 KERNEL=="sda1", GOTO="BAD"
1179 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1180 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1181 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1186 desc
=> "GOTO label does not exist",
1187 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1188 exp_name
=> "right",
1190 KERNEL=="sda1", GOTO="does-not-exist"
1191 KERNEL=="sda1", SYMLINK+="right",
1196 desc
=> "SYMLINK+ compare test",
1197 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1198 exp_name
=> "right",
1199 not_exp_name
=> "wrong",
1201 KERNEL=="sda1", SYMLINK+="link"
1202 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1203 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1207 desc
=> "invalid key operation",
1208 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1211 KERNEL="sda1", SYMLINK+="no"
1212 KERNEL=="sda1", SYMLINK+="yes"
1216 desc
=> "operator chars in attribute",
1217 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1220 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1224 desc
=> "overlong comment line",
1225 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1228 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1229 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1230 KERNEL=="sda1", SYMLINK+=="no"
1231 KERNEL=="sda1", SYMLINK+="yes"
1235 desc
=> "magic subsys/kernel lookup",
1236 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1237 exp_name
=> "00:16:41:e2:8d:ff",
1239 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1243 desc
=> "TEST absolute path",
1244 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1245 exp_name
=> "there",
1247 TEST=="/etc/machine-id", SYMLINK+="there"
1248 TEST!="/etc/machine-id", SYMLINK+="notthere"
1252 desc
=> "TEST subsys/kernel lookup",
1253 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1256 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1260 desc
=> "TEST relative path",
1261 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1262 exp_name
=> "relative",
1264 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1268 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1269 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1270 exp_name
=> "found-subdir",
1272 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1276 desc
=> "TEST MODE=0000",
1277 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1279 exp_perms
=> "0:0:0000",
1280 exp_rem_error
=> "yes",
1282 KERNEL=="sda", MODE="0000"
1286 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1287 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1289 exp_perms
=> "1:1:0400",
1290 exp_rem_error
=> "yes",
1292 KERNEL=="sda", MODE="666"
1293 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1297 desc
=> "TEST PROGRAM feeds MODE with overflow",
1298 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1300 exp_perms
=> "0:0:0440",
1301 exp_rem_error
=> "yes",
1303 KERNEL=="sda", MODE="440"
1304 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1308 desc
=> "magic [subsys/sysname] attribute substitution",
1309 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1310 exp_name
=> "sda-8741C4G-end",
1311 exp_perms
=> "0:0:0600",
1313 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1314 KERNEL=="sda", ENV{TESTENV}="change-envp"
1315 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1319 desc
=> "builtin path_id",
1320 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1321 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1323 KERNEL=="sda", IMPORT{builtin}="path_id"
1324 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1328 desc
=> "add and match tag",
1329 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1330 exp_name
=> "found",
1331 not_exp_name
=> "bad" ,
1333 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1334 TAGS=="green", SYMLINK+="found"
1335 TAGS=="blue", SYMLINK+="bad"
1339 desc
=> "don't crash with lots of tags",
1340 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1341 exp_name
=> "found",
1342 rules
=> $rules_10k_tags . <<EOF
1343 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
1349 my ($action, $devpath, $rules) = @_;
1351 # create temporary rules
1352 system("mkdir", "-p", "$udev_rules_dir");
1353 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1357 if ($valgrind > 0) {
1358 return system("$udev_bin_valgrind $action $devpath");
1359 } elsif ($gdb > 0) {
1360 return system("$udev_bin_gdb $action $devpath");
1361 } elsif ($strace > 0) {
1362 return system("$udev_bin_strace $action $devpath");
1364 return system("$udev_bin", "$action", "$devpath");
1370 sub permissions_test
{
1371 my($rules, $uid, $gid, $mode) = @_;
1377 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1379 if (defined(getpwnam($1))) {
1380 $userid = int(getpwnam($1));
1384 if ($uid != $userid) { $wrong = 1; }
1387 if (defined(getgrnam($2))) {
1388 $groupid = int(getgrnam($2));
1392 if ($gid != $groupid) { $wrong = 1; }
1395 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1398 print "permissions: ok\n";
1400 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1401 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1402 print "permissions: error\n";
1408 sub major_minor_test
{
1409 my($rules, $rdev) = @_;
1411 my $major = ($rdev >> 8) & 0xfff;
1412 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1415 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1417 if ($major != $1) { $wrong = 1; };
1420 if ($minor != $2) { $wrong = 1; };
1423 print "major:minor: ok\n";
1425 printf " expected major:minor is: %i:%i\n", $1, $2;
1426 printf " created major:minor is : %i:%i\n", $major, $minor;
1427 print "major:minor: error\n";
1434 system("umount", $udev_tmpfs);
1436 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
1437 system("mount", "-o", "rw,mode=755,nosuid,noexec,nodev", "-t", "tmpfs", "tmpfs", $udev_tmpfs) && die "unable to mount tmpfs";
1439 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1440 # setting group and mode of udev_dev ensures the tests work
1441 # even if the parent directory has setgid bit enabled.
1442 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1443 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1445 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
1447 system("rm", "-rf", "$udev_run");
1451 my ($rules, $number) = @_;
1454 print "TEST $number: $rules->{desc}\n";
1455 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1457 $rc = udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1459 print "$udev_bin add failed with code $rc\n";
1462 if (defined($rules->{not_exp_name
})) {
1463 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1464 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1465 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1471 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1472 (-l
"$udev_dev/$rules->{exp_name}")) {
1474 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1475 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1477 if (defined($rules->{exp_perms
})) {
1478 permissions_test
($rules, $uid, $gid, $mode);
1480 if (defined($rules->{exp_majorminor
})) {
1481 major_minor_test
($rules, $rdev);
1486 if ($rules->{exp_add_error
}) {
1487 print " as expected\n";
1490 system("tree", "$udev_dev");
1497 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1502 $rc = udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1504 print "$udev_bin remove failed with code $rc\n";
1507 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1508 (-l
"$udev_dev/$rules->{exp_name}")) {
1509 print "remove: error";
1510 if ($rules->{exp_rem_error
}) {
1511 print " as expected\n";
1514 system("tree", "$udev_dev");
1520 print "remove: ok\n";
1525 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1531 # only run if we have root permissions
1532 # due to mknod restrictions
1534 print "Must have root permissions to run properly.\n";
1535 exit($EXIT_TEST_SKIP);
1538 # skip the test when running in a chroot
1539 system("systemd-detect-virt", "-r", "-q");
1541 print "Running in a chroot, skipping the test.\n";
1542 exit($EXIT_TEST_SKIP);
1545 # skip the test when running in a container
1546 system("systemd-detect-virt", "-c", "-q");
1548 print "Running in a container, skipping the test.\n";
1549 exit($EXIT_TEST_SKIP);
1557 foreach my $arg (@ARGV) {
1558 if ($arg =~ m/--valgrind/) {
1560 printf("using valgrind\n");
1561 } elsif ($arg =~ m/--gdb/) {
1563 printf("using gdb\n");
1564 } elsif ($arg =~ m/--strace/) {
1566 printf("using strace\n");
1573 foreach my $arg (@list) {
1574 if (defined($tests[$arg-1]->{desc
})) {
1575 print "udev-test will run test number $arg:\n\n";
1576 run_test
($tests[$arg-1], $arg);
1578 print "test does not exist.\n";
1583 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1585 foreach my $rules (@tests) {
1586 run_test
($rules, $test_num);
1591 print "$error errors occurred\n\n";
1594 system("rm", "-rf", "$udev_run");
1595 system("umount", "$udev_tmpfs");