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";
30 my $EXIT_TEST_SKIP = 77;
35 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
37 exp_rem_error => "yes",
43 desc => "label test of scsi disc",
44 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
45 exp_name => "boot_disk" ,
47 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
48 KERNEL=="ttyACM0", SYMLINK+="modem"
52 desc => "label test of scsi disc",
53 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
54 exp_name => "boot_disk" ,
56 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
57 KERNEL=="ttyACM0", SYMLINK+="modem"
61 desc => "label test of scsi disc",
62 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
63 exp_name => "boot_disk" ,
65 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
66 KERNEL=="ttyACM0", SYMLINK+="modem"
70 desc => "label test of scsi partition",
71 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
72 exp_name => "boot_disk1" ,
74 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n"
78 desc => "label test of pattern match",
79 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
80 exp_name => "boot_disk1" ,
82 SUBSYSTEMS=="scsi", ATTRS{vendor}=="?ATA", SYMLINK+="boot_disk%n-1"
83 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA?", SYMLINK+="boot_disk%n-2"
84 SUBSYSTEMS=="scsi", ATTRS{vendor}=="A??", SYMLINK+="boot_disk%n"
85 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATAS", SYMLINK+="boot_disk%n-3"
89 desc => "label test of multiple sysfs files",
90 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
91 exp_name => "boot_disk1" ,
93 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS X ", SYMLINK+="boot_diskX%n"
94 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", SYMLINK+="boot_disk%n"
98 desc => "label test of max sysfs files (skip invalid rule)",
99 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
100 exp_name => "boot_disk1" ,
102 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"
103 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
107 desc => "catch device by *",
108 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
109 exp_name => "modem/0" ,
111 KERNEL=="ttyACM*", SYMLINK+="modem/%n"
115 desc => "catch device by * - take 2",
116 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
117 exp_name => "modem/0" ,
119 KERNEL=="*ACM1", SYMLINK+="bad"
120 KERNEL=="*ACM0", SYMLINK+="modem/%n"
124 desc => "catch device by ?",
125 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
126 exp_name => "modem/0" ,
128 KERNEL=="ttyACM??*", SYMLINK+="modem/%n-1"
129 KERNEL=="ttyACM??", SYMLINK+="modem/%n-2"
130 KERNEL=="ttyACM?", SYMLINK+="modem/%n"
134 desc => "catch device by character class",
135 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
136 exp_name => "modem/0" ,
138 KERNEL=="ttyACM[A-Z]*", SYMLINK+="modem/%n-1"
139 KERNEL=="ttyACM?[0-9]", SYMLINK+="modem/%n-2"
140 KERNEL=="ttyACM[0-9]*", SYMLINK+="modem/%n"
144 desc => "replace kernel name",
145 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
146 exp_name => "modem" ,
148 KERNEL=="ttyACM0", SYMLINK+="modem"
152 desc => "Handle comment lines in config file (and replace kernel name)",
153 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
154 exp_name => "modem" ,
157 KERNEL=="ttyACM0", SYMLINK+="modem"
162 desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
163 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
164 exp_name => "modem" ,
166 # this is a comment with whitespace before the comment
167 KERNEL=="ttyACM0", SYMLINK+="modem"
172 desc => "Handle whitespace only lines (and replace kernel name)",
173 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
174 exp_name => "whitespace" ,
179 # this is a comment with whitespace before the comment
180 KERNEL=="ttyACM0", SYMLINK+="whitespace"
187 desc => "Handle empty lines in config file (and replace kernel name)",
188 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
189 exp_name => "modem" ,
192 KERNEL=="ttyACM0", SYMLINK+="modem"
197 desc => "Handle backslashed multi lines in config file (and replace kernel name)",
198 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
199 exp_name => "modem" ,
201 KERNEL=="ttyACM0", \\
207 desc => "preserve backslashes, if they are not for a newline",
208 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
211 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", SYMLINK+="aaa"
215 desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
216 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
217 exp_name => "modem" ,
227 KERNEL=="ttyACM0", \\
233 desc => "subdirectory handling",
234 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
235 exp_name => "sub/direct/ory/modem" ,
237 KERNEL=="ttyACM0", SYMLINK+="sub/direct/ory/modem"
241 desc => "parent device name match of scsi partition",
242 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
243 exp_name => "first_disk5" ,
245 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="first_disk%n"
249 desc => "test substitution chars",
250 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
251 exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
253 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:%M:minor:%m:kernelnumber:%n:id:%b"
257 desc => "import of shell-value returned from program",
258 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
259 exp_name => "node12345678",
261 SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
262 KERNEL=="ttyACM0", SYMLINK+="modem"
266 desc => "sustitution of sysfs value (%s{file})",
267 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
268 exp_name => "disk-ATA-sda" ,
270 SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="disk-%s{vendor}-%k"
271 KERNEL=="ttyACM0", SYMLINK+="modem"
275 desc => "program result substitution",
276 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
277 exp_name => "special-device-5" ,
278 not_exp_name => "not" ,
280 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", SYMLINK+="not"
281 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", SYMLINK+="%c-%n"
285 desc => "program result substitution (newline removal)",
286 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
287 exp_name => "newline_removed" ,
289 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", SYMLINK+="newline_removed"
293 desc => "program result substitution",
294 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
295 exp_name => "test-0:0:0:0" ,
297 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", SYMLINK+="%c"
301 desc => "program with lots of arguments",
302 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
305 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
309 desc => "program with subshell",
310 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
313 SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
317 desc => "program arguments combined with apostrophes",
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'", KERNEL=="sda5", SYMLINK+="%c{5}"
325 desc => "characters before the %c{N} substitution",
326 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
327 exp_name => "my-foo9" ,
329 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
333 desc => "substitute the second to last argument",
334 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
335 exp_name => "my-foo8" ,
337 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
341 desc => "test substitution by variable name",
342 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
343 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
345 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
349 desc => "test substitution by variable name 2",
350 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
351 exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
353 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
357 desc => "test substitution by variable name 3",
358 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
359 exp_name => "850:0:0:05" ,
361 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="%M%m%b%n"
365 desc => "test substitution by variable name 4",
366 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
369 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major\$minor\$number"
373 desc => "test substitution by variable name 5",
374 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
375 exp_name => "8550:0:0:0" ,
377 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="\$major%m%n\$id"
381 desc => "non matching SUBSYSTEMS for device with no parent",
382 devpath => "/devices/virtual/tty/console",
385 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", SYMLINK+="foo"
386 KERNEL=="console", SYMLINK+="TTY"
390 desc => "non matching SUBSYSTEMS",
391 devpath => "/devices/virtual/tty/console",
394 SUBSYSTEMS=="foo", ATTRS{dev}=="5:1", SYMLINK+="foo"
395 KERNEL=="console", SYMLINK+="TTY"
399 desc => "ATTRS match",
400 devpath => "/devices/virtual/tty/console",
403 KERNEL=="console", SYMLINK+="TTY"
404 ATTRS{dev}=="5:1", SYMLINK+="foo"
408 desc => "ATTR (empty file)",
409 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
410 exp_name => "empty" ,
412 KERNEL=="sda", ATTR{test_empty_file}=="?*", SYMLINK+="something"
413 KERNEL=="sda", ATTR{test_empty_file}!="", SYMLINK+="not-empty"
414 KERNEL=="sda", ATTR{test_empty_file}=="", SYMLINK+="empty"
415 KERNEL=="sda", ATTR{test_empty_file}!="?*", SYMLINK+="not-something"
419 desc => "ATTR (non-existent file)",
420 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
421 exp_name => "non-existent" ,
423 KERNEL=="sda", ATTR{nofile}=="?*", SYMLINK+="something"
424 KERNEL=="sda", ATTR{nofile}!="", SYMLINK+="not-empty"
425 KERNEL=="sda", ATTR{nofile}=="", SYMLINK+="empty"
426 KERNEL=="sda", ATTR{nofile}!="?*", SYMLINK+="not-something"
427 KERNEL=="sda", TEST!="nofile", SYMLINK+="non-existent"
428 KERNEL=="sda", SYMLINK+="wrong"
432 desc => "program and bus type match",
433 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
434 exp_name => "scsi-0:0:0:0" ,
436 SUBSYSTEMS=="usb", PROGRAM=="/bin/echo -n usb-%b", SYMLINK+="%c"
437 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n scsi-%b", SYMLINK+="%c"
438 SUBSYSTEMS=="foo", PROGRAM=="/bin/echo -n foo-%b", SYMLINK+="%c"
442 desc => "sysfs parent hierarchy",
443 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
444 exp_name => "modem" ,
446 ATTRS{idProduct}=="007b", SYMLINK+="modem"
450 desc => "name test with ! in the name",
451 devpath => "/devices/virtual/block/fake!blockdev0",
452 exp_name => "is/a/fake/blockdev0" ,
454 SUBSYSTEMS=="scsi", SYMLINK+="is/not/a/%k"
455 SUBSYSTEM=="block", SYMLINK+="is/a/%k"
456 KERNEL=="ttyACM0", SYMLINK+="modem"
460 desc => "name test with ! in the name, but no matching rule",
461 devpath => "/devices/virtual/block/fake!blockdev0",
462 exp_name => "fake/blockdev0" ,
463 exp_rem_error => "yes",
465 KERNEL=="ttyACM0", SYMLINK+="modem"
469 desc => "KERNELS rule",
470 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
471 exp_name => "scsi-0:0:0:0",
473 SUBSYSTEMS=="usb", KERNELS=="0:0:0:0", SYMLINK+="not-scsi"
474 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:1", SYMLINK+="no-match"
475 SUBSYSTEMS=="scsi", KERNELS==":0", SYMLINK+="short-id"
476 SUBSYSTEMS=="scsi", KERNELS=="/0:0:0:0", SYMLINK+="no-match"
477 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="scsi-0:0:0:0"
481 desc => "KERNELS wildcard all",
482 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
483 exp_name => "scsi-0:0:0:0",
485 SUBSYSTEMS=="scsi", KERNELS=="*:1", SYMLINK+="no-match"
486 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", SYMLINK+="no-match"
487 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", SYMLINK+="no-match"
488 SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", SYMLINK+="before"
489 SUBSYSTEMS=="scsi", KERNELS=="*", SYMLINK+="scsi-0:0:0:0"
493 desc => "KERNELS wildcard partial",
494 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
495 exp_name => "scsi-0:0:0:0",
497 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
498 SUBSYSTEMS=="scsi", KERNELS=="*:0", SYMLINK+="scsi-0:0:0:0"
502 desc => "KERNELS wildcard partial 2",
503 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
504 exp_name => "scsi-0:0:0:0",
506 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="before"
507 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", SYMLINK+="scsi-0:0:0:0"
511 desc => "substitute attr with link target value (first match)",
512 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
513 exp_name => "driver-is-sd",
515 SUBSYSTEMS=="scsi", SYMLINK+="driver-is-\$attr{driver}"
519 desc => "substitute attr with link target value (currently selected device)",
520 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
521 exp_name => "driver-is-ahci",
523 SUBSYSTEMS=="pci", SYMLINK+="driver-is-\$attr{driver}"
527 desc => "ignore ATTRS attribute whitespace",
528 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
529 exp_name => "ignored",
531 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE", SYMLINK+="ignored"
535 desc => "do not ignore ATTRS attribute whitespace",
536 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
537 exp_name => "matched-with-space",
539 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="wrong-to-ignore"
540 SUBSYSTEMS=="scsi", ATTRS{whitespace_test}=="WHITE SPACE ", SYMLINK+="matched-with-space"
544 desc => "permissions USER=bad GROUP=name",
545 devpath => "/devices/virtual/tty/tty33",
547 exp_perms => "0:0:0600",
549 KERNEL=="tty33", OWNER="bad", GROUP="name"
553 desc => "permissions OWNER=1",
554 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
556 exp_perms => "1::0600",
558 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1"
562 desc => "permissions GROUP=1",
563 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
565 exp_perms => ":1:0660",
567 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="1"
571 desc => "textual user id",
572 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
574 exp_perms => "nobody::0600",
576 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="nobody"
580 desc => "textual group id",
581 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
583 exp_perms => ":daemon:0660",
585 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", GROUP="daemon"
589 desc => "textual user/group id",
590 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
592 exp_perms => "root:mail:0660",
594 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="root", GROUP="mail"
598 desc => "permissions MODE=0777",
599 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
601 exp_perms => "::0777",
603 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", MODE="0777"
607 desc => "permissions OWNER=1 GROUP=1 MODE=0777",
608 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
610 exp_perms => "1:1:0777",
612 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", OWNER="1", GROUP="1", MODE="0777"
616 desc => "permissions OWNER to 1",
617 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
618 exp_name => "ttyACM0",
621 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1"
625 desc => "permissions GROUP to 1",
626 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
627 exp_name => "ttyACM0",
628 exp_perms => ":1:0660",
630 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="1"
634 desc => "permissions MODE to 0060",
635 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
636 exp_name => "ttyACM0",
637 exp_perms => "::0060",
639 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", MODE="0060"
643 desc => "permissions OWNER, GROUP, MODE",
644 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
645 exp_name => "ttyACM0",
646 exp_perms => "1:1:0777",
648 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", OWNER="1", GROUP="1", MODE="0777"
652 desc => "permissions only rule",
653 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
654 exp_name => "ttyACM0",
655 exp_perms => "1:1:0777",
657 KERNEL=="ttyACM[0-9]*", OWNER="1", GROUP="1", MODE="0777"
658 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
659 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
663 desc => "multiple permissions only rule",
664 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
665 exp_name => "ttyACM0",
666 exp_perms => "1:1:0777",
668 SUBSYSTEM=="tty", OWNER="1"
669 SUBSYSTEM=="tty", GROUP="1"
670 SUBSYSTEM=="tty", MODE="0777"
671 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
672 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n"
676 desc => "permissions only rule with override at SYMLINK+ rule",
677 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
678 exp_name => "ttyACM0",
679 exp_perms => "1:2:0777",
681 SUBSYSTEM=="tty", OWNER="1"
682 SUBSYSTEM=="tty", GROUP="1"
683 SUBSYSTEM=="tty", MODE="0777"
684 KERNEL=="ttyUSX[0-9]*", OWNER="2", GROUP="2", MODE="0444"
685 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", GROUP="2"
689 desc => "major/minor number test",
690 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
692 exp_majorminor => "8:0",
694 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node"
698 desc => "big major number test",
699 devpath => "/devices/virtual/misc/misc-fake1",
701 exp_majorminor => "4095:1",
703 KERNEL=="misc-fake1", SYMLINK+="node"
707 desc => "big major and big minor number test",
708 devpath => "/devices/virtual/misc/misc-fake89999",
710 exp_majorminor => "4095:89999",
712 KERNEL=="misc-fake89999", SYMLINK+="node"
716 desc => "multiple symlinks with format char",
717 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
718 exp_name => "symlink2-ttyACM0",
720 KERNEL=="ttyACM[0-9]*", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
724 desc => "multiple symlinks with a lot of s p a c e s",
725 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
729 KERNEL=="ttyACM[0-9]*", SYMLINK=" one two "
733 desc => "symlink creation (same directory)",
734 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
735 exp_name => "modem0",
737 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
741 desc => "multiple symlinks",
742 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
743 exp_name => "second-0" ,
745 KERNEL=="ttyACM0", SYMLINK="first-%n second-%n third-%n"
749 desc => "symlink name '.'",
750 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
752 exp_add_error => "yes",
753 exp_rem_error => "yes",
755 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="."
759 desc => "symlink node to itself",
760 devpath => "/devices/virtual/tty/tty0",
762 exp_add_error => "yes",
763 exp_rem_error => "yes",
766 KERNEL=="tty0", SYMLINK+="tty0"
770 desc => "symlink %n substitution",
771 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
772 exp_name => "symlink0",
774 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink%n"
778 desc => "symlink %k substitution",
779 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
780 exp_name => "symlink-ttyACM0",
782 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="symlink-%k"
786 desc => "symlink %M:%m substitution",
787 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
788 exp_name => "major-166:0",
790 KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK+="major-%M:%m"
794 desc => "symlink %b substitution",
795 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
796 exp_name => "symlink-0:0:0:0",
798 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
802 desc => "symlink %c substitution",
803 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
806 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo test", SYMLINK+="%c"
810 desc => "symlink %c{N} substitution",
811 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
814 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2}"
818 desc => "symlink %c{N+} substitution",
819 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
822 KERNEL=="ttyACM[0-9]*", PROGRAM=="/bin/echo symlink test this", SYMLINK+="%c{2+}"
826 desc => "symlink only rule with %c{N+}",
827 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
830 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo link test this" SYMLINK+="%c{2+}"
834 desc => "symlink %s{filename} substitution",
835 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
838 KERNEL=="ttyACM[0-9]*", SYMLINK+="%s{dev}"
842 desc => "program result substitution (numbered part of)",
843 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
846 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
850 desc => "program result substitution (numbered part of+)",
851 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
854 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
858 desc => "SUBSYSTEM match test",
859 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
862 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", SUBSYSTEM=="vc"
863 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", SUBSYSTEM=="block"
864 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match2", SUBSYSTEM=="vc"
868 desc => "DRIVERS match test",
869 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
872 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="should_not_match", DRIVERS=="sd-wrong"
873 SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="node", DRIVERS=="sd"
877 desc => "devnode substitution test",
878 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
881 SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/usr/bin/test -b %N" SYMLINK+="node"
885 desc => "parent node name substitution test",
886 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
887 exp_name => "sda-part-1",
889 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
893 desc => "udev_root substitution",
894 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
895 exp_name => "start-/dev-end",
897 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="start-%r-end"
901 desc => "last_rule option",
902 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
905 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="last", OPTIONS="last_rule"
906 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="very-last"
910 desc => "negation KERNEL!=",
911 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
914 SUBSYSTEMS=="scsi", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
915 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
916 SUBSYSTEMS=="scsi", KERNEL!="xsda1", SYMLINK+="match"
920 desc => "negation SUBSYSTEM!=",
921 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
922 exp_name => "not-anything",
924 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", SYMLINK+="matches-but-is-negated"
925 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
926 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", SYMLINK+="not-anything"
930 desc => "negation PROGRAM!= exit code",
931 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
932 exp_name => "nonzero-program",
934 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
935 KERNEL=="sda1", PROGRAM!="/bin/false", SYMLINK+="nonzero-program"
939 desc => "ENV{} test",
940 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
943 ENV{ENV_KEY_TEST}="test"
944 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
945 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", SYMLINK+="true"
946 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
950 desc => "ENV{} test",
951 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
954 ENV{ENV_KEY_TEST}="test"
955 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", SYMLINK+="wrong"
956 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
957 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
958 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", SYMLINK+="bad"
962 desc => "ENV{} test (assign)",
963 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
966 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
967 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
968 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
969 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", SYMLINK+="true"
973 desc => "ENV{} test (assign 2 times)",
974 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
977 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
978 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
979 SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="before"
980 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", SYMLINK+="no"
981 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", SYMLINK+="true"
985 desc => "ENV{} test (assign2)",
986 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
989 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
990 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
991 ENV{MAINDEVICE}=="true", SYMLINK+="disk"
992 SUBSYSTEM=="block", SYMLINK+="before"
993 ENV{PARTITION}=="true", SYMLINK+="part"
997 desc => "untrusted string sanitize",
998 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1001 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
1005 desc => "untrusted string sanitize (don't replace utf8)",
1006 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1009 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
1013 desc => "untrusted string sanitize (replace invalid utf8)",
1014 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1015 exp_name => "replaced",
1017 SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
1021 desc => "read sysfs value from parent device",
1022 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1023 exp_name => "serial-354172020305000",
1025 KERNEL=="ttyACM*", ATTRS{serial}=="?*", SYMLINK+="serial-%s{serial}"
1029 desc => "match against empty key string",
1030 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1033 KERNEL=="sda", ATTRS{nothing}!="", SYMLINK+="not-1-ok"
1034 KERNEL=="sda", ATTRS{nothing}=="", SYMLINK+="not-2-ok"
1035 KERNEL=="sda", ATTRS{vendor}!="", SYMLINK+="ok"
1036 KERNEL=="sda", ATTRS{vendor}=="", SYMLINK+="not-3-ok"
1040 desc => "check ACTION value",
1041 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1044 ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
1045 ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
1049 desc => "final assignment",
1050 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1052 exp_perms => "root:tty:0640",
1054 KERNEL=="sda", GROUP:="tty"
1055 KERNEL=="sda", GROUP="not-ok", MODE="0640", SYMLINK+="ok"
1059 desc => "final assignment 2",
1060 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1062 exp_perms => "root:tty:0640",
1064 KERNEL=="sda", GROUP:="tty"
1065 SUBSYSTEM=="block", MODE:="640"
1066 KERNEL=="sda", GROUP="not-ok", MODE="0666", SYMLINK+="ok"
1070 desc => "env substitution",
1071 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1072 exp_name => "node-add-me",
1074 KERNEL=="sda", MODE="0666", SYMLINK+="node-\$env{ACTION}-me"
1078 desc => "reset list to current value",
1079 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1080 exp_name => "three",
1081 not_exp_name => "two",
1083 KERNEL=="ttyACM[0-9]*", SYMLINK+="one"
1084 KERNEL=="ttyACM[0-9]*", SYMLINK+="two"
1085 KERNEL=="ttyACM[0-9]*", SYMLINK="three"
1089 desc => "test empty SYMLINK+ (empty override)",
1090 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1091 exp_name => "right",
1092 not_exp_name => "wrong",
1094 KERNEL=="ttyACM[0-9]*", SYMLINK+="wrong"
1095 KERNEL=="ttyACM[0-9]*", SYMLINK=""
1096 KERNEL=="ttyACM[0-9]*", SYMLINK+="right"
1100 desc => "test multi matches",
1101 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1102 exp_name => "right",
1104 KERNEL=="ttyACM*", SYMLINK+="before"
1105 KERNEL=="ttyACM*|nothing", SYMLINK+="right"
1109 desc => "test multi matches 2",
1110 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1111 exp_name => "right",
1113 KERNEL=="dontknow*|*nothing", SYMLINK+="nomatch"
1114 KERNEL=="ttyACM*", SYMLINK+="before"
1115 KERNEL=="dontknow*|ttyACM*|nothing*", SYMLINK+="right"
1119 desc => "test multi matches 3",
1120 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1121 exp_name => "right",
1123 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1124 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1125 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1126 KERNEL=="dontknow|ttyACM0|nothing", SYMLINK+="right"
1130 desc => "test multi matches 4",
1131 devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
1132 exp_name => "right",
1134 KERNEL=="dontknow|nothing", SYMLINK+="nomatch"
1135 KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong1"
1136 KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", SYMLINK+="wrong2"
1137 KERNEL=="all|dontknow|ttyACM0", SYMLINK+="right"
1138 KERNEL=="ttyACM0a|nothing", SYMLINK+="wrong3"
1142 desc => "IMPORT parent test sequence 1/2 (keep)",
1143 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1144 exp_name => "parent",
1147 KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
1148 KERNEL=="sda", SYMLINK+="parent"
1152 desc => "IMPORT parent test sequence 2/2 (keep)",
1153 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1154 exp_name => "parentenv-parent_right",
1157 KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
1161 desc => "GOTO test",
1162 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1163 exp_name => "right",
1165 KERNEL=="sda1", GOTO="TEST"
1166 KERNEL=="sda1", SYMLINK+="wrong"
1167 KERNEL=="sda1", GOTO="BAD"
1168 KERNEL=="sda1", SYMLINK+="", LABEL="NO"
1169 KERNEL=="sda1", SYMLINK+="right", LABEL="TEST", GOTO="end"
1170 KERNEL=="sda1", SYMLINK+="wrong2", LABEL="BAD"
1175 desc => "GOTO label does not exist",
1176 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1177 exp_name => "right",
1179 KERNEL=="sda1", GOTO="does-not-exist"
1180 KERNEL=="sda1", SYMLINK+="right",
1185 desc => "SYMLINK+ compare test",
1186 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1187 exp_name => "right",
1188 not_exp_name => "wrong",
1190 KERNEL=="sda1", SYMLINK+="link"
1191 KERNEL=="sda1", SYMLINK=="link*", SYMLINK+="right"
1192 KERNEL=="sda1", SYMLINK=="nolink*", SYMLINK+="wrong"
1196 desc => "invalid key operation",
1197 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1200 KERNEL="sda1", SYMLINK+="no"
1201 KERNEL=="sda1", SYMLINK+="yes"
1205 desc => "operator chars in attribute",
1206 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1209 KERNEL=="sda", ATTR{test:colon+plus}=="?*", SYMLINK+="yes"
1213 desc => "overlong comment line",
1214 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
1217 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1218 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
1219 KERNEL=="sda1", SYMLINK+=="no"
1220 KERNEL=="sda1", SYMLINK+="yes"
1224 desc => "magic subsys/kernel lookup",
1225 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1226 exp_name => "00:16:41:e2:8d:ff",
1228 KERNEL=="sda", SYMLINK+="\$attr{[net/eth0]address}"
1232 desc => "TEST absolute path",
1233 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1234 exp_name => "there",
1236 TEST=="/etc/machine-id", SYMLINK+="there"
1237 TEST!="/etc/machine-id", SYMLINK+="notthere"
1241 desc => "TEST subsys/kernel lookup",
1242 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1245 KERNEL=="sda", TEST=="[net/eth0]", SYMLINK+="yes"
1249 desc => "TEST relative path",
1250 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1251 exp_name => "relative",
1253 KERNEL=="sda", TEST=="size", SYMLINK+="relative"
1257 desc => "TEST wildcard substitution (find queue/nr_requests)",
1258 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1259 exp_name => "found-subdir",
1261 KERNEL=="sda", TEST=="*/nr_requests", SYMLINK+="found-subdir"
1265 desc => "TEST MODE=0000",
1266 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1268 exp_perms => "0:0:0000",
1269 exp_rem_error => "yes",
1271 KERNEL=="sda", MODE="0000"
1275 desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
1276 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1278 exp_perms => "1:1:0400",
1279 exp_rem_error => "yes",
1281 KERNEL=="sda", MODE="666"
1282 KERNEL=="sda", PROGRAM=="/bin/echo 1 1 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1286 desc => "TEST PROGRAM feeds MODE with overflow",
1287 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1289 exp_perms => "0:0:0440",
1290 exp_rem_error => "yes",
1292 KERNEL=="sda", MODE="440"
1293 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
1297 desc => "magic [subsys/sysname] attribute substitution",
1298 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1299 exp_name => "sda-8741C4G-end",
1300 exp_perms => "0:0:0600",
1302 KERNEL=="sda", PROGRAM="/bin/true create-envp"
1303 KERNEL=="sda", ENV{TESTENV}="change-envp"
1304 KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end"
1308 desc => "builtin path_id",
1309 devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
1310 exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
1312 KERNEL=="sda", IMPORT{builtin}="path_id"
1313 KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
1319 my ($action, $devpath, $rules) = @_;
1321 # create temporary rules
1322 system("mkdir", "-p", "$udev_rules_dir");
1323 open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
1327 if ($valgrind > 0) {
1328 system("$udev_bin_valgrind $action $devpath");
1330 system("$udev_bin", "$action", "$devpath");
1336 sub permissions_test {
1337 my($rules, $uid, $gid, $mode) = @_;
1343 $rules->{exp_perms} =~ m/^(.*):(.*):(.*)$/;
1345 if (defined(getpwnam($1))) {
1346 $userid = int(getpwnam($1));
1350 if ($uid != $userid) { $wrong = 1; }
1353 if (defined(getgrnam($2))) {
1354 $groupid = int(getgrnam($2));
1358 if ($gid != $groupid) { $wrong = 1; }
1361 if (($mode & 07777) != oct($3)) { $wrong = 1; };
1364 print "permissions: ok\n";
1366 printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
1367 printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777;
1368 print "permissions: error\n";
1374 sub major_minor_test {
1375 my($rules, $rdev) = @_;
1377 my $major = ($rdev >> 8) & 0xfff;
1378 my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00);
1381 $rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
1383 if ($major != $1) { $wrong = 1; };
1386 if ($minor != $2) { $wrong = 1; };
1389 print "major:minor: ok\n";
1391 printf " expected major:minor is: %i:%i\n", $1, $2;
1392 printf " created major:minor is : %i:%i\n", $major, $minor;
1393 print "major:minor: error\n";
1400 system("rm", "-rf", "$udev_dev");
1401 mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
1402 # setting group and mode of udev_dev ensures the tests work
1403 # even if the parent directory has setgid bit enabled.
1404 chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
1405 chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
1407 system("rm", "-rf", "$udev_run");
1411 my ($rules, $number) = @_;
1413 print "TEST $number: $rules->{desc}\n";
1414 print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
1416 udev("add", $rules->{devpath}, \$rules->{rules});
1417 if (defined($rules->{not_exp_name})) {
1418 if ((-e "$udev_dev/$rules->{not_exp_name}") ||
1419 (-l "$udev_dev/$rules->{not_exp_name}")) {
1420 print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
1426 if ((-e "$udev_dev/$rules->{exp_name}") ||
1427 (-l "$udev_dev/$rules->{exp_name}")) {
1429 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
1430 $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$rules->{exp_name}");
1432 if (defined($rules->{exp_perms})) {
1433 permissions_test($rules, $uid, $gid, $mode);
1435 if (defined($rules->{exp_majorminor})) {
1436 major_minor_test($rules, $rdev);
1441 if ($rules->{exp_add_error}) {
1442 print " as expected\n";
1445 system("tree", "$udev_dev");
1452 if (defined($rules->{option}) && $rules->{option} eq "keep") {
1457 udev("remove", $rules->{devpath}, \$rules->{rules});
1458 if ((-e "$udev_dev/$rules->{exp_name}") ||
1459 (-l "$udev_dev/$rules->{exp_name}")) {
1460 print "remove: error";
1461 if ($rules->{exp_rem_error}) {
1462 print " as expected\n";
1465 system("tree", "$udev_dev");
1471 print "remove: ok\n";
1476 if (defined($rules->{option}) && $rules->{option} eq "clean") {
1482 # only run if we have root permissions
1483 # due to mknod restrictions
1485 print "Must have root permissions to run properly.\n";
1489 # skip the test when running in a container
1490 system("systemd-detect-virt", "-c", "-q");
1492 print "Running in a container, skipping the test.\n";
1493 exit($EXIT_TEST_SKIP);
1501 foreach my $arg (@ARGV) {
1502 if ($arg =~ m/--valgrind/) {
1504 printf("using valgrind\n");
1511 foreach my $arg (@list) {
1512 if (defined($tests[$arg-1]->{desc})) {
1513 print "udev-test will run test number $arg:\n\n";
1514 run_test($tests[$arg-1], $arg);
1516 print "test does not exist.\n";
1521 print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
1523 foreach my $rules (@tests) {
1524 run_test($rules, $test_num);
1529 print "$error errors occurred\n\n";
1532 system("rm", "-rf", "$udev_dev");
1533 system("rm", "-rf", "$udev_run");