chiark / gitweb /
test: add RUN+="socket: ..." to a test to run monitor code
[elogind.git] / test / udev-test.pl
index 26337cb840d6423ba31b7f998f476b08d53986b2..096977a611044683ceeaad2ebe3200413b272b47 100755 (executable)
@@ -36,7 +36,7 @@ my @tests = (
                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 +92,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 +104,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 +113,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 +123,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 +134,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 +145,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 +154,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 +165,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 +176,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 +192,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 +203,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 +214,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 +223,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 +242,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"
@@ -470,8 +470,8 @@ 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
        },
        {
@@ -498,7 +498,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 +546,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 +556,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 +566,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 +610,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 +690,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 +700,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 +710,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 +720,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 +730,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 +742,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 +756,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,7 +800,7 @@ 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",
                rules           => <<EOF
@@ -810,7 +810,7 @@ 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 +821,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 +851,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 +885,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 +898,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 +908,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 +918,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 +938,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 +948,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 +958,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,7 +979,7 @@ 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
@@ -989,7 +989,7 @@ 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",
+               devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "166",
                exp_target      => "ttyACM0",
                rules           => <<EOF
@@ -1154,8 +1154,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 +1165,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 +1175,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 +1185,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 +1195,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 +1207,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 +1222,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 +1234,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 +1248,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 +1280,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 +1311,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 +1344,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 +1365,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 +1395,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 +1409,70 @@ 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",
+               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=""
 KERNEL=="ttyACM[0-9]*", NAME="wrong"
+KERNEL=="ttyACM[0-9]*", NAME=""
 EOF
        },
        {
                desc            => "test empty NAME 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=="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 +1504,10 @@ 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", LABEL="BAD"
 EOF
        },
        {
@@ -1535,8 +1563,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 +1584,17 @@ EOF
                exp_name        => "there",
                rules           => <<EOF
 TEST=="/etc/hosts", NAME="there"
-NAME="notthere"
+TEST!="/etc/hosts", NAME="notthere"
+EOF
+       },
+       {
+               desc            => "TEST invalid NAME= only (skip invalid rule)",
+               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
+SUBSYSTEM=="block", NAME="yes"
+NAME="no"
 EOF
        },
        {
@@ -1603,6 +1641,7 @@ EOF
                exp_name        => "sda",
                exp_perms       => "0:0:0400",
                rules           => <<EOF
+KERNEL=="sda", MODE="666"
 KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
 EOF
        },
@@ -1611,16 +1650,26 @@ 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", 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 +1684,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");
        }
 }