udev-test.pl revision 83be97ba211c4f69e7fd9f16f57ca7210a116a7d
# udev-test
#
# Provides automated testing of the udev binary.
# The whole test is self contained in this file, except the matching sysfs tree.
# Simply extend the @tests array, to add a new test variant.
#
# Every test is driven by its own temporary config file.
# This program prepares the environment, creates the config and calls udev.
#
# udev reads the config, looks at the provided sysfs and
# first creates and then removes the device node.
# After creation and removal the result is checked against the
# expected value and the result is printed.
#
# happy testing,
# Kay Sievers <kay.sievers@vrfy.org>, 2003
use warnings;
use strict;
my $sysfs = "sys/";
my $udev_bin = "../udev";
my $udev_db = ".udev.tdb";
my $perm = "udev.permissions";
my $main_conf = "udev-test.conf";
my $conf_tmp = "udev-test.rules";
my @tests = (
{
desc => "label test of scsi disc",
subsys => "block",
expected => "boot_disk" ,
},
{
desc => "label test of scsi partition",
subsys => "block",
expected => "boot_disk1" ,
},
{
desc => "label test of pattern match",
subsys => "block",
expected => "boot_disk1" ,
},
{
desc => "catch device by *",
subsys => "tty",
expected => "visor/0" ,
},
{
desc => "catch device by ?",
subsys => "tty",
expected => "visor/0" ,
},
{
desc => "catch device by character class",
subsys => "tty",
expected => "visor/0" ,
},
{
desc => "replace kernel name",
subsys => "tty",
expected => "visor" ,
},
{
desc => "subdirectory handling",
subsys => "tty",
},
{
desc => "place on bus of scsi partition",
subsys => "block",
expected => "first_disk3" ,
},
{
desc => "test NAME substitution chars",
subsys => "block",
expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
},
{
desc => "callout result substitution",
subsys => "block",
expected => "special-device-3" ,
},
{
desc => "callout program substitution",
subsys => "block",
expected => "test-0:0:0:0" ,
},
{
desc => "devfs disk naming substitution",
subsys => "block",
},
{
desc => "devfs disk naming substitution",
subsys => "block",
},
{
desc => "callout bus type",
subsys => "block",
expected => "scsi-0:0:0:0" ,
},
);
# set env
sub udev {
# create temporary config
close CONF;
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
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 $method = $1;
print "TEST: $config->{desc}\n";
print "method \'$method\' for \'$config->{devpath}\' expecting node \'$config->{expected}\'\n";
if (-e "$PWD/$udev_root$config->{expected}") {
print "add: ok ";
} else {
print "add: error\n";
system("tree $udev_root");
print "\n";
$error++;
}
if (-e "$PWD/$udev_root$config->{expected}") {
print "remove: error\n\n";
system("tree $udev_root");
$error++;
} else {
print "remove: ok\n\n";
}
}
print "$error errors occured\n\n";
# cleanup
unlink($udev_db);
system("rm -rf $udev_root");
unlink($conf_tmp);
unlink($main_conf);