# After creation and removal the result is checked against the
# expected value and the result is printed.
#
-# Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
+# Copyright (C) 2004-2011 Kay Sievers <kay.sievers@vrfy.org>
# Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
use warnings;
use strict;
my $PWD = $ENV{PWD};
-my $sysfs = "test/sys/";
-my $udev_bin = "udev/test-udev";
+my $sysfs = "test/sys";
+my $udev_bin = "src/test-udev";
my $valgrind = 0;
my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
-my $udev_root = "udev-root/";
+my $udev_root = "udev-root";
my $udev_conf = "udev-test.conf";
my $udev_rules = "udev-test.rules";
my @tests = (
{
desc => "no rules",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda" ,
exp_rem_error => "yes",
},
{
desc => "label test of scsi disc",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "boot_disk" ,
rules => <<EOF
},
{
desc => "label test of scsi disc",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "boot_disk" ,
rules => <<EOF
},
{
desc => "label test of scsi disc",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "boot_disk" ,
rules => <<EOF
},
{
desc => "label test of scsi partition",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "boot_disk1" ,
rules => <<EOF
},
{
desc => "label test of pattern match",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "boot_disk1" ,
rules => <<EOF
},
{
desc => "label test of multiple sysfs files",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "boot_disk1" ,
rules => <<EOF
},
{
desc => "label test of max sysfs files (skip invalid rule)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "boot_disk1" ,
rules => <<EOF
},
{
desc => "catch device by *",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem/0" ,
rules => <<EOF
},
{
desc => "catch device by * - take 2",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem/0" ,
rules => <<EOF
},
{
desc => "catch device by ?",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem/0" ,
rules => <<EOF
},
{
desc => "catch device by character class",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem/0" ,
rules => <<EOF
},
{
desc => "replace kernel name",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "Handle comment lines in config file (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
- # this is a comment with whitespace before the comment
+ # this is a comment with whitespace before the comment
KERNEL=="ttyACM0", SYMLINK+="modem"
EOF
},
{
desc => "Handle whitespace only lines (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "whitespace" ,
rules => <<EOF
-
- # this is a comment with whitespace before the comment
+
+ # this is a comment with whitespace before the comment
KERNEL=="ttyACM0", SYMLINK+="whitespace"
-
+
EOF
},
{
desc => "Handle empty lines in config file (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "Handle backslashed multi lines in config file (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "preserve backslashes, if they are not for a newline",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "aaa",
rules => <<EOF
},
{
desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "subdirectory handling",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "sub/direct/ory/modem" ,
rules => <<EOF
},
{
desc => "parent device name match of scsi partition",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "first_disk5" ,
rules => <<EOF
},
{
desc => "test substitution chars",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
rules => <<EOF
},
{
desc => "import of shell-value file",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "subdir/err/node" ,
rules => <<EOF
},
{
desc => "import of shell-value returned from program",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node12345678",
rules => <<EOF
-SUBSYSTEMS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
+SUBSYSTEMS=="scsi", IMPORT{program}="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
KERNEL=="ttyACM0", SYMLINK+="modem"
EOF
},
{
desc => "sustitution of sysfs value (%s{file})",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "disk-ATA-sda" ,
rules => <<EOF
},
{
desc => "program result substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "special-device-5" ,
not_exp_name => "not" ,
},
{
desc => "program result substitution (newline removal)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "newline_removed" ,
rules => <<EOF
},
{
desc => "program result substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "test-0:0:0:0" ,
rules => <<EOF
},
{
desc => "program with lots of arguments",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "foo9" ,
rules => <<EOF
},
{
desc => "program with subshell",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "bar9" ,
rules => <<EOF
},
{
desc => "program arguments combined with apostrophes",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "foo7" ,
rules => <<EOF
},
{
desc => "characters before the %c{N} substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "my-foo9" ,
rules => <<EOF
},
{
desc => "substitute the second to last argument",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "my-foo8" ,
rules => <<EOF
},
{
desc => "test substitution by variable name",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
rules => <<EOF
},
{
desc => "test substitution by variable name 2",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
rules => <<EOF
},
{
desc => "test substitution by variable name 3",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "850:0:0:05" ,
rules => <<EOF
},
{
desc => "test substitution by variable name 4",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "855" ,
rules => <<EOF
},
{
desc => "test substitution by variable name 5",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "8550:0:0:0" ,
rules => <<EOF
},
{
desc => "non matching SUBSYSTEMS for device with no parent",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "TTY",
rules => <<EOF
},
{
desc => "non matching SUBSYSTEMS",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "TTY" ,
rules => <<EOF
},
{
desc => "ATTRS match",
- subsys => "tty",
devpath => "/devices/virtual/tty/console",
exp_name => "foo" ,
rules => <<EOF
},
{
desc => "ATTR (empty file)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "empty" ,
rules => <<EOF
},
{
desc => "ATTR (non-existent file)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "non-existent" ,
rules => <<EOF
},
{
desc => "program and bus type match",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "scsi-0:0:0:0" ,
rules => <<EOF
},
{
desc => "sysfs parent hierarchy",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem" ,
rules => <<EOF
},
{
desc => "name test with ! in the name",
- subsys => "block",
devpath => "/devices/virtual/block/fake!blockdev0",
exp_name => "is/a/fake/blockdev0" ,
rules => <<EOF
},
{
desc => "name test with ! in the name, but no matching rule",
- subsys => "block",
devpath => "/devices/virtual/block/fake!blockdev0",
exp_name => "fake/blockdev0" ,
exp_rem_error => "yes",
},
{
desc => "KERNELS rule",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "scsi-0:0:0:0",
rules => <<EOF
},
{
desc => "KERNELS wildcard all",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "scsi-0:0:0:0",
rules => <<EOF
},
{
desc => "KERNELS wildcard partial",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "scsi-0:0:0:0",
rules => <<EOF
},
{
desc => "KERNELS wildcard partial 2",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "scsi-0:0:0:0",
rules => <<EOF
},
{
desc => "substitute attr with link target value (first match)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "driver-is-sd",
rules => <<EOF
},
{
desc => "substitute attr with link target value (currently selected device)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "driver-is-ahci",
rules => <<EOF
},
{
desc => "ignore ATTRS attribute whitespace",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "ignored",
rules => <<EOF
},
{
desc => "do not ignore ATTRS attribute whitespace",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "matched-with-space",
rules => <<EOF
},
{
desc => "permissions USER=bad GROUP=name",
- subsys => "tty",
devpath => "/devices/virtual/tty/tty33",
exp_name => "tty33",
exp_perms => "0:0:0600",
},
{
desc => "permissions OWNER=5000",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => "5000::0600",
},
{
desc => "permissions GROUP=100",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => ":100:0660",
},
{
desc => "textual user id",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => "nobody::0600",
},
{
desc => "textual group id",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => ":daemon:0660",
},
{
desc => "textual user/group id",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => "root:mail:0660",
},
{
desc => "permissions MODE=0777",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => "::0777",
},
{
desc => "permissions OWNER=5000 GROUP=100 MODE=0777",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_perms => "5000:100:0777",
},
{
desc => "permissions OWNER to 5000",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "5000::",
},
{
desc => "permissions GROUP to 100",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => ":100:0660",
},
{
desc => "permissions MODE to 0060",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "::0060",
},
{
desc => "permissions OWNER, GROUP, MODE",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "5000:100:0777",
},
{
desc => "permissions only rule",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "5000:100:0777",
},
{
desc => "multiple permissions only rule",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "3000:4000:0777",
},
{
desc => "permissions only rule with override at SYMLINK+ rule",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "ttyACM0",
exp_perms => "3000:8000:0777",
},
{
desc => "major/minor number test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
exp_majorminor => "8:0",
},
{
desc => "big major number test",
- subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake1",
exp_name => "node",
exp_majorminor => "4095:1",
},
{
desc => "big major and big minor number test",
- subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake89999",
exp_name => "node",
exp_majorminor => "4095:89999",
},
{
desc => "multiple symlinks with format char",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "symlink2-ttyACM0",
rules => <<EOF
},
{
desc => "multiple symlinks with a lot of s p a c e s",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "one",
not_exp_name => " ",
},
{
desc => "symlink creation (same directory)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "modem0",
rules => <<EOF
KERNEL=="ttyACM[0-9]*", SYMLINK+="ttyACM%n", SYMLINK="modem%n"
-EOF
- },
- {
- desc => "symlink creation (relative link forward)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
- exp_name => "1/2/symlink" ,
- exp_target => "a/b/node",
- exp_rem_error => "yes",
- rules => <<EOF
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/symlink"
-EOF
- },
- {
- desc => "symlink creation (relative link back and forward)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6",
- exp_name => "1/2/c/d/symlink" ,
- exp_target => "../../a/b/node",
- exp_rem_error => "yes",
- rules => <<EOF
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="1/2/a/b/node", SYMLINK+="1/2/c/d/symlink"
EOF
},
{
desc => "multiple symlinks",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "second-0" ,
rules => <<EOF
},
{
desc => "symlink name '.'",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => ".",
exp_add_error => "yes",
},
{
desc => "symlink node to itself",
- subsys => "tty",
devpath => "/devices/virtual/tty/tty0",
exp_name => "link",
exp_add_error => "yes",
},
{
desc => "symlink %n substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "symlink0",
rules => <<EOF
},
{
desc => "symlink %k substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "symlink-ttyACM0",
rules => <<EOF
},
{
desc => "symlink %M:%m substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "major-166:0",
rules => <<EOF
},
{
desc => "symlink %b substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "symlink-0:0:0:0",
- exp_target => "node",
rules => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", SYMLINK+="symlink-%b"
+SUBSYSTEMS=="scsi", KERNEL=="sda", SYMLINK+="symlink-%b"
EOF
},
{
desc => "symlink %c substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "test",
rules => <<EOF
},
{
desc => "symlink %c{N} substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "test",
rules => <<EOF
},
{
desc => "symlink %c{N+} substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "this",
rules => <<EOF
},
{
desc => "symlink only rule with %c{N+}",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "test",
rules => <<EOF
},
{
desc => "symlink %s{filename} substitution",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "166:0",
rules => <<EOF
},
{
desc => "program result substitution (numbered part of)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "link1",
rules => <<EOF
},
{
desc => "program result substitution (numbered part of+)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
exp_name => "link4",
rules => <<EOF
},
{
desc => "SUBSYSTEM match test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
rules => <<EOF
},
{
desc => "DRIVERS match test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
rules => <<EOF
EOF
},
{
- desc => "temporary node creation test",
- subsys => "block",
+ desc => "devnode substitution test",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node",
rules => <<EOF
EOF
},
{
- desc => "parent node name substitution test sequence 1/2 (keep)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
- exp_name => "main_device",
- option => "keep",
- exp_rem_error => "yes",
- rules => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="main_device"
-EOF
- },
- {
- desc => "parent node name substitution test sequence 2/2 (clean)",
- subsys => "block",
+ desc => "parent node name substitution test",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
- exp_name => "main_device-part-1",
- option => "clean",
+ exp_name => "sda-part-1",
rules => <<EOF
SUBSYSTEMS=="scsi", KERNEL=="sda1", SYMLINK+="%P-part-1"
EOF
},
{
desc => "udev_root substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "start-udev-root-end",
rules => <<EOF
},
{
desc => "last_rule option",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "last",
rules => <<EOF
},
{
desc => "negation KERNEL!=",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "match",
rules => <<EOF
},
{
desc => "negation SUBSYSTEM!=",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "not-anything",
rules => <<EOF
},
{
desc => "negation PROGRAM!= exit code",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "nonzero-program",
rules => <<EOF
},
{
desc => "test for whitespace between the operator",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "true",
rules => <<EOF
},
{
desc => "ENV{} test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "true",
rules => <<EOF
},
{
desc => "ENV{} test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "true",
rules => <<EOF
},
{
desc => "ENV{} test (assign)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "true",
rules => <<EOF
},
{
desc => "ENV{} test (assign 2 times)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "true",
rules => <<EOF
},
{
desc => "ENV{} test (assign2)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "part",
rules => <<EOF
},
{
desc => "untrusted string sanitize",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "sane",
rules => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", SYMLINK+="sane"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/usr/bin/badprogram)", RESULT=="name_ _/usr/bin/badprogram_", SYMLINK+="sane"
EOF
},
{
desc => "untrusted string sanitize (don't replace utf8)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "uber",
rules => <<EOF
},
{
desc => "untrusted string sanitize (replace invalid utf8)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "replaced",
rules => <<EOF
},
{
desc => "read sysfs value from parent device",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "serial-354172020305000",
rules => <<EOF
},
{
desc => "match against empty key string",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "ok",
rules => <<EOF
},
{
desc => "check ACTION value",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "ok",
rules => <<EOF
ACTION=="unknown", KERNEL=="sda", SYMLINK+="unknown-not-ok"
ACTION=="add", KERNEL=="sda", SYMLINK+="ok"
-EOF
- },
- {
- desc => "test RUN key remove",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
- exp_name => "testsymlink2",
- exp_target => "ok2",
- rules => <<EOF
-KERNEL=="sda", NAME="ok2", RUN+="/bin/ln -s ok2 %r/testsymlink2"
-KERNEL=="sda", ACTION=="remove", RUN+="/bin/rm -f %r/testsymlink2"
EOF
},
{
desc => "final assignment",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "ok",
exp_perms => "root:tty:0640",
},
{
desc => "final assignment 2",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "ok",
exp_perms => "root:tty:0640",
},
{
desc => "env substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "node-add-me",
rules => <<EOF
},
{
desc => "reset list to current value",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "three",
not_exp_name => "two",
},
{
desc => "test empty SYMLINK+ (empty override)",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
not_exp_name => "wrong",
},
{
desc => "test multi matches",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
rules => <<EOF
},
{
desc => "test multi matches 2",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
rules => <<EOF
},
{
desc => "test multi matches 3",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
rules => <<EOF
},
{
desc => "test multi matches 4",
- subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
rules => <<EOF
},
{
desc => "IMPORT parent test sequence 1/2 (keep)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "parent",
option => "keep",
rules => <<EOF
-KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
+KERNEL=="sda", IMPORT{program}="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
KERNEL=="sda", SYMLINK+="parent"
EOF
},
{
desc => "IMPORT parent test sequence 2/2 (keep)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "parentenv-parent_right",
option => "clean",
},
{
desc => "GOTO test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "right",
rules => <<EOF
},
{
desc => "GOTO label does not exist",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "right",
rules => <<EOF
},
{
desc => "SYMLINK+ compare test",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "right",
not_exp_name => "wrong",
},
{
desc => "invalid key operation",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "yes",
rules => <<EOF
},
{
desc => "operator chars in attribute",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "yes",
rules => <<EOF
},
{
desc => "overlong comment line",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
exp_name => "yes",
rules => <<EOF
},
{
desc => "magic subsys/kernel lookup",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "00:16:41:e2:8d:ff",
rules => <<EOF
},
{
desc => "TEST absolute path",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "there",
rules => <<EOF
},
{
desc => "TEST subsys/kernel lookup",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "yes",
rules => <<EOF
},
{
desc => "TEST relative path",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "relative",
rules => <<EOF
},
{
desc => "TEST wildcard substitution (find queue/nr_requests)",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "found-subdir",
rules => <<EOF
},
{
desc => "TEST MODE=0000",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda",
exp_perms => "0:0:0000",
},
{
desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda",
exp_perms => "5000:100:0400",
},
{
desc => "TEST PROGRAM feeds MODE with overflow",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda",
exp_perms => "0:0:0440",
},
{
desc => "magic [subsys/sysname] attribute substitution",
- subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda-8741C4G-end",
exp_perms => "0:0:0600",
KERNEL=="sda", PROGRAM="/bin/true create-envp"
KERNEL=="sda", ENV{TESTENV}="change-envp"
KERNEL=="sda", SYMLINK+="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
+EOF
+ },
+ {
+ desc => "builtin path_id",
+ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
+ exp_name => "disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0",
+ rules => <<EOF
+KERNEL=="sda", IMPORT{builtin}="path_id"
+KERNEL=="sda", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/\$env{ID_PATH}"
EOF
},
);
# set env
-$ENV{SYSFS_PATH} = $sysfs;
$ENV{UDEV_CONFIG_FILE} = $udev_conf;
sub udev {
- my ($action, $subsys, $devpath, $rules) = @_;
-
- $ENV{DEVPATH} = $devpath;
+ my ($action, $devpath, $rules) = @_;
# create temporary rules
open CONF, ">$udev_rules" || die "unable to create rules file: $udev_rules";
print CONF $$rules;
close CONF;
- $ENV{ACTION} = $action;
- $ENV{SUBSYSTEM} = $subsys;
if ($valgrind > 0) {
- system("$udev_bin_valgrind");
+ system("$udev_bin_valgrind $action $devpath");
} else {
- system("$udev_bin");
+ system("$udev_bin $action $devpath");
}
}
}
}
-sub symlink_test {
- my ($rules) = @_;
-
- my $output = `ls -l $PWD/$udev_root$rules->{exp_name}`;
-
- if ($output =~ m/(.*)-> (.*)/) {
- if ($2 eq $rules->{exp_target}) {
- print "symlink: ok\n";
- } else {
- print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
- print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n";
- print "symlink: error";
- if ($rules->{exp_add_error}) {
- print " as expected\n";
- } else {
- print "\n";
- $error++;
- sleep(1);
- }
- }
- } else {
- print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
- print "symlink: not created";
- if ($rules->{exp_add_error}) {
- print " as expected\n";
- } else {
- print "\n";
- $error++;
- sleep(1);
- }
- }
-}
-
sub make_udev_root {
system("rm -rf $udev_root");
mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
my ($rules, $number) = @_;
print "TEST $number: $rules->{desc}\n";
+ print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
- if ($rules->{exp_target}) {
- print "device \'$rules->{devpath}\' expecting link '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
- } else {
- print "device \'$rules->{devpath}\' expecting node/link \'$rules->{exp_name}\'\n";
- }
-
-
- udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
+ udev("add", $rules->{devpath}, \$rules->{rules});
if (defined($rules->{not_exp_name})) {
- if ((-e "$PWD/$udev_root$rules->{not_exp_name}") ||
- (-l "$PWD/$udev_root$rules->{not_exp_name}")) {
+ if ((-e "$PWD/$udev_root/$rules->{not_exp_name}") ||
+ (-l "$PWD/$udev_root/$rules->{not_exp_name}")) {
print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
$error++;
sleep(1);
}
}
- if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
- (-l "$PWD/$udev_root$rules->{exp_name}")) {
+ if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
+ (-l "$PWD/$udev_root/$rules->{exp_name}")) {
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
- $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}");
+ $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root/$rules->{exp_name}");
if (defined($rules->{exp_perms})) {
permissions_test($rules, $uid, $gid, $mode);
if (defined($rules->{exp_majorminor})) {
major_minor_test($rules, $rdev);
}
- if (defined($rules->{exp_target})) {
- symlink_test($rules);
- }
print "add: ok\n";
} else {
print "add: error";
return;
}
- udev("remove", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
- if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
- (-l "$PWD/$udev_root$rules->{exp_name}")) {
+ udev("remove", $rules->{devpath}, \$rules->{rules});
+ if ((-e "$PWD/$udev_root/$rules->{exp_name}") ||
+ (-l "$PWD/$udev_root/$rules->{exp_name}")) {
print "remove: error";
if ($rules->{exp_rem_error}) {
print " as expected\n";
open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
print CONF "udev_root=\"$udev_root\"\n";
print CONF "udev_run=\"$udev_root/.udev\"\n";
+print CONF "udev_sys=\"$sysfs\"\n";
print CONF "udev_rules=\"$PWD\"\n";
print CONF "udev_log=\"err\"\n";
close CONF;