chiark / gitweb /
[PATCH] Add another test to udev-test.pl and fix a bug when only running 1 test.
[elogind.git] / test / udev-test.pl
index 0700e535767ef79d9115bede4e9d0a9405b8d1c5..62a2bb327b16990521f930a1acbdec09d4b6abf6 100644 (file)
@@ -90,6 +90,16 @@ EOF
                expected => "visor/0" ,
                conf     => <<EOF
 KERNEL="ttyUSB*", NAME="visor/%n"
+EOF
+       },
+       {
+               desc     => "catch device by * - take 2",
+               subsys   => "tty",
+               devpath  => "class/tty/ttyUSB0",
+               expected => "visor/0" ,
+               conf     => <<EOF
+KERNEL="*USB1", NAME="bad"
+KERNEL="*USB0", NAME="visor/%n"
 EOF
        },
        {
@@ -326,6 +336,25 @@ EOF
                expected => "visor" ,
                conf     => <<EOF
 SYSFS_idProduct="2008", NAME="visor"
+EOF
+       },
+       {
+               desc     => "name test with ! in the name",
+               subsys   => "block",
+               devpath  => "block/rd!c0d0",
+               expected => "rd/c0d0" ,
+               conf     => <<EOF
+BUS="scsi", NAME="%k"
+KERNEL="ttyUSB0", NAME="visor"
+EOF
+       },
+       {
+               desc     => "name test with ! in the name, but no matching rule",
+               subsys   => "block",
+               devpath  => "block/rd!c0d0",
+               expected => "rd/c0d0" ,
+               conf     => <<EOF
+KERNEL="ttyUSB0", NAME="visor"
 EOF
        },
 );
@@ -350,25 +379,12 @@ sub udev {
        system("$udev_bin $subsys");
 }
 
-
-# prepare
-system("rm -rf $udev_root");
-mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
-
-# test
 my $error = 0;
-print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
 
-# create initial config file
-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 "udev_permissions=\"$perm\"\n";
-close CONF;
-
-foreach my $config (@tests) {
-       print "TEST: $config->{desc}\n";
+sub run_test {
+       my ($config, $number) = @_;
+       
+       print "TEST $number: $config->{desc}\n";
        print "device \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
 
        udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf});
@@ -392,6 +408,37 @@ foreach my $config (@tests) {
        }
 }
 
+# prepare
+system("rm -rf $udev_root");
+mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
+
+# create initial config file
+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 "udev_permissions=\"$perm\"\n";
+close CONF;
+
+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);
+} else {
+       # test all
+       print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
+
+       foreach my $config (@tests) {
+               run_test($config, $test_num);
+               $test_num++;
+
+       }
+}
+
 print "$error errors occured\n\n";
 
 # cleanup