chiark / gitweb /
libudev: allow to store negative values in the udev database
[elogind.git] / test / udev-test.pl
index 26337cb840d6423ba31b7f998f476b08d53986b2..47cadc5db35768f64f6a3165d90cdf291ba4d414 100755 (executable)
@@ -21,8 +21,8 @@ use warnings;
 use strict;
 
 my $PWD                        = $ENV{PWD};
-my $sysfs              = "sys/";
-my $udev_bin           = "../udev/test-udev";
+my $sysfs              = "test/sys/";
+my $udev_bin           = "udev/test-udev";
 my $valgrind           = 0;
 my $udev_bin_valgrind  = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
 my $udev_root          = "udev-root/";
@@ -30,13 +30,21 @@ 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" ,
+               rules           => <<EOF
+EOF
+       },
        {
                desc            => "label test of scsi disc (old key names)",
                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
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="boot_disk%n"
+SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
 KERNEL=="ttyACM0", NAME="modem"
 EOF
        },
@@ -92,7 +100,7 @@ SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", NAME="boot
 EOF
        },
        {
-               desc            => "label test of max sysfs files",
+               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" ,
@@ -104,7 +112,7 @@ EOF
        {
                desc            => "catch device by *",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem/0" ,
                rules           => <<EOF
 KERNEL=="ttyACM*", NAME="modem/%n"
@@ -113,7 +121,7 @@ EOF
        {
                desc            => "catch device by * - take 2",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem/0" ,
                rules           => <<EOF
 KERNEL=="*ACM1", NAME="bad"
@@ -123,7 +131,7 @@ EOF
        {
                desc            => "catch device by ?",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem/0" ,
                rules           => <<EOF
 KERNEL=="ttyACM??*", NAME="modem/%n-1"
@@ -134,7 +142,7 @@ EOF
        {
                desc            => "catch device by character class",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem/0" ,
                rules           => <<EOF
 KERNEL=="ttyACM[A-Z]*", NAME="modem/%n-1"
@@ -145,7 +153,7 @@ EOF
        {
                desc            => "replace kernel name",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem" ,
                rules           => <<EOF
 KERNEL=="ttyACM0", NAME="modem"
@@ -154,7 +162,7 @@ EOF
        {
                desc            => "Handle comment lines in config file (and replace kernel name)",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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
@@ -165,7 +173,7 @@ 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-1/5-1:1.0/tty/ttyACM0",
+               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 
@@ -176,7 +184,7 @@ EOF
        {
                desc            => "Handle whitespace only lines (and replace kernel name)",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "whitespace" ,
                rules           => <<EOF
 
@@ -192,7 +200,7 @@ EOF
        {
                desc            => "Handle empty lines in config file (and replace kernel name)",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem" ,
                rules           => <<EOF
 
@@ -203,7 +211,7 @@ 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-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem" ,
                rules           => <<EOF
 KERNEL=="ttyACM0", \\
@@ -214,7 +222,7 @@ EOF
        {
                desc            => "preserve backslashes, if they are not for a newline",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "aaa",
                rules           => <<EOF
 KERNEL=="ttyACM0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", NAME="aaa"
@@ -223,14 +231,14 @@ 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-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem" ,
                rules           => <<EOF
 
 #
 \\
 
-\\\\
+\\
 
 #\\
 
@@ -242,7 +250,7 @@ EOF
        {
                desc            => "subdirectory handling",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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
 KERNEL=="ttyACM0", NAME="sub/direct/ory/modem"
@@ -273,15 +281,6 @@ EOF
                exp_name        => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
                rules           => <<EOF
 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
-EOF
-       },
-       {
-               desc            => "test substitution chars (with length limit)",
-               subsys          => "block",
-               devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
-               exp_name        => "M8-m5-n5-b0:0-xAT" ,
-               rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-x%2s{vendor}"
 EOF
        },
        {
@@ -343,15 +342,6 @@ EOF
                exp_name        => "test-0:0:0:0" ,
                rules           => <<EOF
 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c"
-EOF
-       },
-       {
-               desc            => "program with escaped format char (tricky: callout returns format char!)",
-               subsys          => "block",
-               devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
-               exp_name        => "escape-5" ,
-               rules           => <<EOF
-SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda5", NAME="%c"
 EOF
        },
        {
@@ -470,8 +460,35 @@ EOF
                devpath         => "/devices/virtual/tty/console",
                exp_name        => "foo" ,
                rules           => <<EOF
-ATTRS{dev}=="5:1", NAME="foo"
 KERNEL=="console", NAME="TTY"
+ATTRS{dev}=="5:1", NAME="foo"
+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
+KERNEL=="sda", ATTR{test_empty_file}=="?*", NAME:="something"
+KERNEL=="sda", ATTR{test_empty_file}!="", NAME:="not-empty"
+KERNEL=="sda", ATTR{test_empty_file}=="", NAME:="empty"
+KERNEL=="sda", ATTR{test_empty_file}!="?*", NAME:="not-something"
+KERNEL=="sda", NAME="wrong"
+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
+KERNEL=="sda", ATTR{nofile}=="?*", NAME:="something"
+KERNEL=="sda", ATTR{nofile}!="", NAME:="not-empty"
+KERNEL=="sda", ATTR{nofile}=="", NAME:="empty"
+KERNEL=="sda", ATTR{nofile}!="?*", NAME:="not-something"
+KERNEL=="sda", TEST!="nofile", NAME:="non-existent"
+KERNEL=="sda", NAME="wrong"
 EOF
        },
        {
@@ -498,7 +515,7 @@ EOF
        {
                desc            => "sysfs parent hierarchy",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem" ,
                rules           => <<EOF
 ATTRS{idProduct}=="007b", NAME="modem"
@@ -546,8 +563,8 @@ EOF
 SUBSYSTEMS=="scsi", KERNELS=="*:1", NAME="no-match"
 SUBSYSTEMS=="scsi", KERNELS=="*:0:1", NAME="no-match"
 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:1", NAME="no-match"
+SUBSYSTEMS=="scsi", KERNEL=="0:0:0:0", NAME="before"
 SUBSYSTEMS=="scsi", KERNELS=="*", NAME="scsi-0:0:0:0"
-SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="bad"
 EOF
        },
        {
@@ -556,8 +573,8 @@ EOF
                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
+SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="before"
 SUBSYSTEMS=="scsi", KERNELS=="*:0", NAME="scsi-0:0:0:0"
-SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="bad"
 EOF
        },
        {
@@ -566,8 +583,8 @@ EOF
                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
+SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="before"
 SUBSYSTEMS=="scsi", KERNELS=="*:0:0:0", NAME="scsi-0:0:0:0"
-SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="bad"
 EOF
        },
        {
@@ -610,7 +627,7 @@ EOF
        {
                desc            => "permissions USER=bad GROUP=name",
                subsys          => "tty",
-               devpath         => "/class/tty/tty33",
+               devpath         => "/devices/virtual/tty/tty33",
                exp_name        => "tty33",
                exp_perms       => "0:0:0660",
                rules           => <<EOF
@@ -690,7 +707,7 @@ EOF
        {
                desc            => "permissions OWNER to 5000",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "ttyACM0",
                exp_perms       => "5000::",
                rules           => <<EOF
@@ -700,7 +717,7 @@ EOF
        {
                desc            => "permissions GROUP to 100",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "ttyACM0",
                exp_perms       => ":100:0660",
                rules           => <<EOF
@@ -710,7 +727,7 @@ EOF
        {
                desc            => "permissions MODE to 0060",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "ttyACM0",
                exp_perms       => "::0060",
                rules           => <<EOF
@@ -720,7 +737,7 @@ EOF
        {
                desc            => "permissions OWNER, GROUP, MODE",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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",
                rules           => <<EOF
@@ -730,7 +747,7 @@ EOF
        {
                desc            => "permissions only rule",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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",
                rules           => <<EOF
@@ -742,7 +759,7 @@ EOF
        {
                desc            => "multiple permissions only rule",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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",
                rules           => <<EOF
@@ -756,7 +773,7 @@ EOF
        {
                desc            => "permissions only rule with override at NAME rule",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               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",
                rules           => <<EOF
@@ -800,17 +817,17 @@ EOF
        {
                desc            => "multiple symlinks with format char",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "symlink2-ttyACM0",
-               exp_target      => "ttyACM0",
+               exp_target      => "ttyACM-0",
                rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
+KERNEL=="ttyACM[0-9]*", NAME="ttyACM-%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
 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-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "one",
                not_exp_name    => " ",
                exp_target      => "ttyACM0",
@@ -821,7 +838,7 @@ EOF
        {
                desc            => "symlink creation (same directory)",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "modem0",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -851,7 +868,7 @@ EOF
        {
                desc            => "multiple symlinks",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "second-0" ,
                exp_target      => "modem" ,
                rules           => <<EOF
@@ -885,7 +902,7 @@ EOF
        {
                desc            => "symlink node to itself",
                subsys          => "tty",
-               devpath         => "/class/tty/tty0",
+               devpath         => "/devices/virtual/tty/tty0",
                exp_name        => "link",
                exp_target      => "link",
                exp_add_error   => "yes",
@@ -898,7 +915,7 @@ EOF
        {
                desc            => "symlink %n substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "symlink0",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -908,7 +925,7 @@ EOF
        {
                desc            => "symlink %k substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "symlink-ttyACM0",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -918,7 +935,7 @@ EOF
        {
                desc            => "symlink %M:%m substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "major-166:0",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -938,7 +955,7 @@ EOF
        {
                desc            => "symlink %c substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "test",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -948,7 +965,7 @@ EOF
        {
                desc            => "symlink %c{N} substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "test",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -958,7 +975,7 @@ EOF
        {
                desc            => "symlink %c{N+} substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "this",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -979,21 +996,11 @@ EOF
        {
                desc            => "symlink %s{filename} substitution",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "166:0",
                exp_target      => "ttyACM0",
                rules           => <<EOF
 KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK+="%s{dev}"
-EOF
-       },
-       {
-               desc            => "symlink %Ns{filename} substitution",
-               subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
-               exp_name        => "166",
-               exp_target      => "ttyACM0",
-               rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK+="%3s{dev}"
 EOF
        },
        {
@@ -1024,7 +1031,7 @@ EOF
                not_exp_name    => "node",
                exp_add_error   => "yes",
                rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore"
+SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore_device"
 EOF
        },
        {
@@ -1154,8 +1161,8 @@ EOF
                exp_name        => "match",
                rules           => <<EOF
 SUBSYSTEMS=="scsi", KERNEL!="sda1", NAME="matches-but-is-negated"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 SUBSYSTEMS=="scsi", KERNEL!="xsda1", NAME="match"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="wrong"
 EOF
        },
        {
@@ -1165,8 +1172,8 @@ EOF
                exp_name        => "not-anything",
                rules           => <<EOF
 SUBSYSTEMS=="scsi", SUBSYSTEM=="block", KERNEL!="sda1", NAME="matches-but-is-negated"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 SUBSYSTEMS=="scsi", SUBSYSTEM!="anything", NAME="not-anything"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="wrong"
 EOF
        },
        {
@@ -1175,8 +1182,8 @@ EOF
                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
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 KERNEL=="sda1", PROGRAM!="/bin/false", NAME="nonzero-program"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="wrong"
 EOF
        },
        {
@@ -1185,8 +1192,8 @@ EOF
                devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
                exp_name        => "true",
                rules           => <<EOF
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 KERNEL   ==   "sda1"     ,    NAME   =    "true"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="wrong"
 EOF
        },
        {
@@ -1195,6 +1202,7 @@ EOF
                devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
                exp_name        => "true",
                rules           => <<EOF
+ENV{ENV_KEY_TEST}="test"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", NAME="true"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad"
@@ -1206,9 +1214,10 @@ EOF
                devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
                exp_name        => "true",
                rules           => <<EOF
+ENV{ENV_KEY_TEST}="test"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="go", NAME="wrong"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sdax1", NAME="no"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1", NAME="true"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", NAME="no"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", NAME="true"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad"
 EOF
        },
@@ -1220,8 +1229,8 @@ EOF
                rules           => <<EOF
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", NAME="true"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="bad"
 EOF
        },
        {
@@ -1232,9 +1241,9 @@ EOF
                rules           => <<EOF
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="absolutely-\$env{ASSIGN}"
+SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="before"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no"
 SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="absolutely-true", NAME="true"
-SUBSYSTEMS=="scsi", KERNEL=="sda1", NAME="bad"
 EOF
        },
        {
@@ -1246,8 +1255,8 @@ EOF
 SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
 SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
 ENV{MAINDEVICE}=="true", NAME="disk"
+SUBSYSTEM=="block", NAME="before"
 ENV{PARTITION}=="true", NAME="part"
-NAME="bad"
 EOF
        },
        {
@@ -1278,12 +1287,12 @@ SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", R
 EOF
        },
        {
-               desc            => "read sysfs value from device down in the chain",
+               desc            => "read sysfs value from parent device",
                subsys          => "block",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "serial-354172020305000",
                rules           => <<EOF
-KERNEL=="ttyACM*", NAME="serial-%s{serial}"
+KERNEL=="ttyACM*", ATTRS{serial}=="?*", NAME="serial-%s{serial}"
 EOF
        },
        {
@@ -1309,13 +1318,13 @@ ACTION=="add", KERNEL=="sda", NAME="ok"
 EOF
        },
        {
-               desc            => "apply NAME only once",
+               desc            => "apply NAME final",
                subsys          => "block",
                devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                exp_name        => "link",
                exp_target      => "ok",
                rules           => <<EOF
-KERNEL=="sda", NAME="ok"
+KERNEL=="sda", NAME:="ok"
 KERNEL=="sda", NAME="not-ok"
 KERNEL=="sda", SYMLINK+="link"
 EOF
@@ -1342,8 +1351,8 @@ EOF
                exp_rem_error   => "yes",
                option          => "clean",
                rules           => <<EOF
-KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'"
 KERNEL=="sda", NAME="not-ok"
+KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'"
 EOF
        },
        {
@@ -1363,20 +1372,20 @@ EOF
                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:nobody:0640",
+               exp_perms       => "root:tty:0640",
                rules           => <<EOF
-KERNEL=="sda", GROUP:="nobody"
+KERNEL=="sda", GROUP:="tty"
 KERNEL=="sda", GROUP="not-ok", MODE="0640", NAME="ok"
 EOF
        },
        {
-               desc            => "final assignment",
+               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:nobody:0640",
+               exp_perms       => "root:tty:0640",
                rules           => <<EOF
-KERNEL=="sda", GROUP:="nobody"
+KERNEL=="sda", GROUP:="tty"
 SUBSYSTEM=="block", MODE:="640"
 KERNEL=="sda", GROUP="not-ok", MODE="0666", NAME="ok"
 EOF
@@ -1393,7 +1402,7 @@ EOF
        {
                desc            => "reset list to current value",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "three",
                not_exp_name    => "two",
                exp_target      => "node",
@@ -1407,45 +1416,81 @@ EOF
        {
                desc            => "test empty NAME",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
-               exp_name        => "node",
-               not_exp_name    => "wrong",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
+               exp_name        => "<none>",
+               not_exp_name    => "ttyACM0",
                exp_add_error   => "yes",
                rules           => <<EOF
 KERNEL=="ttyACM[0-9]*", NAME=""
+EOF
+       },
+       {
+               desc            => "test empty NAME (empty override)",
+               subsys          => "tty",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
+               exp_name        => "<none>",
+               not_exp_name    => "wrong",
+               exp_add_error   => "yes",
+               rules           => <<EOF
 KERNEL=="ttyACM[0-9]*", NAME="wrong"
+KERNEL=="ttyACM[0-9]*", NAME=""
 EOF
        },
        {
-               desc            => "test empty NAME 2",
+               desc            => "test empty NAME (non-empty override)",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "right",
                rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="right"
 KERNEL=="ttyACM[0-9]*", NAME=""
 KERNEL=="ttyACM[0-9]*", NAME="wrong"
+KERNEL=="ttyACM[0-9]*", NAME="right"
 EOF
        },
        {
                desc            => "test multi matches",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "right",
                rules           => <<EOF
+KERNEL=="ttyACM*", NAME="before"
 KERNEL=="ttyACM*|nothing", NAME="right"
-KERNEL=="ttyACM*", NAME="wrong"
 EOF
        },
        {
                desc            => "test multi matches 2",
                subsys          => "tty",
-               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-1/5-1:1.0/tty/ttyACM0",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "right",
                rules           => <<EOF
 KERNEL=="dontknow*|*nothing", NAME="nomatch"
+KERNEL=="ttyACM*", NAME="before"
 KERNEL=="dontknow*|ttyACM*|nothing*", NAME="right"
-KERNEL=="ttyACM*", NAME="wrong"
+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
+KERNEL=="dontknow|nothing", NAME="nomatch"
+KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong1"
+KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong2"
+KERNEL=="dontknow|ttyACM0|nothing", NAME="right"
+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
+KERNEL=="dontknow|nothing", NAME="nomatch"
+KERNEL=="dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong1"
+KERNEL=="X|attyACM0|dontknow|ttyACM0a|nothing|attyACM0", NAME="wrong2"
+KERNEL=="all|dontknow|ttyACM0", NAME="right"
+KERNEL=="ttyACM0a|nothing", NAME="wrong3"
 EOF
        },
        {
@@ -1477,9 +1522,22 @@ EOF
                rules           => <<EOF
 KERNEL=="sda1", GOTO="TEST"
 KERNEL=="sda1", NAME="wrong"
+KERNEL=="sda1", GOTO="BAD"
 KERNEL=="sda1", NAME="", LABEL="NO"
-KERNEL=="sda1", NAME="right", LABEL="TEST"
-KERNEL=="sda1", NAME="wrong2"
+KERNEL=="sda1", NAME="right", LABEL="TEST", GOTO="end"
+KERNEL=="sda1", NAME="wrong2", LABEL="BAD"
+LABEL="end"
+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
+KERNEL=="sda1", GOTO="does-not-exist"
+KERNEL=="sda1", NAME="right",
+LABEL="exists"
 EOF
        },
        {
@@ -1535,8 +1593,8 @@ EOF
                exp_name        => "yes",
                rules           => <<EOF
 # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-   # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
-KERNEL="sda1", NAME=="no"
+   # 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
+KERNEL=="sda1", NAME=="no"
 KERNEL=="sda1", NAME="yes"
 EOF
        },
@@ -1556,7 +1614,7 @@ EOF
                exp_name        => "there",
                rules           => <<EOF
 TEST=="/etc/hosts", NAME="there"
-NAME="notthere"
+TEST!="/etc/hosts", NAME="notthere"
 EOF
        },
        {
@@ -1597,13 +1655,14 @@ KERNEL=="sda", MODE="0000"
 EOF
        },
        {
-               desc            => "TEST PROGRAM feeds MODE",
+               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       => "0:0:0400",
+               exp_perms       => "5000:100:0400",
                rules           => <<EOF
-KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
+KERNEL=="sda", MODE="666"
+KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
 EOF
        },
        {
@@ -1611,16 +1670,27 @@ EOF
                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:0400",
+               exp_perms       => "0:0:0660",
                rules           => <<EOF
+KERNEL=="sda", MODE="440"
 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
 EOF
        },
-
+       {
+               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:0660",
+               rules           => <<EOF
+KERNEL=="sda", PROGRAM="/bin/true create-envp"
+KERNEL=="sda", ENV{TESTENV}="change-envp"
+KERNEL=="sda", NAME="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
+EOF
+       },
 );
 
 # set env
-$ENV{ENV_KEY_TEST} = "test";
 $ENV{SYSFS_PATH} = $sysfs;
 $ENV{UDEV_CONFIG_FILE} = $udev_conf;
 
@@ -1635,10 +1705,11 @@ sub udev {
        close CONF;
 
        $ENV{ACTION} = $action;
+       $ENV{SUBSYSTEM} = $subsys;
        if ($valgrind > 0) {
-               system("$udev_bin_valgrind $subsys");
+               system("$udev_bin_valgrind");
        } else {
-               system("$udev_bin $subsys");
+               system("$udev_bin");
        }
 }
 
@@ -1758,19 +1829,20 @@ sub run_test {
 
 
        udev("add", $rules->{subsys}, $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}")) {
+                       print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
+                       $error++
+               }
+       }
+
        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}");
 
-               if (defined($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++
-                       }
-               }
                if (defined($rules->{exp_perms})) {
                        permissions_test($rules, $uid, $gid, $mode);
                }