]>
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 © 2004 Leann Ogasawara <ogasawara@osdl.org>
22 my $udev_bin = "./test-udev";
26 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --track-origins=yes --quiet $udev_bin";
27 my $udev_bin_gdb = "gdb --args $udev_bin";
28 my $udev_bin_strace = "strace -efile $udev_bin";
29 my $udev_run = "test/run";
30 my $udev_tmpfs = "test/tmpfs";
31 my $udev_sys = "${udev_tmpfs}/sys";
32 my $udev_dev = "${udev_tmpfs}/dev";
33 my $udev_rules_dir = "$udev_run/udev/rules.d";
34 my $udev_rules = "$udev_rules_dir/udev-test.rules";
35 my $EXIT_TEST_SKIP = 77;
37 my $rules_10k_tags = "";
38 for (my $i = 1; $i <= 10000; ++$i) {
39 $rules_10k_tags .= 'KERNEL=="sda", TAG+="test' . $i . "\"\n";
42 my $rules_10k_tags_continuation = "KERNEL==\"sda\", \\\n";
43 for (my $i = 1; $i < 10000; ++$i) {
44 $rules_10k_tags_continuation .= 'TAG+="test' . $i . "\",\\\n";
46 $rules_10k_tags_continuation .= "TAG+=\"test10000\"\\n";
51 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
53 exp_rem_error
=> "yes",
59 desc
=> "label test of scsi disc",
60 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
61 exp_name
=> "boot_disk",
63 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
64 KERNEL=="ttyACM0", SYMLINK+="modem"
68 desc
=> "label test of scsi disc",
69 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
70 exp_name
=> "boot_disk",
72 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
73 KERNEL=="ttyACM0", SYMLINK+="modem"
77 desc
=> "label test of scsi disc",
78 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
79 exp_name
=> "boot_disk",
81 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
82 KERNEL=="ttyACM0", SYMLINK+="modem"
86 desc
=> "label test of scsi partition",
87 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
88 exp_name
=> "boot_disk1",
90 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
94 desc
=> "label test of pattern match",
95 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
96 exp_name
=> "boot_disk1",
98 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
99 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
100 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
101 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
105 desc
=> "label test of multiple sysfs files",
106 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
107 exp_name
=> "boot_disk1",
109 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
110 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
114 desc
=> "label test of max sysfs files (skip invalid rule)",
115 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
116 exp_name
=> "boot_disk1",
118 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"
119 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
123 desc
=> "catch device by *",
124 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
125 exp_name
=> "modem/0",
127 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
131 desc
=> "catch device by * - take 2",
132 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
133 exp_name
=> "modem/0",
135 KERNEL=="*ACM1", SYMLINK+="bad"
136 KERNEL=="*ACM0", SYMLINK+="modem/%n"
140 desc
=> "catch device by ?",
141 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
142 exp_name
=> "modem/0",
144 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
145 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
146 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
150 desc
=> "catch device by character class",
151 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
152 exp_name
=> "modem/0",
154 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
155 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
156 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
160 desc
=> "replace kernel name",
161 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
164 KERNEL=="ttyACM0", SYMLINK+="modem"
168 desc
=> "Handle comment lines in config file (and replace kernel name)",
169 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
173 KERNEL=="ttyACM0", SYMLINK+="modem"
178 desc
=> "Handle comment lines in config file with whitespace (and replace kernel name)",
179 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
182 # this is a comment with whitespace before the comment
183 KERNEL=="ttyACM0", SYMLINK+="modem"
188 desc
=> "Handle whitespace only lines (and replace kernel name)",
189 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
190 exp_name
=> "whitespace",
195 # this is a comment with whitespace before the comment
196 KERNEL=="ttyACM0", SYMLINK+="whitespace"
203 desc
=> "Handle empty lines in config file (and replace kernel name)",
204 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
208 KERNEL=="ttyACM0", SYMLINK+="modem"
213 desc
=> "Handle backslashed multi lines in config file (and replace kernel name)",
214 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
217 KERNEL=="ttyACM0", \\
223 desc
=> "preserve backslashes, if they are not for a newline",
224 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
227 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
231 desc
=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
232 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
243 KERNEL=="ttyACM0", \\
249 desc
=> "subdirectory handling",
250 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
251 exp_name
=> "sub/direct/ory/modem",
253 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
257 desc
=> "parent device name match of scsi partition",
258 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
259 exp_name
=> "first_disk5",
261 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
265 desc
=> "test substitution chars",
266 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
267 exp_name
=> "Major:8:minor:5:kernelnumber:5:id:0:0:0:0",
269 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
273 desc
=> "import of shell-value returned from program",
274 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
275 exp_name
=> "node12345678",
277 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
278 KERNEL=="ttyACM0", SYMLINK+="modem"
282 desc
=> "substitution of sysfs value (%s{file})",
283 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
284 exp_name
=> "disk-ATA-sda",
286 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
287 KERNEL=="ttyACM0", SYMLINK+="modem"
291 desc
=> "program result substitution",
292 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
293 exp_name
=> "special-device-5",
294 not_exp_name
=> "not",
296 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
297 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
301 desc
=> "program result substitution (newline removal)",
302 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
303 exp_name
=> "newline_removed",
305 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
309 desc
=> "program result substitution",
310 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
311 exp_name
=> "test-0:0:0:0",
313 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
317 desc
=> "program with lots of arguments",
318 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
321 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
325 desc
=> "program with subshell",
326 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
329 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
333 desc
=> "program arguments combined with apostrophes",
334 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
337 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
341 desc
=> "program arguments combined with escaped double quotes, part 1",
342 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
345 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf %%s \\\"foo1 foo2\\\" | grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
349 desc
=> "program arguments combined with escaped double quotes, part 2",
350 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
353 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c \\\"printf %%s 'foo1 foo2' | grep 'foo1 foo2'\\\"", KERNEL=="sda5", SYMLINK+="%c{2}"
357 desc
=> "program arguments combined with escaped double quotes, part 3",
358 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
361 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'printf \\\"%%s %%s\\\" \\\"foo1 foo2\\\" \\\"foo3\\\"| grep \\\"foo1 foo2\\\"'", KERNEL=="sda5", SYMLINK+="%c{2}"
365 desc
=> "characters before the %c{N} substitution",
366 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
367 exp_name
=> "my-foo9",
369 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
373 desc
=> "substitute the second to last argument",
374 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
375 exp_name
=> "my-foo8",
377 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
381 desc
=> "test substitution by variable name",
382 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
383 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
385 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
389 desc
=> "test substitution by variable name 2",
390 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
391 exp_name
=> "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
393 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
397 desc
=> "test substitution by variable name 3",
398 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
399 exp_name
=> "850:0:0:05",
401 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
405 desc
=> "test substitution by variable name 4",
406 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
409 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
413 desc
=> "test substitution by variable name 5",
414 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
415 exp_name
=> "8550:0:0:0",
417 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
421 desc
=> "non matching SUBSYSTEMS for device with no parent",
422 devpath
=> "/devices/virtual/tty/console",
425 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
426 KERNEL=="console", SYMLINK+="TTY"
430 desc
=> "non matching SUBSYSTEMS",
431 devpath
=> "/devices/virtual/tty/console",
434 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
435 KERNEL=="console", SYMLINK+="TTY"
439 desc
=> "ATTRS match",
440 devpath
=> "/devices/virtual/tty/console",
443 KERNEL=="console", SYMLINK+="TTY"
444 ATTRS{dev}=="5:1", SYMLINK+="foo"
448 desc
=> "ATTR (empty file)",
449 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
452 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
453 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
454 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
455 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
459 desc
=> "ATTR (non-existent file)",
460 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
461 exp_name
=> "non-existent",
463 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
464 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
465 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
466 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
467 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
468 KERNEL=="sda", SYMLINK+="wrong"
472 desc
=> "program and bus type match",
473 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
474 exp_name
=> "scsi-0:0:0:0",
476 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
477 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
478 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
482 desc
=> "sysfs parent hierarchy",
483 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
486 ATTRS{idProduct}=="007b", SYMLINK+="modem"
490 desc
=> "name test with ! in the name",
491 devpath
=> "/devices/virtual/block/fake!blockdev0",
492 exp_name
=> "is/a/fake/blockdev0",
494 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
495 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
496 KERNEL=="ttyACM0", SYMLINK+="modem"
500 desc
=> "name test with ! in the name, but no matching rule",
501 devpath
=> "/devices/virtual/block/fake!blockdev0",
502 exp_name
=> "fake/blockdev0",
503 exp_rem_error
=> "yes",
505 KERNEL=="ttyACM0", SYMLINK+="modem"
509 desc
=> "KERNELS rule",
510 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
511 exp_name
=> "scsi-0:0:0:0",
513 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
514 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
515 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
516 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
517 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
521 desc
=> "KERNELS wildcard all",
522 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
523 exp_name
=> "scsi-0:0:0:0",
525 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
526 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
527 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
528 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
529 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
533 desc
=> "KERNELS wildcard partial",
534 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
535 exp_name
=> "scsi-0:0:0:0",
537 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
538 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
542 desc
=> "KERNELS wildcard partial 2",
543 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
544 exp_name
=> "scsi-0:0:0:0",
546 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
547 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
551 desc
=> "substitute attr with link target value (first match)",
552 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
553 exp_name
=> "driver-is-sd",
555 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
559 desc
=> "substitute attr with link target value (currently selected device)",
560 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
561 exp_name
=> "driver-is-ahci",
563 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
567 desc
=> "ignore ATTRS attribute whitespace",
568 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
569 exp_name
=> "ignored",
571 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
575 desc
=> "do not ignore ATTRS attribute whitespace",
576 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
577 exp_name
=> "matched-with-space",
579 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
580 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
584 desc
=> "permissions USER=bad GROUP=name",
585 devpath
=> "/devices/virtual/tty/tty33",
587 exp_perms
=> "0:0:0600",
589 KERNEL=="tty33", OWNER="bad", GROUP="name"
593 desc
=> "permissions OWNER=1",
594 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
596 exp_perms
=> "1::0600",
598 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
602 desc
=> "permissions GROUP=1",
603 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
605 exp_perms
=> ":1:0660",
607 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
611 desc
=> "textual user id",
612 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
614 exp_perms
=> "daemon::0600",
616 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="daemon"
620 desc
=> "textual group id",
621 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
623 exp_perms
=> ":daemon:0660",
625 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
629 desc
=> "textual user/group id",
630 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
632 exp_perms
=> "root:audio:0660",
634 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="audio"
638 desc
=> "permissions MODE=0777",
639 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
641 exp_perms
=> "::0777",
643 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
647 desc
=> "permissions OWNER=1 GROUP=1 MODE=0777",
648 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
650 exp_perms
=> "1:1:0777",
652 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
656 desc
=> "permissions OWNER to 1",
657 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
658 exp_name
=> "ttyACM0",
661 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
665 desc
=> "permissions GROUP to 1",
666 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
667 exp_name
=> "ttyACM0",
668 exp_perms
=> ":1:0660",
670 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
674 desc
=> "permissions MODE to 0060",
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
=> "::0060",
679 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
683 desc
=> "permissions OWNER, GROUP, MODE",
684 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
685 exp_name
=> "ttyACM0",
686 exp_perms
=> "1:1:0777",
688 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
692 desc
=> "permissions only rule",
693 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
694 exp_name
=> "ttyACM0",
695 exp_perms
=> "1:1:0777",
697 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
698 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
699 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
703 desc
=> "multiple permissions only rule",
704 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
705 exp_name
=> "ttyACM0",
706 exp_perms
=> "1:1:0777",
708 SUBSYSTEM=="tty", OWNER="1"
709 SUBSYSTEM=="tty", GROUP="1"
710 SUBSYSTEM=="tty", MODE="0777"
711 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
712 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
716 desc
=> "permissions only rule with override at SYMLINK+ rule",
717 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
718 exp_name
=> "ttyACM0",
719 exp_perms
=> "1:2:0777",
721 SUBSYSTEM=="tty", OWNER="1"
722 SUBSYSTEM=="tty", GROUP="1"
723 SUBSYSTEM=="tty", MODE="0777"
724 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
725 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
729 desc
=> "major/minor number test",
730 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
732 exp_majorminor
=> "8:0",
734 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
738 desc
=> "big major number test",
739 devpath
=> "/devices/virtual/misc/misc-fake1",
741 exp_majorminor
=> "4095:1",
743 KERNEL=="misc-fake1", SYMLINK+="node"
747 desc
=> "big major and big minor number test",
748 devpath
=> "/devices/virtual/misc/misc-fake89999",
750 exp_majorminor
=> "4095:89999",
752 KERNEL=="misc-fake89999", SYMLINK+="node"
756 desc
=> "multiple symlinks with format char",
757 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
758 exp_name
=> "symlink2-ttyACM0",
760 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
764 desc
=> "multiple symlinks with a lot of s p a c e s",
765 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
769 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
773 desc
=> "symlink with spaces in substituted variable",
774 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
775 exp_name
=> "name-one_two_three-end",
778 ENV{WITH_WS}="one two three"
779 SYMLINK="name-\$env{WITH_WS}-end"
783 desc
=> "symlink with leading space in substituted variable",
784 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
785 exp_name
=> "name-one_two_three-end",
788 ENV{WITH_WS}=" one two three"
789 SYMLINK="name-\$env{WITH_WS}-end"
793 desc
=> "symlink with trailing space in substituted variable",
794 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
795 exp_name
=> "name-one_two_three-end",
798 ENV{WITH_WS}="one two three "
799 SYMLINK="name-\$env{WITH_WS}-end"
803 desc
=> "symlink with lots of space in substituted variable",
804 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
805 exp_name
=> "name-one_two_three-end",
808 ENV{WITH_WS}=" one two three "
809 SYMLINK="name-\$env{WITH_WS}-end"
813 desc
=> "symlink with multiple spaces in substituted variable",
814 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
815 exp_name
=> "name-one_two_three-end",
818 ENV{WITH_WS}=" one two three "
819 SYMLINK="name-\$env{WITH_WS}-end"
823 desc
=> "symlink with space and var with space, part 1",
824 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
828 ENV{WITH_WS}=" one two three "
829 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
833 desc
=> "symlink with space and var with space, part 2",
834 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
835 exp_name
=> "name-one_two_three-end",
838 ENV{WITH_WS}=" one two three "
839 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
843 desc
=> "symlink with space and var with space, part 3",
844 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
845 exp_name
=> "another_symlink",
848 ENV{WITH_WS}=" one two three "
849 SYMLINK=" first name-\$env{WITH_WS}-end another_symlink a b c "
853 desc
=> "symlink creation (same directory)",
854 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
855 exp_name
=> "modem0",
857 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
861 desc
=> "multiple symlinks",
862 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
863 exp_name
=> "second-0",
865 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
869 desc
=> "symlink name '.'",
870 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
872 exp_add_error
=> "yes",
873 exp_rem_error
=> "yes",
875 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
879 desc
=> "symlink node to itself",
880 devpath
=> "/devices/virtual/tty/tty0",
882 exp_add_error
=> "yes",
883 exp_rem_error
=> "yes",
886 KERNEL=="tty0", SYMLINK+="tty0"
890 desc
=> "symlink %n substitution",
891 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
892 exp_name
=> "symlink0",
894 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
898 desc
=> "symlink %k substitution",
899 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
900 exp_name
=> "symlink-ttyACM0",
902 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
906 desc
=> "symlink %M:%m substitution",
907 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
908 exp_name
=> "major-166:0",
910 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
914 desc
=> "symlink %b substitution",
915 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
916 exp_name
=> "symlink-0:0:0:0",
918 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
922 desc
=> "symlink %c substitution",
923 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
926 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
930 desc
=> "symlink %c{N} substitution",
931 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
934 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
938 desc
=> "symlink %c{N+} substitution",
939 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
942 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
946 desc
=> "symlink only rule with %c{N+}",
947 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
950 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
954 desc
=> "symlink %s{filename} substitution",
955 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
958 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
962 desc
=> "program result substitution (numbered part of)",
963 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
966 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
970 desc
=> "program result substitution (numbered part of+)",
971 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
974 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
978 desc
=> "SUBSYSTEM match test",
979 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
982 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
983 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
984 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
988 desc
=> "DRIVERS match test",
989 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
992 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
993 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
997 desc
=> "devnode substitution test",
998 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1001 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
1005 desc
=> "parent node name substitution test",
1006 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1007 exp_name
=> "sda-part-1",
1009 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
1013 desc
=> "udev_root substitution",
1014 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1015 exp_name
=> "start-/dev-end",
1017 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
1021 desc
=> "last_rule option",
1022 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1025 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
1026 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
1030 desc
=> "negation KERNEL!=",
1031 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1032 exp_name
=> "match",
1034 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1035 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1036 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
1040 desc
=> "negation SUBSYSTEM!=",
1041 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1042 exp_name
=> "not-anything",
1044 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
1045 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1046 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
1050 desc
=> "negation PROGRAM!= exit code",
1051 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1052 exp_name
=> "nonzero-program",
1054 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1055 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
1059 desc
=> "ENV{} test",
1060 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1063 ENV{ENV_KEY_TEST}="test"
1064 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1065 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
1066 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1070 desc
=> "ENV{} test",
1071 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1074 ENV{ENV_KEY_TEST}="test"
1075 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
1076 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
1077 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
1078 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
1082 desc
=> "ENV{} test (assign)",
1083 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1086 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1087 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1088 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1089 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
1093 desc
=> "ENV{} test (assign 2 times)",
1094 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1097 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
1098 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
1099 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
1100 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
1101 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
1105 desc
=> "ENV{} test (assign2)",
1106 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1109 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
1110 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
1111 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
1112 SUBSYSTEM=="block", SYMLINK+="before"
1113 ENV{PARTITION}=="true", SYMLINK+="part"
1117 desc
=> "untrusted string sanitize",
1118 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1121 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1125 desc
=> "untrusted string sanitize (don't replace utf8)",
1126 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1129 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1133 desc
=> "untrusted string sanitize (replace invalid utf8)",
1134 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1135 exp_name
=> "replaced",
1137 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1141 desc
=> "read sysfs value from parent device",
1142 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1143 exp_name
=> "serial-354172020305000",
1145 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1149 desc
=> "match against empty key string",
1150 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1153 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1154 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1155 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1156 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1160 desc
=> "check ACTION value",
1161 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1164 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1165 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1169 desc
=> "final assignment",
1170 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1172 exp_perms
=> "root:tty:0640",
1174 KERNEL=="sda", GROUP:="tty"
1175 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1179 desc
=> "final assignment 2",
1180 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1182 exp_perms
=> "root:tty:0640",
1184 KERNEL=="sda", GROUP:="tty"
1185 SUBSYSTEM=="block", MODE:="640"
1186 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1190 desc
=> "env substitution",
1191 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1192 exp_name
=> "node-add-me",
1194 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1198 desc
=> "reset list to current value",
1199 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1200 exp_name
=> "three",
1201 not_exp_name
=> "two",
1203 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1204 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1205 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1209 desc
=> "test empty SYMLINK+ (empty override)",
1210 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1211 exp_name
=> "right",
1212 not_exp_name
=> "wrong",
1214 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1215 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1216 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1220 desc
=> "test multi matches",
1221 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1222 exp_name
=> "right",
1224 KERNEL=="ttyACM*", SYMLINK+="before"
1225 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1229 desc
=> "test multi matches 2",
1230 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1231 exp_name
=> "right",
1233 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1234 KERNEL=="ttyACM*", SYMLINK+="before"
1235 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1239 desc
=> "test multi matches 3",
1240 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1241 exp_name
=> "right",
1243 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1244 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1245 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1246 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1250 desc
=> "test multi matches 4",
1251 devpath
=> "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1252 exp_name
=> "right",
1254 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1255 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1256 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1257 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1258 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1262 desc
=> "test multi matches 5",
1263 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1264 exp_name
=> "found",
1265 not_exp_name
=> "bad",
1267 KERNEL=="sda", TAG="foo"
1268 TAGS=="|foo", SYMLINK+="found"
1269 TAGS=="|aaa", SYMLINK+="bad"
1273 desc
=> "test multi matches 6",
1274 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1275 exp_name
=> "found",
1276 not_exp_name
=> "bad",
1278 KERNEL=="sda", TAG=""
1279 TAGS=="|foo", SYMLINK+="found"
1280 TAGS=="aaa|bbb", SYMLINK+="bad"
1284 desc
=> "test multi matches 7",
1285 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1286 exp_name
=> "found",
1287 not_exp_name
=> "bad",
1289 KERNEL=="sda", TAG="foo"
1290 TAGS=="foo||bar", SYMLINK+="found"
1291 TAGS=="aaa||bbb", SYMLINK+="bad"
1295 desc
=> "test multi matches 8",
1296 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1297 exp_name
=> "found",
1298 not_exp_name
=> "bad",
1300 KERNEL=="sda", TAG=""
1301 TAGS=="foo||bar", SYMLINK+="found"
1302 TAGS=="aaa|bbb", SYMLINK+="bad"
1306 desc
=> "test multi matches 9",
1307 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1308 exp_name
=> "found",
1309 not_exp_name
=> "bad",
1311 KERNEL=="sda", TAG="foo"
1312 TAGS=="foo|", SYMLINK+="found"
1313 TAGS=="aaa|", SYMLINK+="bad"
1317 desc
=> "test multi matches 10",
1318 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1319 exp_name
=> "found",
1320 not_exp_name
=> "bad",
1322 KERNEL=="sda", TAG=""
1323 TAGS=="foo|", SYMLINK+="found"
1324 TAGS=="aaa|bbb", SYMLINK+="bad"
1328 desc
=> "test multi matches 11",
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 KERNEL=="sda", TAG="c"
1334 TAGS=="foo||bar||c", SYMLINK+="found"
1335 TAGS=="aaa||bbb||ccc", SYMLINK+="bad"
1339 desc
=> "IMPORT parent test sequence 1/2 (keep)",
1340 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1341 exp_name
=> "parent",
1344 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1345 KERNEL=="sda", SYMLINK+="parent"
1349 desc
=> "IMPORT parent test sequence 2/2 (keep)",
1350 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1351 exp_name
=> "parentenv-parent_right",
1354 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1358 desc
=> "GOTO test",
1359 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1360 exp_name
=> "right",
1362 KERNEL=="sda1", GOTO="TEST"
1363 KERNEL=="sda1", SYMLINK+="wrong"
1364 KERNEL=="sda1", GOTO="BAD"
1365 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1366 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1367 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1372 desc
=> "GOTO label does not exist",
1373 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1374 exp_name
=> "right",
1376 KERNEL=="sda1", GOTO="does-not-exist"
1377 KERNEL=="sda1", SYMLINK+="right",
1382 desc
=> "SYMLINK+ compare test",
1383 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1384 exp_name
=> "right",
1385 not_exp_name
=> "wrong",
1387 KERNEL=="sda1", SYMLINK+="link"
1388 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1389 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1393 desc
=> "invalid key operation",
1394 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1397 KERNEL="sda1", SYMLINK+="no"
1398 KERNEL=="sda1", SYMLINK+="yes"
1402 desc
=> "operator chars in attribute",
1403 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1406 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1410 desc
=> "overlong comment line",
1411 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1414 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1415 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1416 KERNEL=="sda1", SYMLINK+=="no"
1417 KERNEL=="sda1", SYMLINK+="yes"
1421 desc
=> "magic subsys/kernel lookup",
1422 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1423 exp_name
=> "00:16:41:e2:8d:ff",
1425 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1429 desc
=> "TEST absolute path",
1430 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1431 exp_name
=> "there",
1433 TEST=="/etc/machine-id", SYMLINK+="there"
1434 TEST!="/etc/machine-id", SYMLINK+="notthere"
1438 desc
=> "TEST subsys/kernel lookup",
1439 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1442 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1446 desc
=> "TEST relative path",
1447 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1448 exp_name
=> "relative",
1450 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1454 desc
=> "TEST wildcard substitution (find queue/nr_requests)",
1455 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1456 exp_name
=> "found-subdir",
1458 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1462 desc
=> "TEST MODE=0000",
1463 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1465 exp_perms
=> "0:0:0000",
1466 exp_rem_error
=> "yes",
1468 KERNEL=="sda", MODE="0000"
1472 desc
=> "TEST PROGRAM feeds OWNER, GROUP, MODE",
1473 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1475 exp_perms
=> "1:1:0400",
1476 exp_rem_error
=> "yes",
1478 KERNEL=="sda", MODE="666"
1479 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1483 desc
=> "TEST PROGRAM feeds MODE with overflow",
1484 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1486 exp_perms
=> "0:0:0440",
1487 exp_rem_error
=> "yes",
1489 KERNEL=="sda", MODE="440"
1490 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1494 desc
=> "magic [subsys/sysname] attribute substitution",
1495 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1496 exp_name
=> "sda-8741C4G-end",
1497 exp_perms
=> "0:0:0600",
1499 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1500 KERNEL=="sda", ENV{TESTENV}="change-envp"
1501 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1505 desc
=> "builtin path_id",
1506 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1507 exp_name
=> "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1509 KERNEL=="sda", IMPORT{builtin}="path_id"
1510 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1514 desc
=> "add and match tag",
1515 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1516 exp_name
=> "found",
1517 not_exp_name
=> "bad",
1519 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", TAG+="green"
1520 TAGS=="green", SYMLINK+="found"
1521 TAGS=="blue", SYMLINK+="bad"
1525 desc
=> "don't crash with lots of tags",
1526 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1527 exp_name
=> "found",
1528 rules
=> $rules_10k_tags . <<EOF
1529 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="found"
1533 desc
=> "continuations",
1534 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1535 exp_name
=> "found",
1536 not_exp_name
=> "bad",
1537 rules
=> $rules_10k_tags_continuation . <<EOF
1538 TAGS=="test1", TAGS=="test500", TAGS=="test1234", TAGS=="test9999", TAGS=="test10000", SYMLINK+="bad"
1540 # comment in continuation
1542 # space before comment
1544 # spaces before and after token are dropped
1549 TAGS=="hoge1", TAGS=="hoge2", TAGS=="hoge3", TAGS=="hoge4", SYMLINK+="found"
1553 desc
=> "continuations with empty line",
1554 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1555 exp_name
=> "found",
1556 not_exp_name
=> "bad",
1558 # empty line finishes continuation
1559 KERNEL=="sda", TAG+="foo" \\
1561 KERNEL=="sdb", TAG+="hoge"
1562 KERNEL=="sda", TAG+="aaa" \\
1563 KERNEL=="sdb", TAG+="bbb"
1564 TAGS=="foo", SYMLINK+="found"
1565 TAGS=="aaa", SYMLINK+="bad"
1569 desc
=> "continuations with white only line",
1570 devpath
=> "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1571 exp_name
=> "found",
1572 not_exp_name
=> "bad",
1574 # space only line finishes continuation
1575 KERNEL=="sda", TAG+="foo" \\
1577 KERNEL=="sdb", TAG+="hoge"
1578 KERNEL=="sda", TAG+="aaa" \\
1579 KERNEL=="sdb", TAG+="bbb"
1580 TAGS=="foo", SYMLINK+="found"
1581 TAGS=="aaa", SYMLINK+="bad"
1587 my ($action, $devpath, $rules) = @_;
1589 # create temporary rules
1590 system("mkdir", "-p", "$udev_rules_dir");
1591 open CONF
, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1595 if ($valgrind > 0) {
1596 return system("$udev_bin_valgrind $action $devpath");
1597 } elsif ($gdb > 0) {
1598 return system("$udev_bin_gdb $action $devpath");
1599 } elsif ($strace > 0) {
1600 return system("$udev_bin_strace $action $devpath");
1602 return system("$udev_bin", "$action", "$devpath");
1608 sub permissions_test
{
1609 my($rules, $uid, $gid, $mode) = @_;
1615 $rules->{exp_perms
} =~ m/^(.*):(.*):(.*)$/;
1617 if (defined(getpwnam($1))) {
1618 $userid = int(getpwnam($1));
1622 if ($uid != $userid) { $wrong = 1; }
1625 if (defined(getgrnam($2))) {
1626 $groupid = int(getgrnam($2));
1630 if ($gid != $groupid) { $wrong = 1; }
1633 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1636 print "permissions: ok\n";
1638 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1639 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1640 print "permissions: error\n";
1646 sub major_minor_test
{
1647 my($rules, $rdev) = @_;
1649 my $major = ($rdev >> 8) & 0xfff;
1650 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1653 $rules->{exp_majorminor
} =~ m/^(.*):(.*)$/;
1655 if ($major != $1) { $wrong = 1; };
1658 if ($minor != $2) { $wrong = 1; };
1661 print "major:minor: ok\n";
1663 printf " expected major:minor is: %i:%i\n", $1, $2;
1664 printf " created major:minor is : %i:%i\n", $major, $minor;
1665 print "major:minor: error\n";
1672 system("umount", $udev_tmpfs);
1674 mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
1676 if (system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) {
1677 warn "unable to mount tmpfs";
1681 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1682 # setting group and mode of udev_dev ensures the tests work
1683 # even if the parent directory has setgid bit enabled.
1684 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1685 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1687 if (system("mknod", $udev_dev . "/null", "c", "1", "3")) {
1688 warn "unable to create $udev_dev/null";
1692 # check if we are permitted to create block device nodes
1693 my $block_device_filename = $udev_dev . "/sda";
1694 if (system("mknod", $block_device_filename, "b", "8", "0")) {
1695 warn "unable to create $block_device_filename";
1698 unlink $block_device_filename;
1700 system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
1702 system("rm", "-rf", "$udev_run");
1704 if (!mkdir($udev_run)) {
1705 warn "unable to create directory $udev_run";
1713 my ($rules, $number) = @_;
1716 print "TEST $number: $rules->{desc}\n";
1717 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1719 $rc = udev
("add", $rules->{devpath
}, \
$rules->{rules
});
1721 print "$udev_bin add failed with code $rc\n";
1724 if (defined($rules->{not_exp_name
})) {
1725 if ((-e
"$udev_dev/$rules->{not_exp_name}") ||
1726 (-l
"$udev_dev/$rules->{not_exp_name}")) {
1727 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1733 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1734 (-l
"$udev_dev/$rules->{exp_name}")) {
1736 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1737 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1739 if (defined($rules->{exp_perms
})) {
1740 permissions_test
($rules, $uid, $gid, $mode);
1742 if (defined($rules->{exp_majorminor
})) {
1743 major_minor_test
($rules, $rdev);
1748 if ($rules->{exp_add_error
}) {
1749 print " as expected\n";
1752 system("tree", "$udev_dev");
1759 if (defined($rules->{option
}) && $rules->{option
} eq "keep") {
1764 $rc = udev
("remove", $rules->{devpath
}, \
$rules->{rules
});
1766 print "$udev_bin remove failed with code $rc\n";
1769 if ((-e
"$udev_dev/$rules->{exp_name}") ||
1770 (-l
"$udev_dev/$rules->{exp_name}")) {
1771 print "remove: error";
1772 if ($rules->{exp_rem_error
}) {
1773 print " as expected\n";
1776 system("tree", "$udev_dev");
1782 print "remove: ok\n";
1787 if (defined($rules->{option
}) && $rules->{option
} eq "clean") {
1794 system("rm", "-rf", "$udev_run");
1795 system("umount", "$udev_tmpfs");
1799 # only run if we have root permissions
1800 # due to mknod restrictions
1802 print "Must have root permissions to run properly.\n";
1803 exit($EXIT_TEST_SKIP);
1806 # skip the test when running in a chroot
1807 system("systemd-detect-virt", "-r", "-q");
1809 print "Running in a chroot, skipping the test.\n";
1810 exit($EXIT_TEST_SKIP);
1813 if (!udev_setup
()) {
1814 warn "Failed to set up the environment, skipping the test";
1816 exit($EXIT_TEST_SKIP);
1819 if (system($udev_bin, "check")) {
1820 warn "$udev_bin failed to set up the environment, skipping the test";
1822 exit($EXIT_TEST_SKIP);
1828 foreach my $arg (@ARGV) {
1829 if ($arg =~ m/--valgrind/) {
1831 printf("using valgrind\n");
1832 } elsif ($arg =~ m/--gdb/) {
1834 printf("using gdb\n");
1835 } elsif ($arg =~ m/--strace/) {
1837 printf("using strace\n");
1844 foreach my $arg (@list) {
1845 if (defined($tests[$arg-1]->{desc
})) {
1846 print "udev-test will run test number $arg:\n\n";
1847 run_test
($tests[$arg-1], $arg);
1849 print "test does not exist.\n";
1854 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1856 foreach my $rules (@tests) {
1857 run_test
($rules, $test_num);
1862 print "$error errors occurred\n\n";