chiark / gitweb /
[PATCH] add test for callout rule with a device that has no bus.
[elogind.git] / test / udev-test.pl
index 39d8450c34a9a52075013a763cb916e9fdb87fd8..ea1d8611efa6f377966c87d30dd7657d62e9d11e 100644 (file)
@@ -38,7 +38,7 @@ my @tests = (
                devpath  => "block/sda",
                expected => "boot_disk" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="boot_disk%n"
 REPLACE, KERNEL="ttyUSB0", NAME="visor"
 EOF
        },
@@ -48,7 +48,7 @@ EOF
                devpath  => "block/sda/sda1",
                expected => "boot_disk1" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="boot_disk%n"
 EOF
        },
        {
@@ -57,10 +57,30 @@ EOF
                devpath  => "block/sda/sda1",
                expected => "boot_disk1" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="?IBM-ESXS", NAME="boot_disk%n-1"
-LABEL, BUS="scsi", vendor="IBM-ESXS?", NAME="boot_disk%n-2"
-LABEL, BUS="scsi", vendor="IBM-ES??", NAME="boot_disk%n"
-LABEL, BUS="scsi", vendor="IBM-ESXSS", NAME="boot_disk%n-3"
+LABEL, BUS="scsi", SYSFS_vendor="?IBM-ESXS", NAME="boot_disk%n-1"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS?", NAME="boot_disk%n-2"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ES??", NAME="boot_disk%n"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXSS", NAME="boot_disk%n-3"
+EOF
+       },
+       {
+               desc     => "label test of multiple sysfs files",
+               subsys   => "block",
+               devpath  => "block/sda/sda1",
+               expected => "boot_disk1" ,
+               conf     => <<EOF
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", SYSFS_model="ST336605LW   !#", NAME="boot_diskX%n"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", SYSFS_model="ST336605LW    !#", NAME="boot_disk%n"
+EOF
+       },
+       {
+               desc     => "label test of max sysfs files",
+               subsys   => "block",
+               devpath  => "block/sda/sda1",
+               expected => "boot_disk1" ,
+               conf     => <<EOF
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", SYSFS_model="ST336605LW    !#", SYSFS_scsi_level="4", SYSFS_rev="B245", SYSFS_type="2", SYSFS_queue_depth="32", NAME="boot_diskXX%n"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", SYSFS_model="ST336605LW    !#", SYSFS_scsi_level="4", SYSFS_rev="B245", SYSFS_type="0", NAME="boot_disk%n"
 EOF
        },
        {
@@ -101,6 +121,39 @@ EOF
                expected => "visor" ,
                conf     => <<EOF
 REPLACE, KERNEL="ttyUSB0", NAME="visor"
+EOF
+       },
+       {
+               desc     => "Handle comment lines in config file (and replace kernel name)",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "visor" ,
+               conf     => <<EOF
+# this is a comment
+REPLACE, KERNEL="ttyUSB0", NAME="visor"
+
+EOF
+       },
+       {
+               desc     => "Handle comment lines in config file with whitespace (and replace kernel name)",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "visor" ,
+               conf     => <<EOF
+ # this is a comment with whitespace before the comment 
+REPLACE, KERNEL="ttyUSB0", NAME="visor"
+
+EOF
+       },
+       {
+               desc     => "Handle empty lines in config file (and replace kernel name)",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "visor" ,
+               conf     => <<EOF
+
+REPLACE, KERNEL="ttyUSB0", NAME="visor"
+
 EOF
        },
        {
@@ -150,15 +203,34 @@ EOF
                expected => "test-0:0:0:0" ,
                conf     => <<EOF
 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
+EOF
+       },
+       {
+               desc     => "callout program substitution (numbered part of)",
+               subsys   => "block",
+               devpath  => "block/sda/sda3",
+               expected => "link1" ,
+               conf     => <<EOF
+CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n node link1 link2", ID="node *", NAME="%1c", SYMLINK="%2c %3c"
+EOF
+       },
+       {
+               desc     => "callout for device with no bus",
+               subsys   => "tty",
+               devpath  => "class/tty/console",
+               expected => "TTY" ,
+               conf     => <<EOF
+CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n foo", ID="foo", NAME="foo"
+REPLACE, KERNEL="console", NAME="TTY"
 EOF
        },
        {
                desc     => "devfs disk naming substitution",
                subsys   => "block",
                devpath  => "block/sda",
-               expected => "lun0/disk" ,
+               expected => "lun0/disc" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="lun0/%D"
 EOF
        },
        {
@@ -167,7 +239,7 @@ EOF
                devpath  => "block/sda/sda2",
                expected => "lun0/part2" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="lun0/%D"
 EOF
        },
        {
@@ -196,7 +268,7 @@ EOF
                devpath  => "block/sda/sda2",
                expected => "1/2/a/b/symlink" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/node", SYMLINK="1/2/a/b/symlink"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="1/2/node", SYMLINK="1/2/a/b/symlink"
 EOF
        },
        {
@@ -205,7 +277,7 @@ EOF
                devpath  => "block/sda/sda2",
                expected => "1/2/symlink" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/symlink"
 EOF
        },
        {
@@ -214,7 +286,7 @@ EOF
                devpath  => "block/sda/sda2",
                expected => "1/2/c/d/symlink" ,
                conf     => <<EOF
-LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
+LABEL, BUS="scsi", SYSFS_vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
 EOF
        },
        {
@@ -266,7 +338,7 @@ print CONF "udev_permissions=\"$perm\"\n";
 close CONF;
 
 foreach my $config (@tests) {
-       $config->{conf} =~ m/^([A-Z]*).*/;
+       $config->{conf} =~ m/([A-Z]+)\s*,/;
        my $method  = $1;
 
        print "TEST: $config->{desc}\n";