chiark / gitweb /
[PATCH] add dumb script to show all sysfs devices in the system.
[elogind.git] / test / udev-test.pl
index ebd3c6a8a0b8da8cc23ca5906f71f6bfdd532e30..a7becf99df36bed2c976c8226822fb6b6a1f35ef 100644 (file)
@@ -158,6 +158,22 @@ EOF
  # this is a comment with whitespace before the comment 
 KERNEL="ttyUSB0", NAME="visor"
 
+EOF
+       },
+       {
+               desc            => "Handle whitespace only lines (and replace kernel name)",
+               subsys          => "tty",
+               devpath         => "/class/tty/ttyUSB0",
+               exp_name        => "whitespace" ,
+               conf            => <<EOF
+
+
+ # this is a comment with whitespace before the comment 
+KERNEL="ttyUSB0", NAME="whitespace"
+
+
 EOF
        },
        {
@@ -237,6 +253,15 @@ BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special--*", NAME="%c
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-device-", NAME="%c-3-%n"
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-devic", NAME="%c-4-%n"
 BUS="scsi", PROGRAM="/bin/echo -n special-device", RESULT="special-*", NAME="%c-%n"
+EOF
+       },
+       {
+               desc            => "program result substitution (no argument should be subsystem)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda3",
+               exp_name        => "subsys_block" ,
+               conf            => <<EOF
+BUS="scsi", PROGRAM="/bin/echo", RESULT="block", NAME="subsys_block"
 EOF
        },
        {
@@ -397,6 +422,16 @@ EOF
                exp_name        => "rd/c0d0" ,
                conf            => <<EOF
 KERNEL="ttyUSB0", NAME="visor"
+EOF
+       },
+       {
+               desc            => "name test with ! in the name for a partition",
+               subsys          => "block",
+               devpath         => "/block/cciss!c0d0/cciss!c0d0p1",
+               exp_name        => "cciss/c0d0p1" ,
+               conf            => <<EOF
+BUS="scsi", NAME="%k"
+KERNEL="ttyUSB0", NAME="visor"
 EOF
        },
        {
@@ -989,6 +1024,74 @@ EOF
                exp_target      => "node",
                conf            => <<EOF
 BUS="scsi", PROGRAM="/bin/echo -n node link1 link2 link3 link4", RESULT="node *", NAME="%c{1}", SYMLINK="%c{2+}"
+EOF
+       },
+       {
+               desc            => "enumeration char test (single test)",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "cdrom",
+               conf            => <<EOF
+KERNEL="sda", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test sequence (1/5 keep)",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "cdrom",
+               option          => "keep",
+               conf            => <<EOF
+KERNEL="sda", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test sequence 2/5 (keep)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda1",
+               exp_name        => "enum",
+               option          => "keep",
+               conf            => <<EOF
+KERNEL="sda1", NAME="enum%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test sequence 3/5 (keep)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda2",
+               exp_name        => "cdrom1",
+               option          => "keep",
+               conf            => <<EOF
+KERNEL="sda2", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test sequence 4/5 (keep)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda3",
+               exp_name        => "enum1",
+               option          => "keep",
+               conf            => <<EOF
+KERNEL="sda3", NAME="enum%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test sequence 5/5 (clean)",
+               subsys          => "block",
+               devpath         => "/block/sda/sda4",
+               exp_name        => "cdrom2",
+               option          => "clear",
+               conf            => <<EOF
+KERNEL="sda4", NAME="cdrom%e"
+EOF
+       },
+       {
+               desc            => "enumeration char test after cleanup (single test)",
+               subsys          => "block",
+               devpath         => "/block/sda",
+               exp_name        => "cdrom",
+               conf            => <<EOF
+KERNEL="sda", NAME="cdrom%e"
 EOF
        },
 );
@@ -997,7 +1100,6 @@ EOF
 $ENV{UDEV_TEST} = "yes";
 $ENV{SYSFS_PATH} = $sysfs;
 $ENV{UDEV_CONFIG_FILE} = $main_conf;
-$ENV{UDEV_NO_SLEEP} = "yes";
 $ENV{UDEV_NO_DEVD} = "yes";
 
 
@@ -1134,6 +1236,11 @@ sub run_test {
                }
        }
 
+       if (defined($config->{option}) && $config->{option} eq "keep") {
+               print "\n\n";
+               return;
+       }
+
        udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf});
        if ((-e "$PWD/$udev_root$config->{exp_name}") ||
            (-l "$PWD/$udev_root$config->{exp_name}")) {
@@ -1149,6 +1256,13 @@ sub run_test {
        } else {
                print "remove: ok\n\n";
        }
+
+       if (defined($config->{option}) && $config->{option} eq "clear") {
+               unlink($udev_db);
+               system("rm -rf $udev_root");
+               mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
+       }
+
 }
 
 # prepare
@@ -1168,9 +1282,13 @@ my $test_num = 1;
 if ($ARGV[0]) {
        # only run one test
        $test_num = $ARGV[0];
-       print "udev-test will run test number $test_num only\n";
 
-       run_test($tests[$test_num-1], $test_num);
+       if (defined($tests[$test_num-1]->{desc})) {
+               print "udev-test will run test number $test_num only:\n\n";
+               run_test($tests[$test_num-1], $test_num);
+       } else {
+               print "test does not exist.\n";
+       }
 } else {
        # test all
        print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
@@ -1178,7 +1296,6 @@ if ($ARGV[0]) {
        foreach my $config (@tests) {
                run_test($config, $test_num);
                $test_num++;
-
        }
 }