chiark / gitweb /
[PATCH] namedev: skip backslashes only if followed by newline
[elogind.git] / test / udev-test.pl
index 53eee35457012fcd2575a11cbff727f4abca5521..f442b162ec31cf5ff314480b269284ec5ff30e13 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;
@@ -198,6 +192,15 @@ 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
        },
        {
@@ -215,7 +218,7 @@ EOF
 #\\
 
 KERNEL="ttyUSB0", \\
-NAME="visor"
+       NAME="visor"
 
 EOF
        },
@@ -619,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
        },
        {
@@ -721,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
        },
        {
@@ -740,7 +772,8 @@ 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
@@ -751,7 +784,7 @@ EOF
                devpath         => "/block/sda",
                exp_name        => "symlink",
                exp_target      => "",
-               exp_error       => "yes",
+               exp_add_error   => "yes",
                conf            => <<EOF
 BUS="scsi", KERNEL="sda", NAME="", SYMLINK="symlink"
 EOF
@@ -762,7 +795,8 @@ EOF
                devpath         => "/block/sda",
                exp_name        => "",
                exp_target      => "",
-               exp_error       => "yes",
+               exp_add_error   => "yes",
+               exp_rem_error   => "yes",
                conf            => <<EOF
 BUS="scsi", KERNEL="sda", NAME="", SYMLINK=""
 EOF
@@ -773,6 +807,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
@@ -928,7 +964,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",
@@ -984,6 +1020,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
        },
        {
@@ -991,9 +1058,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
        },
        {
@@ -1001,10 +1068,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
        },
        {
@@ -1026,6 +1093,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
        },
 );
@@ -1112,7 +1227,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++;
@@ -1121,7 +1236,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++;
@@ -1160,7 +1275,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";
@@ -1179,7 +1294,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";
@@ -1215,9 +1330,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;