chiark / gitweb /
[PATCH] remove PLACE key match
[elogind.git] / test / udev-test.pl
index 9a581ce5276ff01d413c928fd369f5c01ee1bf54..c7e1a9d47e7f4d3898f9a070e1e4b7d2853888a1 100644 (file)
 # After creation and removal the result is checked against the
 # expected value and the result is printed.
 #
-# happy testing,
 # Kay Sievers <kay.sievers@vrfy.org>, 2003
-#
-# Modified April 9, 2004 by Leann Ogasawara <ogasawara@osdl.org>
-#  - expanded @tests array to add more symlinks and permissions tests
-#  - some of the symlinks tests also test lack of node creation
-#  - added symlink_test() function
-#  - moved permissions and major_minor tests into their own functions
+# Leann Ogasawara <ogasawara@osdl.org>, 2004
 
 use warnings;
 use strict;
@@ -187,6 +181,45 @@ EOF
 
 KERNEL="ttyUSB0", NAME="visor"
 
+EOF
+       },
+       {
+               desc            => "Handle backslashed multi lines in config file (and replace kernel name)",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "visor" ,
+               conf            => <<EOF
+KERNEL="ttyUSB0", \\
+NAME="visor"
+
+EOF
+       },
+       {
+               desc            => "preserve backslashes, if they are not for a newline",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "aaa",
+               conf            => <<EOF
+KERNEL="ttyUSB0", PROGRAM="/bin/echo -e \\101", RESULT="A", NAME="aaa"
+EOF
+       },
+       {
+               desc            => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "visor" ,
+               conf            => <<EOF
+
+#
+\\
+
+\\\\
+
+#\\
+
+KERNEL="ttyUSB0", \\
+       NAME="visor"
+
 EOF
        },
        {
@@ -204,7 +237,7 @@ EOF
                devpath         => "/block/sda/sda3",
                exp_name        => "first_disk3" ,
                conf            => <<EOF
-BUS="scsi", PLACE="0:0:0:0", NAME="first_disk%n"
+BUS="scsi", ID="0:0:0:0", NAME="first_disk%n"
 EOF
        },
        {
@@ -213,7 +246,7 @@ EOF
                devpath         => "/block/sda/sda3",
                exp_name        => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
                conf            => <<EOF
-BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
+BUS="scsi", ID="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
 EOF
        },
        {
@@ -222,7 +255,7 @@ EOF
                devpath         => "/block/sda/sda3",
                exp_name        => "M8-m3-n3-b0:0-sIBM" ,
                conf            => <<EOF
-BUS="scsi", PLACE="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
+BUS="scsi", ID="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
 EOF
        },
        {
@@ -589,6 +622,46 @@ EOF
                exp_perms       => "5000:100:0777",
                conf            => <<EOF
 KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", OWNER="5000", GROUP="100", MODE="0777"
+EOF
+       },
+       {
+               desc            => "permissions only rule",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "ttyUSB0",
+               exp_perms       => "5000:100:0777",
+               conf            => <<EOF
+KERNEL="ttyUSB[0-9]*", OWNER="5000", GROUP="100", MODE="0777"
+KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
+KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n"
+EOF
+       },
+       {
+               desc            => "multiple permissions only rule",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "ttyUSB0",
+               exp_perms       => "3000:4000:0777",
+               conf            => <<EOF
+SUBSYSTEM="tty", OWNER="3000"
+SUBSYSTEM="tty", GROUP="4000"
+SUBSYSTEM="tty", MODE="0777"
+KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
+KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n"
+EOF
+       },
+       {
+               desc            => "permissions only rule with override at NAME rule",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "ttyUSB0",
+               exp_perms       => "3000:8000:0777",
+               conf            => <<EOF
+SUBSYSTEM="tty", OWNER="3000"
+SUBSYSTEM="tty", GROUP="4000"
+SUBSYSTEM="tty", MODE="0777"
+KERNEL="ttyUSX[0-9]*", OWNER="5001", GROUP="101", MODE="0444"
+KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", GROUP="8000"
 EOF
        },
        {
@@ -691,17 +764,6 @@ EOF
 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only1"
 BUS="scsi", KERNEL="sda", SYMLINK="symlink-only2"
 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="symlink0"
-EOF
-       },
-       {
-               desc            => "symlink name empty",
-               subsys          => "block",
-               devpath         => "/block/sda",
-               exp_name        => "",
-               exp_target      => "link",
-               exp_error       => "yes",
-               conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME="link", SYMLINK=""
 EOF
        },
        {
@@ -710,31 +772,10 @@ EOF
                devpath         => "/block/sda",
                exp_name        => ".",
                exp_target      => "link",
-               exp_error       => "yes",
+               exp_add_error   => "yes",
+               exp_rem_error   => "yes",
                conf            => <<EOF
 BUS="scsi", KERNEL="sda", NAME="link", SYMLINK="."
-EOF
-       },
-       {
-               desc            => "symlink to empty name",
-               subsys          => "block",
-               devpath         => "/block/sda",
-               exp_name        => "symlink",
-               exp_target      => "",
-               exp_error       => "yes",
-               conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink"
-EOF
-       },
-       {
-               desc            => "symlink and name empty",
-               subsys          => "block",
-               devpath         => "/block/sda",
-               exp_name        => "",
-               exp_target      => "",
-               exp_error       => "yes",
-               conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME="", SYMLINK=""
 EOF
        },
        {
@@ -743,6 +784,8 @@ EOF
                devpath         => "/class/tty/tty0",
                exp_name        => "link",
                exp_target      => "link",
+               exp_rem_error   => "yes",
+               option          => "clear",
                conf            => <<EOF
 KERNEL="tty0", NAME="link", SYMLINK="link"
 EOF
@@ -898,7 +941,7 @@ KERNEL="sda", NAME="cdrom%e"
 EOF
        },
        {
-               desc            => "enumeration char test sequence (1/5 keep)",
+               desc            => "enumeration char test sequence 1/5 (keep)",
                subsys          => "block",
                devpath         => "/block/sda",
                exp_name        => "cdrom",
@@ -954,6 +997,37 @@ EOF
                exp_name        => "cdrom",
                conf            => <<EOF
 KERNEL="sda", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "ignore rule test",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node",
+               exp_add_error   => "yes",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore"
+EOF
+       },
+       {
+               desc            => "all_partitions, option-only rule",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node6",
+               conf            => <<EOF
+SUBSYSTEM="block", OPTIONS="all_partitions"
+BUS="scsi", KERNEL="sda", NAME="node"
+EOF
+       },
+       {
+               desc            => "all_partitions, option-only rule (fail on partition)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda1",
+               exp_name        => "node6",
+               exp_add_error   => "yes",
+               conf            => <<EOF
+SUBSYSTEM="block", OPTIONS="all_partitions"
+BUS="scsi", KERNEL="sda", NAME="node"
 EOF
        },
        {
@@ -961,9 +1035,9 @@ EOF
                subsys          => "block",
                devpath         => "/block/sda",
                exp_name        => "node",
-               exp_error       => "yes",
+               exp_rem_error   => "yes",
                conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME{ignore_remove}="node"
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore_remove"
 EOF
        },
        {
@@ -971,10 +1045,10 @@ EOF
                subsys          => "block",
                devpath         => "/block/sda",
                exp_name        => "node14",
-               exp_error       => "yes",
+               exp_rem_error   => "yes",
                option          => "clear",
                conf            => <<EOF
-BUS="scsi", KERNEL="sda", NAME{ignore_remove, all_partitions}="node"
+BUS="scsi", KERNEL="sda", NAME="node", OPTIONS="ignore_remove, all_partitions"
 EOF
        },
        {
@@ -996,6 +1070,54 @@ EOF
                conf            => <<EOF
 BUS="scsi", KERNEL="sda", NAME="should_not_match", DRIVER="sd-wrong"
 BUS="scsi", KERNEL="sda", NAME="node", DRIVER="sd"
+EOF
+       },
+       {
+               desc            => "temporary node creation test",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "node",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test -b %N" NAME="node"
+EOF
+       },
+       {
+               desc            => "devpath substitution test",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "sda",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", PROGRAM="/bin/echo %p", RESULT="/block/sda" NAME="%k"
+EOF
+       },
+       {
+               desc            => "parent node name substitution test sequence 1/2 (keep)",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "main_device",
+               option          => "keep",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda", NAME="main_device"
+EOF
+       },
+       {
+               desc            => "parent node name substitution test sequence 2/2 (clean)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda1",
+               exp_name        => "main_device-part-1",
+               option          => "clean",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda1", NAME="%P-part-1"
+EOF
+       },
+       {
+               desc            => "udev_root substitution",
+               subsys          => "block",
+               devpath         => "/block/sda/sda1",
+               exp_name        => "start-udev-root-end",
+               option          => "clean",
+               conf            => <<EOF
+BUS="scsi", KERNEL="sda1", NAME="start-%r-end"
 EOF
        },
 );
