chiark / gitweb /
keymap: move force-release directory
[elogind.git] / test / udev-test.pl
index 61e91c48b66e9ec5381ea72b87cee7beb5bfd900..896bb228c46e112c5cf003a88d2d3ae669f31235 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/";
@@ -39,7 +39,7 @@ my @tests = (
 EOF
        },
        {
-               desc            => "label test of scsi disc (old key names)",
+               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" ,
@@ -49,7 +49,7 @@ KERNEL=="ttyACM0", NAME="modem"
 EOF
        },
        {
-               desc            => "label test of scsi disc (old key names)",
+               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" ,
@@ -263,15 +263,6 @@ EOF
                exp_name        => "first_disk5" ,
                rules           => <<EOF
 SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="first_disk%n"
-EOF
-       },
-       {
-               desc            => "test substitution chars (old key names)",
-               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
-BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
 EOF
        },
        {
@@ -281,15 +272,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
        },
        {
@@ -351,15 +333,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
        },
        {
@@ -480,6 +453,33 @@ EOF
                rules           => <<EOF
 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
        },
        {
@@ -810,9 +810,9 @@ EOF
                subsys          => "tty",
                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
        },
        {
@@ -992,16 +992,6 @@ EOF
                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-2/5-2:1.0/tty/ttyACM0",
-               exp_name        => "166",
-               exp_target      => "ttyACM0",
-               rules           => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK+="%3s{dev}"
 EOF
        },
        {
@@ -1022,17 +1012,6 @@ EOF
                exp_target      => "node",
                rules           => <<EOF
 SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}"
-EOF
-       },
-       {
-               desc            => "ignore rule test",
-               subsys          => "block",
-               devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
-               exp_name        => "nothing",
-               not_exp_name    => "node",
-               exp_add_error   => "yes",
-               rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore"
 EOF
        },
        {
@@ -1113,7 +1092,7 @@ EOF
                devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
                exp_name        => "sda",
                rules           => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda" NAME="%k"
+SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda"
 EOF
        },
        {
@@ -1419,6 +1398,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
@@ -1427,7 +1417,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",
@@ -1514,8 +1504,20 @@ 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", LABEL="BAD"
+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
        },
        {
@@ -1593,16 +1595,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
        },
        {
@@ -1643,14 +1635,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", MODE="666"
-KERNEL=="sda", PROGRAM=="/bin/echo 0 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
+KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
 EOF
        },
        {
@@ -1817,19 +1809,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);
                }