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";
25 my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
26 my $udev_dev = "test/dev";
27 my $udev_run = "test/run";
28 my $udev_rules_dir = "$udev_run/udev/rules.d";
29 my $udev_rules = "$udev_rules_dir/udev-test.rules";
34 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
36 exp_rem_error => "yes",
42 desc => "label test of scsi disc",
43 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
44 exp_name => "boot_disk" ,
46 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
47 KERNEL=="ttyACM0", SYMLINK+="modem"
51 desc => "label test of scsi disc",
52 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
53 exp_name => "boot_disk" ,
55 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
56 KERNEL=="ttyACM0", SYMLINK+="modem"
60 desc => "label test of scsi disc",
61 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
62 exp_name => "boot_disk" ,
64 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
65 KERNEL=="ttyACM0", SYMLINK+="modem"
69 desc => "label test of scsi partition",
70 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
71 exp_name => "boot_disk1" ,
73 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
77 desc => "label test of pattern match",
78 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
79 exp_name => "boot_disk1" ,
81 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
82 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
83 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
84 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
88 desc => "label test of multiple sysfs files",
89 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
90 exp_name => "boot_disk1" ,
92 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
93 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
97 desc => "label test of max sysfs files (skip invalid rule)",
98 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
99 exp_name => "boot_disk1" ,
101 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", ATTRS{queue_depth}=="32", SYMLINK+="boot_diskXX%n"
102 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
106 desc => "catch device by *",
107 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
108 exp_name => "modem/0" ,
110 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
114 desc => "catch device by * - take 2",
115 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
116 exp_name => "modem/0" ,
118 KERNEL=="*ACM1", SYMLINK+="bad"
119 KERNEL=="*ACM0", SYMLINK+="modem/%n"
123 desc => "catch device by ?",
124 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
125 exp_name => "modem/0" ,
127 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
128 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
129 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
133 desc => "catch device by character class",
134 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
135 exp_name => "modem/0" ,
137 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
138 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
139 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
143 desc => "replace kernel name",
144 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
145 exp_name => "modem" ,
147 KERNEL=="ttyACM0", SYMLINK+="modem"
151 desc => "Handle comment lines in config file (and replace kernel name)",
152 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
153 exp_name => "modem" ,
156 KERNEL=="ttyACM0", SYMLINK+="modem"
161 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
162 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
163 exp_name => "modem" ,
165 # this is a comment with whitespace before the comment
166 KERNEL=="ttyACM0", SYMLINK+="modem"
171 desc => "Handle whitespace only lines (and replace kernel name)",
172 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
173 exp_name => "whitespace" ,
178 # this is a comment with whitespace before the comment
179 KERNEL=="ttyACM0", SYMLINK+="whitespace"
186 desc => "Handle empty lines in config file (and replace kernel name)",
187 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
188 exp_name => "modem" ,
191 KERNEL=="ttyACM0", SYMLINK+="modem"
196 desc => "Handle backslashed multi lines in config file (and replace kernel name)",
197 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
198 exp_name => "modem" ,
200 KERNEL=="ttyACM0", \\
206 desc => "preserve backslashes, if they are not for a newline",
207 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
210 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
214 desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
215 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
216 exp_name => "modem" ,
226 KERNEL=="ttyACM0", \\
232 desc => "subdirectory handling",
233 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
234 exp_name => "sub/direct/ory/modem" ,
236 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
240 desc => "parent device name match of scsi partition",
241 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
242 exp_name => "first_disk5" ,
244 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
248 desc => "test substitution chars",
249 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
250 exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
252 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
256 desc => "import of shell-value returned from program",
257 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
258 exp_name => "node12345678",
260 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
261 KERNEL=="ttyACM0", SYMLINK+="modem"
265 desc => "sustitution of sysfs value (%s{file})",
266 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
267 exp_name => "disk-ATA-sda" ,
269 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
270 KERNEL=="ttyACM0", SYMLINK+="modem"
274 desc => "program result substitution",
275 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
276 exp_name => "special-device-5" ,
277 not_exp_name => "not" ,
279 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
280 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
284 desc => "program result substitution (newline removal)",
285 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
286 exp_name => "newline_removed" ,
288 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
292 desc => "program result substitution",
293 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
294 exp_name => "test-0:0:0:0" ,
296 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
300 desc => "program with lots of arguments",
301 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
304 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
308 desc => "program with subshell",
309 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
312 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
316 desc => "program arguments combined with apostrophes",
317 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
320 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
324 desc => "characters before the %c{N} substitution",
325 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
326 exp_name => "my-foo9" ,
328 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
332 desc => "substitute the second to last argument",
333 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
334 exp_name => "my-foo8" ,
336 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
340 desc => "test substitution by variable name",
341 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
342 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
344 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
348 desc => "test substitution by variable name 2",
349 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
350 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
352 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
356 desc => "test substitution by variable name 3",
357 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
358 exp_name => "850:0:0:05" ,
360 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
364 desc => "test substitution by variable name 4",
365 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
368 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
372 desc => "test substitution by variable name 5",
373 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
374 exp_name => "8550:0:0:0" ,
376 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
380 desc => "non matching SUBSYSTEMS for device with no parent",
381 devpath => "/devices/virtual/tty/console",
384 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
385 KERNEL=="console", SYMLINK+="TTY"
389 desc => "non matching SUBSYSTEMS",
390 devpath => "/devices/virtual/tty/console",
393 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
394 KERNEL=="console", SYMLINK+="TTY"
398 desc => "ATTRS match",
399 devpath => "/devices/virtual/tty/console",
402 KERNEL=="console", SYMLINK+="TTY"
403 ATTRS{dev}=="5:1", SYMLINK+="foo"
407 desc => "ATTR (empty file)",
408 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
409 exp_name => "empty" ,
411 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
412 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
413 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
414 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
418 desc => "ATTR (non-existent file)",
419 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
420 exp_name => "non-existent" ,
422 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
423 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
424 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
425 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
426 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
427 KERNEL=="sda", SYMLINK+="wrong"
431 desc => "program and bus type match",
432 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
433 exp_name => "scsi-0:0:0:0" ,
435 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
436 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
437 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
441 desc => "sysfs parent hierarchy",
442 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
443 exp_name => "modem" ,
445 ATTRS{idProduct}=="007b", SYMLINK+="modem"
449 desc => "name test with ! in the name",
450 devpath => "/devices/virtual/block/fake!blockdev0",
451 exp_name => "is/a/fake/blockdev0" ,
453 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
454 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
455 KERNEL=="ttyACM0", SYMLINK+="modem"
459 desc => "name test with ! in the name, but no matching rule",
460 devpath => "/devices/virtual/block/fake!blockdev0",
461 exp_name => "fake/blockdev0" ,
462 exp_rem_error => "yes",
464 KERNEL=="ttyACM0", SYMLINK+="modem"
468 desc => "KERNELS rule",
469 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
470 exp_name => "scsi-0:0:0:0",
472 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
473 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
474 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
475 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
476 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
480 desc => "KERNELS wildcard all",
481 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
482 exp_name => "scsi-0:0:0:0",
484 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
485 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
486 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
487 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
488 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
492 desc => "KERNELS wildcard partial",
493 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
494 exp_name => "scsi-0:0:0:0",
496 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
497 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
501 desc => "KERNELS wildcard partial 2",
502 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
503 exp_name => "scsi-0:0:0:0",
505 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
506 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
510 desc => "substitute attr with link target value (first match)",
511 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
512 exp_name => "driver-is-sd",
514 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
518 desc => "substitute attr with link target value (currently selected device)",
519 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
520 exp_name => "driver-is-ahci",
522 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
526 desc => "ignore ATTRS attribute whitespace",
527 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
528 exp_name => "ignored",
530 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
534 desc => "do not ignore ATTRS attribute whitespace",
535 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
536 exp_name => "matched-with-space",
538 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
539 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
543 desc => "permissions USER=bad GROUP=name",
544 devpath => "/devices/virtual/tty/tty33",
546 exp_perms => "0:0:0600",
548 KERNEL=="tty33", OWNER="bad", GROUP="name"
552 desc => "permissions OWNER=1",
553 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
555 exp_perms => "1::0600",
557 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
561 desc => "permissions GROUP=1",
562 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
564 exp_perms => ":1:0660",
566 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
570 desc => "textual user id",
571 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
573 exp_perms => "nobody::0600",
575 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
579 desc => "textual group id",
580 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
582 exp_perms => ":daemon:0660",
584 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
588 desc => "textual user/group id",
589 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
591 exp_perms => "root:mail:0660",
593 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
597 desc => "permissions MODE=0777",
598 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
600 exp_perms => "::0777",
602 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
606 desc => "permissions OWNER=1 GROUP=1 MODE=0777",
607 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
609 exp_perms => "1:1:0777",
611 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
615 desc => "permissions OWNER to 1",
616 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
617 exp_name => "ttyACM0",
620 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
624 desc => "permissions GROUP to 1",
625 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
626 exp_name => "ttyACM0",
627 exp_perms => ":1:0660",
629 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
633 desc => "permissions MODE to 0060",
634 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
635 exp_name => "ttyACM0",
636 exp_perms => "::0060",
638 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
642 desc => "permissions OWNER, GROUP, MODE",
643 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
644 exp_name => "ttyACM0",
645 exp_perms => "1:1:0777",
647 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
651 desc => "permissions only rule",
652 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
653 exp_name => "ttyACM0",
654 exp_perms => "1:1:0777",
656 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
657 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
658 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
662 desc => "multiple permissions only rule",
663 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
664 exp_name => "ttyACM0",
665 exp_perms => "1:1:0777",
667 SUBSYSTEM=="tty", OWNER="1"
668 SUBSYSTEM=="tty", GROUP="1"
669 SUBSYSTEM=="tty", MODE="0777"
670 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
671 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
675 desc => "permissions only rule with override at SYMLINK+ rule",
676 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
677 exp_name => "ttyACM0",
678 exp_perms => "1:2:0777",
680 SUBSYSTEM=="tty", OWNER="1"
681 SUBSYSTEM=="tty", GROUP="1"
682 SUBSYSTEM=="tty", MODE="0777"
683 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
684 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
688 desc => "major/minor number test",
689 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
691 exp_majorminor => "8:0",
693 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
697 desc => "big major number test",
698 devpath => "/devices/virtual/misc/misc-fake1",
700 exp_majorminor => "4095:1",
702 KERNEL=="misc-fake1", SYMLINK+="node"
706 desc => "big major and big minor number test",
707 devpath => "/devices/virtual/misc/misc-fake89999",
709 exp_majorminor => "4095:89999",
711 KERNEL=="misc-fake89999", SYMLINK+="node"
715 desc => "multiple symlinks with format char",
716 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
717 exp_name => "symlink2-ttyACM0",
719 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
723 desc => "multiple symlinks with a lot of s p a c e s",
724 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
728 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
732 desc => "symlink creation (same directory)",
733 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
734 exp_name => "modem0",
736 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
740 desc => "multiple symlinks",
741 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
742 exp_name => "second-0" ,
744 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
748 desc => "symlink name '.'",
749 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
751 exp_add_error => "yes",
752 exp_rem_error => "yes",
754 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
758 desc => "symlink node to itself",
759 devpath => "/devices/virtual/tty/tty0",
761 exp_add_error => "yes",
762 exp_rem_error => "yes",
765 KERNEL=="tty0", SYMLINK+="tty0"
769 desc => "symlink %n substitution",
770 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
771 exp_name => "symlink0",
773 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
777 desc => "symlink %k substitution",
778 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
779 exp_name => "symlink-ttyACM0",
781 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
785 desc => "symlink %M:%m substitution",
786 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
787 exp_name => "major-166:0",
789 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
793 desc => "symlink %b substitution",
794 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
795 exp_name => "symlink-0:0:0:0",
797 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
801 desc => "symlink %c substitution",
802 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
805 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
809 desc => "symlink %c{N} substitution",
810 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
813 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
817 desc => "symlink %c{N+} substitution",
818 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
821 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
825 desc => "symlink only rule with %c{N+}",
826 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
829 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
833 desc => "symlink %s{filename} substitution",
834 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
837 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
841 desc => "program result substitution (numbered part of)",
842 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
845 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
849 desc => "program result substitution (numbered part of+)",
850 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
853 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
857 desc => "SUBSYSTEM match test",
858 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
861 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
862 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
863 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
867 desc => "DRIVERS match test",
868 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
871 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
872 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
876 desc => "devnode substitution test",
877 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
880 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
884 desc => "parent node name substitution test",
885 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
886 exp_name => "sda-part-1",
888 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
892 desc => "udev_root substitution",
893 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
894 exp_name => "start-/dev-end",
896 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
900 desc => "last_rule option",
901 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
904 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
905 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
909 desc => "negation KERNEL!=",
910 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
913 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
914 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
915 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
919 desc => "negation SUBSYSTEM!=",
920 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
921 exp_name => "not-anything",
923 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
924 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
925 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
929 desc => "negation PROGRAM!= exit code",
930 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
931 exp_name => "nonzero-program",
933 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
934 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
938 desc => "ENV{} test",
939 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
942 ENV{ENV_KEY_TEST}="test"
943 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
944 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
945 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
949 desc => "ENV{} test",
950 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
953 ENV{ENV_KEY_TEST}="test"
954 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
955 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
956 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
957 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
961 desc => "ENV{} test (assign)",
962 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
965 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
966 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
967 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
968 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
972 desc => "ENV{} test (assign 2 times)",
973 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
976 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
977 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
978 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
979 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
980 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
984 desc => "ENV{} test (assign2)",
985 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
988 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
989 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
990 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
991 SUBSYSTEM=="block", SYMLINK+="before"
992 ENV{PARTITION}=="true", SYMLINK+="part"
996 desc => "untrusted string sanitize",
997 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1000 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1004 desc => "untrusted string sanitize (don't replace utf8)",
1005 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1008 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1012 desc => "untrusted string sanitize (replace invalid utf8)",
1013 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1014 exp_name => "replaced",
1016 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1020 desc => "read sysfs value from parent device",
1021 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1022 exp_name => "serial-354172020305000",
1024 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1028 desc => "match against empty key string",
1029 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1032 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1033 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1034 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1035 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1039 desc => "check ACTION value",
1040 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1043 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1044 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1048 desc => "final assignment",
1049 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1051 exp_perms => "root:tty:0640",
1053 KERNEL=="sda", GROUP:="tty"
1054 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1058 desc => "final assignment 2",
1059 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1061 exp_perms => "root:tty:0640",
1063 KERNEL=="sda", GROUP:="tty"
1064 SUBSYSTEM=="block", MODE:="640"
1065 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1069 desc => "env substitution",
1070 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1071 exp_name => "node-add-me",
1073 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1077 desc => "reset list to current value",
1078 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1079 exp_name => "three",
1080 not_exp_name => "two",
1082 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1083 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1084 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1088 desc => "test empty SYMLINK+ (empty override)",
1089 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1090 exp_name => "right",
1091 not_exp_name => "wrong",
1093 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1094 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1095 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1099 desc => "test multi matches",
1100 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1101 exp_name => "right",
1103 KERNEL=="ttyACM*", SYMLINK+="before"
1104 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1108 desc => "test multi matches 2",
1109 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1110 exp_name => "right",
1112 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1113 KERNEL=="ttyACM*", SYMLINK+="before"
1114 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1118 desc => "test multi matches 3",
1119 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1120 exp_name => "right",
1122 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1123 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1124 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1125 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1129 desc => "test multi matches 4",
1130 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1131 exp_name => "right",
1133 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1134 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1135 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1136 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1137 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1141 desc => "IMPORT parent test sequence 1/2 (keep)",
1142 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1143 exp_name => "parent",
1146 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1147 KERNEL=="sda", SYMLINK+="parent"
1151 desc => "IMPORT parent test sequence 2/2 (keep)",
1152 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1153 exp_name => "parentenv-parent_right",
1156 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1160 desc => "GOTO test",
1161 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1162 exp_name => "right",
1164 KERNEL=="sda1", GOTO="TEST"
1165 KERNEL=="sda1", SYMLINK+="wrong"
1166 KERNEL=="sda1", GOTO="BAD"
1167 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1168 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1169 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1174 desc => "GOTO label does not exist",
1175 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1176 exp_name => "right",
1178 KERNEL=="sda1", GOTO="does-not-exist"
1179 KERNEL=="sda1", SYMLINK+="right",
1184 desc => "SYMLINK+ compare test",
1185 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1186 exp_name => "right",
1187 not_exp_name => "wrong",
1189 KERNEL=="sda1", SYMLINK+="link"
1190 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1191 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1195 desc => "invalid key operation",
1196 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1199 KERNEL="sda1", SYMLINK+="no"
1200 KERNEL=="sda1", SYMLINK+="yes"
1204 desc => "operator chars in attribute",
1205 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1208 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1212 desc => "overlong comment line",
1213 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1216 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1217 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1218 KERNEL=="sda1", SYMLINK+=="no"
1219 KERNEL=="sda1", SYMLINK+="yes"
1223 desc => "magic subsys/kernel lookup",
1224 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1225 exp_name => "00:16:41:e2:8d:ff",
1227 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1231 desc => "TEST absolute path",
1232 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1233 exp_name => "there",
1235 TEST=="/etc/hosts", SYMLINK+="there"
1236 TEST!="/etc/hosts", SYMLINK+="notthere"
1240 desc => "TEST subsys/kernel lookup",
1241 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1244 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1248 desc => "TEST relative path",
1249 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1250 exp_name => "relative",
1252 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1256 desc => "TEST wildcard substitution (find queue/nr_requests)",
1257 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1258 exp_name => "found-subdir",
1260 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1264 desc => "TEST MODE=0000",
1265 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1267 exp_perms => "0:0:0000",
1268 exp_rem_error => "yes",
1270 KERNEL=="sda", MODE="0000"
1274 desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
1275 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1277 exp_perms => "1:1:0400",
1278 exp_rem_error => "yes",
1280 KERNEL=="sda", MODE="666"
1281 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1285 desc => "TEST PROGRAM feeds MODE with overflow",
1286 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1288 exp_perms => "0:0:0440",
1289 exp_rem_error => "yes",
1291 KERNEL=="sda", MODE="440"
1292 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1296 desc => "magic [subsys/sysname] attribute substitution",
1297 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1298 exp_name => "sda-8741C4G-end",
1299 exp_perms => "0:0:0600",
1301 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1302 KERNEL=="sda", ENV{TESTENV}="change-envp"
1303 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1307 desc => "builtin path_id",
1308 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1309 exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1311 KERNEL=="sda", IMPORT{builtin}="path_id"
1312 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1318 my ($action, $devpath, $rules) = @_;
1320 # create temporary rules
1321 system("mkdir", "-p", "$udev_rules_dir");
1322 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1326 if ($valgrind > 0) {
1327 system("$udev_bin_valgrind $action $devpath");
1329 system("$udev_bin", "$action", "$devpath");
1335 sub permissions_test {
1336 my($rules, $uid, $gid, $mode) = @_;
1342 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1344 if (defined(getpwnam($1))) {
1345 $userid = int(getpwnam($1));
1349 if ($uid != $userid) { $wrong = 1; }
1352 if (defined(getgrnam($2))) {
1353 $groupid = int(getgrnam($2));
1357 if ($gid != $groupid) { $wrong = 1; }
1360 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1363 print "permissions: ok\n";
1365 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1366 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1367 print "permissions: error\n";
1373 sub major_minor_test {
1374 my($rules, $rdev) = @_;
1376 my $major = ($rdev >> 8) & 0xfff;
1377 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1380 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
1382 if ($major != $1) { $wrong = 1; };
1385 if ($minor != $2) { $wrong = 1; };
1388 print "major:minor: ok\n";
1390 printf " expected major:minor is: %i:%i\n", $1, $2;
1391 printf " created major:minor is : %i:%i\n", $major, $minor;
1392 print "major:minor: error\n";
1399 system("rm", "-rf", "$udev_dev");
1400 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1401 # setting group and mode of udev_dev ensures the tests work
1402 # even if the parent directory has setgid bit enabled.
1403 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1404 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1406 system("rm", "-rf", "$udev_run");
1410 my ($rules, $number) = @_;
1412 print "TEST $number: $rules->{desc}\n";
1413 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1415 udev("add", $rules->{devpath}, \$rules->{rules});
1416 if (defined($rules->{not_exp_name})) {
1417 if ((-e "$udev_dev/$rules->{not_exp_name}") ||
1418 (-l "$udev_dev/$rules->{not_exp_name}")) {
1419 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1425 if ((-e "$udev_dev/$rules->{exp_name}") ||
1426 (-l "$udev_dev/$rules->{exp_name}")) {
1428 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1429 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1431 if (defined($rules->{exp_perms})) {
1432 permissions_test($rules, $uid, $gid, $mode);
1434 if (defined($rules->{exp_majorminor})) {
1435 major_minor_test($rules, $rdev);
1440 if ($rules->{exp_add_error}) {
1441 print " as expected\n";
1444 system("tree", "$udev_dev");
1451 if (defined($rules->{option}) && $rules->{option} eq "keep") {
1456 udev("remove", $rules->{devpath}, \$rules->{rules});
1457 if ((-e "$udev_dev/$rules->{exp_name}") ||
1458 (-l "$udev_dev/$rules->{exp_name}")) {
1459 print "remove: error";
1460 if ($rules->{exp_rem_error}) {
1461 print " as expected\n";
1464 system("tree", "$udev_dev");
1470 print "remove: ok\n";
1475 if (defined($rules->{option}) && $rules->{option} eq "clean") {
1481 # only run if we have root permissions
1482 # due to mknod restrictions
1484 print "Must have root permissions to run properly.\n";
1493 foreach my $arg (@ARGV) {
1494 if ($arg =~ m/--valgrind/) {
1496 printf("using valgrind\n");
1503 foreach my $arg (@list) {
1504 if (defined($tests[$arg-1]->{desc})) {
1505 print "udev-test will run test number $arg:\n\n";
1506 run_test($tests[$arg-1], $arg);
1508 print "test does not exist.\n";
1513 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1515 foreach my $rules (@tests) {
1516 run_test($rules, $test_num);
1521 print "$error errors occurred\n\n";
1524 system("rm", "-rf", "$udev_dev");
1525 system("rm", "-rf", "$udev_run");