chiark / gitweb /
[PATCH] add tests to catch whitespace and comment config file parsing errors.
[elogind.git] / test / udev-test.pl
index 190b7ce4d6d36b9ed47f47f6daef47800d07404c..7afbd0d6fc34c0e7adce79ceb6313d9f76a1d7e0 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,10 @@ 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
        },
        {
@@ -101,6 +101,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 +183,24 @@ 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     => "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 +209,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 +238,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 +247,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 +256,16 @@ 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
+       },
+       {
+               desc     => "multiple symlinks",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "second-0" ,
+               conf     => <<EOF
+REPLACE, KERNEL="ttyUSB0", NAME="visor", SYMLINK="first-%n second-%n third-%n"
 EOF
        },
 );