chiark / gitweb /
fix NAME="" logic
[elogind.git] / test / udev-test.pl
index 9725aff5ba0a245ca7881787e1f68d0f2792e26e..1b81eb8d722ad29e8e06cd0805248627600aa92c 100755 (executable)
@@ -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
        },
@@ -1024,7 +1032,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
        },
        {
@@ -1411,6 +1419,17 @@ EOF
                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    => "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
@@ -1419,7 +1438,7 @@ 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-2/5-2:1.0/tty/ttyACM0",
                exp_name        => "right",
@@ -1448,6 +1467,31 @@ EOF
 KERNEL=="dontknow*|*nothing", NAME="nomatch"
 KERNEL=="ttyACM*", NAME="before"
 KERNEL=="dontknow*|ttyACM*|nothing*", NAME="right"
+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
        },
        {
@@ -1560,16 +1604,6 @@ EOF
                rules           => <<EOF
 TEST=="/etc/hosts", NAME="there"
 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
        },
        {
@@ -1631,7 +1665,18 @@ 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
@@ -1773,19 +1818,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);
                }