chiark / gitweb /
[PATCH] catch replace device by wildcard
[elogind.git] / test / udev-test.pl
index 613aa792d433f8bbf6cb29ff608e9de5245eaa17..8b967c353c6e5c0364433dc786ffd702498e75dd 100644 (file)
 use warnings;
 use strict;
 
-my $PWD = `pwd`;
-chomp($PWD);
-
+my $PWD = $ENV{PWD};
 my $sysfs     = "sys/";
 my $udev_bin  = "../udev";
 my $udev_root = "udev-root/"; # !!! directory will be removed !!!
-my $udev_db   = "udev.tdb";
+my $udev_db   = ".udev.tdb";
 my $perm      = "udev.permissions";
 my $conf_tmp  = "udev-test.config";
 
@@ -50,6 +48,15 @@ EOF
                expected => "boot_disk1" ,
                conf     => <<EOF
 LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n"
+EOF
+       },
+       {
+               desc     => "catch device by wildcard",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "visor/0" ,
+               conf     => <<EOF
+REPLACE, KERNEL="ttyUSB*", NAME="visor/%n"
 EOF
        },
        {
@@ -59,6 +66,15 @@ EOF
                expected => "visor" ,
                conf     => <<EOF
 REPLACE, KERNEL="ttyUSB0", NAME="visor"
+EOF
+       },
+       {
+               desc     => "subdirectory handling",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "sub/direct/ory/visor" ,
+               conf     => <<EOF
+REPLACE, KERNEL="ttyUSB0", NAME="sub/direct/ory/visor"
 EOF
        },
        {
@@ -80,7 +96,7 @@ TOPOLOGY, BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:b
 EOF
        },
        {
-               desc     => "callout result subtitution, only last should match",
+               desc     => "callout result substitution, only last should match",
                subsys   => "block",
                devpath  => "block/sda/sda3",
                expected => "special-device-3" ,
@@ -90,6 +106,44 @@ CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special--*", NAM
 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-device-", NAME="%c-3-%n"
 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-devic", NAME="%c-4-%n"
 CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n special-device", ID="special-*", NAME="%c-%n"
+EOF
+       },
+       {
+               desc     => "callout program substitution",
+               subsys   => "block",
+               devpath  => "block/sda/sda3",
+               expected => "test-0:0:0:0" ,
+               conf     => <<EOF
+CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n test-%b", ID="test-*", NAME="%c"
+EOF
+       },
+       {
+               desc     => "devfs disk naming substitution",
+               subsys   => "block",
+               devpath  => "block/sda",
+               expected => "lun0/disk" ,
+               conf     => <<EOF
+LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
+EOF
+       },
+       {
+               desc     => "devfs disk naming substitution",
+               subsys   => "block",
+               devpath  => "block/sda/sda2",
+               expected => "lun0/part2" ,
+               conf     => <<EOF
+LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D"
+EOF
+       },
+       {
+               desc     => "callout bus type",
+               subsys   => "block",
+               devpath  => "block/sda",
+               expected => "scsi-0:0:0:0" ,
+               conf     => <<EOF
+CALLOUT, BUS="usb", PROGRAM="/bin/echo -n usb-%b", ID="*", NAME="%c"
+CALLOUT, BUS="scsi", PROGRAM="/bin/echo -n scsi-%b", ID="*", NAME="%c"
+CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c"
 EOF
        },
 );
@@ -142,7 +196,6 @@ foreach my $config (@tests) {
                system("tree $udev_root");
                print "\n";
                $error++;
-#              next;
        }
 
        udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
@@ -158,7 +211,7 @@ foreach my $config (@tests) {
 print "$error errors occured\n\n";
 
 # cleanup
+unlink($udev_db);
 system("rm -rf $udev_root");
 unlink($conf_tmp);
-unlink($udev_db);