@@ -1082,7 +1204,7 @@ sub symlink_test {
                } else {
                        print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
                        print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n";
-                       if ($config->{exp_error}) {
+                       if ($config->{exp_add_error}) {
                                print "as expected    ";
                        } else {
                                $error++;
@@ -1091,7 +1213,7 @@ sub symlink_test {
        } else {
                print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n";
                print "symlink: not created ";
-               if ($config->{exp_error}) {
+               if ($config->{exp_add_error}) {
                        print "as expected    ";
                } else {
                        $error++;
@@ -1130,7 +1252,7 @@ sub run_test {
                print "add: ok    ";
        } else {
                print "add: error ";
-               if ($config->{exp_error}) {
+               if ($config->{exp_add_error}) {
                        print "as expected    ";
                } else {
                        print "\n\n";
@@ -1149,7 +1271,7 @@ sub run_test {
        if ((-e "$PWD/$udev_root$config->{exp_name}") ||
            (-l "$PWD/$udev_root$config->{exp_name}")) {
                print "remove: error ";
-               if ($config->{exp_error}) {
+               if ($config->{exp_rem_error}) {
                        print "as expected\n\n";
                } else {
                        print "\n\n";
@@ -1185,9 +1307,6 @@ open CONF, ">$main_conf" || die "unable to create config file: $main_conf";
 print CONF "udev_root=\"$udev_root\"\n";
 print CONF "udev_db=\"$udev_db\"\n";
 print CONF "udev_rules=\"$conf_tmp\"\n";
-print CONF "default_mode=\"0660\"\n";
-print CONF "default_owner=\"root\"\n";
-print CONF "default_group=\"root\"\n";
 close CONF;
 
 my $test_num = 1;