udev-test.pl revision 4ec9c3e79771aa95586390cecff4218cc8938160
# 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 parses the rules, 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.
#
# Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
# Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
use warnings;
use strict;
my $valgrind = 0;
my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
my $udev_root = "udev-root/";
my $udev_conf = "udev-test.conf";
my $udev_rules = "udev-test.rules";
my @tests = (
{
desc => "no rules",
subsys => "block",
exp_name => "sda" ,
exp_rem_error => "yes",
#
},
{
desc => "label test of scsi disc",
subsys => "block",
exp_name => "boot_disk" ,
SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", SYMLINK+="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
},
{
desc => "label test of scsi disc",
subsys => "block",
exp_name => "boot_disk" ,
},
{
desc => "label test of scsi disc",
subsys => "block",
exp_name => "boot_disk" ,
},
{
desc => "label test of scsi partition",
subsys => "block",
exp_name => "boot_disk1" ,
},
{
desc => "label test of pattern match",
subsys => "block",
exp_name => "boot_disk1" ,
},
{
desc => "label test of multiple sysfs files",
subsys => "block",
exp_name => "boot_disk1" ,
},
{
desc => "label test of max sysfs files (skip invalid rule)",
subsys => "block",
exp_name => "boot_disk1" ,
SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", ATTRS{queue_depth}=="32", SYMLINK+="boot_diskXX%n"
SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", SYMLINK+="boot_disk%n"
},
{
desc => "catch device by *",
subsys => "tty",
exp_name => "modem/0" ,
},
{
desc => "catch device by * - take 2",
subsys => "tty",
exp_name => "modem/0" ,
},
{
desc => "catch device by ?",
subsys => "tty",
exp_name => "modem/0" ,
},
{
desc => "catch device by character class",
subsys => "tty",
exp_name => "modem/0" ,
},
{
desc => "replace kernel name",
subsys => "tty",
exp_name => "modem" ,
},
{
desc => "Handle comment lines in config file (and replace kernel name)",
subsys => "tty",
exp_name => "modem" ,
# this is a comment
},
{
desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
subsys => "tty",
exp_name => "modem" ,
# this is a comment with whitespace before the comment
},
{
desc => "Handle whitespace only lines (and replace kernel name)",
subsys => "tty",
exp_name => "whitespace" ,
# this is a comment with whitespace before the comment
},
{
desc => "Handle empty lines in config file (and replace kernel name)",
subsys => "tty",
exp_name => "modem" ,
},
{
desc => "Handle backslashed multi lines in config file (and replace kernel name)",
subsys => "tty",
exp_name => "modem" ,
KERNEL=="ttyACM0", \\
SYMLINK+="modem"
},
{
desc => "preserve backslashes, if they are not for a newline",
subsys => "tty",
exp_name => "aaa",
},
{
desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
subsys => "tty",
exp_name => "modem" ,
#
\\
\\
#\\
KERNEL=="ttyACM0", \\
SYMLINK+="modem"
},
{
desc => "subdirectory handling",
subsys => "tty",
},
{
desc => "parent device name match of scsi partition",
subsys => "block",
exp_name => "first_disk5" ,
},
{
desc => "test substitution chars",
subsys => "block",
exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
},
{
desc => "import of shell-value file",
subsys => "block",
},
{
desc => "import of shell-value returned from program",
subsys => "block",
exp_name => "node12345678",
SUBSYSTEMS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678\\n TEST_key2=98765\'", SYMLINK+="node\$env{TEST_KEY}"
},
{
desc => "sustitution of sysfs value (%s{file})",
subsys => "block",
exp_name => "disk-ATA-sda" ,
},
{
desc => "program result substitution",
subsys => "block",
exp_name => "special-device-5" ,
not_exp_name => "not" ,
},
{
desc => "program result substitution (newline removal)",
subsys => "block",
exp_name => "newline_removed" ,
},
{
desc => "program result substitution",
subsys => "block",
exp_name => "test-0:0:0:0" ,
},
{
desc => "program with lots of arguments",
subsys => "block",
exp_name => "foo9" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="%c{7}"
},
{
desc => "program with subshell",
subsys => "block",
exp_name => "bar9" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda5", SYMLINK+="%c{7}"
},
{
desc => "program arguments combined with apostrophes",
subsys => "block",
exp_name => "foo7" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda5", SYMLINK+="%c{5}"
},
{
desc => "characters before the %c{N} substitution",
subsys => "block",
exp_name => "my-foo9" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{7}"
},
{
desc => "substitute the second to last argument",
subsys => "block",
exp_name => "my-foo8" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda5", SYMLINK+="my-%c{6}"
},
{
desc => "test substitution by variable name",
subsys => "block",
exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", SYMLINK+="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
},
{
desc => "test substitution by variable name 2",
subsys => "block",
exp_name => "Major:8-minor:5-kernelnumber:5-id:0:0:0:0",
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", SYMLINK+="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
},
{
desc => "test substitution by variable name 3",
subsys => "block",
exp_name => "850:0:0:05" ,
},
{
desc => "test substitution by variable name 4",
subsys => "block",
exp_name => "855" ,
},
{
desc => "test substitution by variable name 5",
subsys => "block",
exp_name => "8550:0:0:0" ,
},
{
desc => "non matching SUBSYSTEMS for device with no parent",
subsys => "tty",
exp_name => "TTY",
},
{
desc => "non matching SUBSYSTEMS",
subsys => "tty",
exp_name => "TTY" ,
},
{
desc => "ATTRS match",
subsys => "tty",
exp_name => "foo" ,
},
{
desc => "ATTR (empty file)",
subsys => "tty",
exp_name => "empty" ,
},
{
desc => "ATTR (non-existent file)",
subsys => "tty",
exp_name => "non-existent" ,
},
{
desc => "program and bus type match",
subsys => "block",
exp_name => "scsi-0:0:0:0" ,
},
{
desc => "sysfs parent hierarchy",
subsys => "tty",
exp_name => "modem" ,
},
{
desc => "name test with ! in the name",
subsys => "block",
},
{
desc => "name test with ! in the name, but no matching rule",
subsys => "block",
exp_rem_error => "yes",
},
{
desc => "KERNELS rule",
subsys => "block",
exp_name => "scsi-0:0:0:0",
},
{
desc => "KERNELS wildcard all",
subsys => "block",
exp_name => "scsi-0:0:0:0",
},
{
desc => "KERNELS wildcard partial",
subsys => "block",
exp_name => "scsi-0:0:0:0",
},
{
desc => "KERNELS wildcard partial 2",
subsys => "block",
exp_name => "scsi-0:0:0:0",
},
{
desc => "substitute attr with link target value (first match)",
subsys => "block",
exp_name => "driver-is-sd",
},
{
desc => "substitute attr with link target value (currently selected device)",
subsys => "block",
exp_name => "driver-is-ahci",
},
{
desc => "ignore ATTRS attribute whitespace",
subsys => "block",
exp_name => "ignored",
},
{
desc => "do not ignore ATTRS attribute whitespace",
subsys => "block",
exp_name => "matched-with-space",
},
{
desc => "permissions USER=bad GROUP=name",
subsys => "tty",
exp_name => "tty33",
exp_perms => "0:0:0600",
},
{
desc => "permissions OWNER=5000",
subsys => "block",
exp_name => "node",
exp_perms => "5000::0600",
},
{
desc => "permissions GROUP=100",
subsys => "block",
exp_name => "node",
exp_perms => ":100:0660",
},
{
desc => "textual user id",
subsys => "block",
exp_name => "node",
exp_perms => "nobody::0600",
},
{
desc => "textual group id",
subsys => "block",
exp_name => "node",
exp_perms => ":daemon:0660",
},
{
subsys => "block",
exp_name => "node",
exp_perms => "root:mail:0660",
},
{
desc => "permissions MODE=0777",
subsys => "block",
exp_name => "node",
exp_perms => "::0777",
},
{
desc => "permissions OWNER=5000 GROUP=100 MODE=0777",
subsys => "block",
exp_name => "node",
exp_perms => "5000:100:0777",
},
{
desc => "permissions OWNER to 5000",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "5000::",
},
{
desc => "permissions GROUP to 100",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => ":100:0660",
},
{
desc => "permissions MODE to 0060",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "::0060",
},
{
desc => "permissions OWNER, GROUP, MODE",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "5000:100:0777",
},
{
desc => "permissions only rule",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "5000:100:0777",
},
{
desc => "multiple permissions only rule",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "3000:4000:0777",
},
{
desc => "permissions only rule with override at SYMLINK+ rule",
subsys => "tty",
exp_name => "ttyACM0",
exp_perms => "3000:8000:0777",
},
{
subsys => "block",
exp_name => "node",
exp_majorminor => "8:0",
},
{
desc => "big major number test",
subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake1",
exp_name => "node",
exp_majorminor => "4095:1",
},
{
desc => "big major and big minor number test",
subsys => "misc",
devpath => "/devices/virtual/misc/misc-fake89999",
exp_name => "node",
exp_majorminor => "4095:89999",
},
{
desc => "multiple symlinks with format char",
subsys => "tty",
exp_name => "symlink2-ttyACM0",
},
{
desc => "multiple symlinks with a lot of s p a c e s",
subsys => "tty",
exp_name => "one",
not_exp_name => " ",
},
{
desc => "symlink creation (same directory)",
subsys => "tty",
exp_name => "modem0",
},
{
desc => "symlink creation (relative link forward)",
subsys => "block",
exp_name => "1/2/symlink" ,
exp_target => "a/b/node",
exp_rem_error => "yes",
},
{
desc => "symlink creation (relative link back and forward)",
subsys => "block",
exp_target => "../../a/b/node",
exp_rem_error => "yes",
},
{
desc => "multiple symlinks",
subsys => "tty",
exp_name => "second-0" ,
},
{
desc => "symlink name '.'",
subsys => "block",
exp_name => ".",
exp_add_error => "yes",
exp_rem_error => "yes",
},
{
desc => "symlink node to itself",
subsys => "tty",
exp_name => "link",
exp_add_error => "yes",
exp_rem_error => "yes",
option => "clean",
},
{
desc => "symlink %n substitution",
subsys => "tty",
exp_name => "symlink0",
},
{
desc => "symlink %k substitution",
subsys => "tty",
exp_name => "symlink-ttyACM0",
},
{
desc => "symlink %M:%m substitution",
subsys => "tty",
exp_name => "major-166:0",
},
{
desc => "symlink %b substitution",
subsys => "block",
exp_name => "symlink-0:0:0:0",
exp_target => "node",
},
{
desc => "symlink %c substitution",
subsys => "tty",
exp_name => "test",
},
{
desc => "symlink %c{N} substitution",
subsys => "tty",
exp_name => "test",
},
{
desc => "symlink %c{N+} substitution",
subsys => "tty",
exp_name => "this",
},
{
desc => "symlink only rule with %c{N+}",
subsys => "block",
exp_name => "test",
},
{
desc => "symlink %s{filename} substitution",
subsys => "tty",
exp_name => "166:0",
},
{
desc => "program result substitution (numbered part of)",
subsys => "block",
exp_name => "link1",
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", SYMLINK+="%c{2} %c{3}"
},
{
desc => "program result substitution (numbered part of+)",
subsys => "block",
exp_name => "link4",
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", SYMLINK+="%c{2+}"
},
{
desc => "SUBSYSTEM match test",
subsys => "block",
exp_name => "node",
},
{
desc => "DRIVERS match test",
subsys => "block",
exp_name => "node",
},
{
desc => "temporary node creation test",
subsys => "block",
exp_name => "node",
},
{
desc => "parent node name substitution test sequence 1/2 (keep)",
subsys => "block",
exp_name => "main_device",
option => "keep",
exp_rem_error => "yes",
},
{
desc => "parent node name substitution test sequence 2/2 (clean)",
subsys => "block",
exp_name => "main_device-part-1",
option => "clean",
},
{
desc => "udev_root substitution",
subsys => "block",
exp_name => "start-udev-root-end",
},
{
desc => "last_rule option",
subsys => "block",
exp_name => "last",
},
{
desc => "negation KERNEL!=",
subsys => "block",
exp_name => "match",
},
{
desc => "negation SUBSYSTEM!=",
subsys => "block",
exp_name => "not-anything",
},
{
desc => "negation PROGRAM!= exit code",
subsys => "block",
exp_name => "nonzero-program",
},
{
desc => "test for whitespace between the operator",
subsys => "block",
exp_name => "true",
},
{
desc => "ENV{} test",
subsys => "block",
exp_name => "true",
},
{
desc => "ENV{} test",
subsys => "block",
exp_name => "true",
SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sdax1", SYMLINK+="no"
SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", SYMLINK+="true"
},
{
desc => "ENV{} test (assign)",
subsys => "block",
exp_name => "true",
},
{
desc => "ENV{} test (assign 2 times)",
subsys => "block",
exp_name => "true",
},
{
desc => "ENV{} test (assign2)",
subsys => "block",
exp_name => "part",
},
{
desc => "untrusted string sanitize",
subsys => "block",
exp_name => "sane",
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", SYMLINK+="sane"
},
{
desc => "untrusted string sanitize (don't replace utf8)",
subsys => "block",
exp_name => "uber",
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", SYMLINK+="uber"
},
{
desc => "untrusted string sanitize (replace invalid utf8)",
subsys => "block",
exp_name => "replaced",
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", SYMLINK+="replaced"
},
{
desc => "read sysfs value from parent device",
subsys => "block",
exp_name => "serial-354172020305000",
},
{
desc => "match against empty key string",
subsys => "block",
exp_name => "ok",
},
{
desc => "check ACTION value",
subsys => "block",
exp_name => "ok",
},
{
desc => "test RUN key remove",
subsys => "block",
exp_name => "testsymlink2",
exp_target => "ok2",
},
{
desc => "final assignment",
subsys => "block",
exp_name => "ok",
exp_perms => "root:tty:0640",
},
{
desc => "final assignment 2",
subsys => "block",
exp_name => "ok",
exp_perms => "root:tty:0640",
},
{
desc => "env substitution",
subsys => "block",
exp_name => "node-add-me",
},
{
desc => "reset list to current value",
subsys => "tty",
exp_name => "three",
not_exp_name => "two",
},
{
desc => "test empty SYMLINK+ (empty override)",
subsys => "tty",
exp_name => "right",
not_exp_name => "wrong",
},
{
desc => "test multi matches",
subsys => "tty",
exp_name => "right",
},
{
desc => "test multi matches 2",
subsys => "tty",
exp_name => "right",
},
{
desc => "test multi matches 3",
subsys => "tty",
exp_name => "right",
},
{
desc => "test multi matches 4",
subsys => "tty",
exp_name => "right",
},
{
desc => "IMPORT parent test sequence 1/2 (keep)",
subsys => "block",
exp_name => "parent",
option => "keep",
},
{
desc => "IMPORT parent test sequence 2/2 (keep)",
subsys => "block",
exp_name => "parentenv-parent_right",
option => "clean",
KERNEL=="sda1", IMPORT{parent}="PARENT*", SYMLINK+="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
},
{
desc => "GOTO test",
subsys => "block",
exp_name => "right",
LABEL="end"
},
{
desc => "GOTO label does not exist",
subsys => "block",
exp_name => "right",
LABEL="exists"
},
{
desc => "SYMLINK+ compare test",
subsys => "block",
exp_name => "right",
not_exp_name => "wrong",
},
{
desc => "invalid key operation",
subsys => "block",
exp_name => "yes",
},
{
desc => "operator chars in attribute",
subsys => "block",
exp_name => "yes",
},
{
desc => "overlong comment line",
subsys => "block",
exp_name => "yes",
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
},
{
subsys => "block",
exp_name => "00:16:41:e2:8d:ff",
},
{
desc => "TEST absolute path",
subsys => "block",
exp_name => "there",
},
{
subsys => "block",
exp_name => "yes",
},
{
desc => "TEST relative path",
subsys => "block",
exp_name => "relative",
},
{
desc => "TEST wildcard substitution (find queue/nr_requests)",
subsys => "block",
exp_name => "found-subdir",
},
{
desc => "TEST MODE=0000",
subsys => "block",
exp_name => "sda",
exp_perms => "0:0:0000",
exp_rem_error => "yes",
},
{
desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
subsys => "block",
exp_name => "sda",
exp_perms => "5000:100:0400",
exp_rem_error => "yes",
},
{
desc => "TEST PROGRAM feeds MODE with overflow",
subsys => "block",
exp_name => "sda",
exp_perms => "0:0:0600",
exp_rem_error => "yes",
KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400letsdoabuffferoverflow0123456789012345789012345678901234567890", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
},
{
subsys => "block",
exp_name => "sda-8741C4G-end",
exp_perms => "0:0:0600",
},
);
# set env
sub udev {
# create temporary rules
close CONF;
if ($valgrind > 0) {
system("$udev_bin_valgrind");
} else {
system("$udev_bin");
}
}
my $error = 0;
sub permissions_test {
my $wrong = 0;
my $userid;
my $groupid;
if ($1 ne "") {
if (defined(getpwnam($1))) {
$userid = int(getpwnam($1));
} else {
$userid = $1;
}
}
if ($2 ne "") {
if (defined(getgrnam($2))) {
$groupid = int(getgrnam($2));
} else {
$groupid = $2;
}
}
if ($3 ne "") {
}
if ($wrong == 0) {
print "permissions: ok\n";
} else {
printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3);
print "permissions: error\n";
$error++;
sleep(1);
}
}
sub major_minor_test {
my $wrong = 0;
$rules->{exp_majorminor} =~ m/^(.*):(.*)$/;
if ($1 ne "") {
}
if ($2 ne "") {
}
if ($wrong == 0) {
print "major:minor: ok\n";
} else {
printf " expected major:minor is: %i:%i\n", $1, $2;
print "major:minor: error\n";
$error++;
sleep(1);
}
}
sub symlink_test {
my ($rules) = @_;
if ($output =~ m/(.*)-> (.*)/) {
print "symlink: ok\n";
} else {
print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
print " created symlink from: \'$rules->{exp_name}\' to \'$2\'\n";
print "symlink: error";
if ($rules->{exp_add_error}) {
print " as expected\n";
} else {
print "\n";
$error++;
sleep(1);
}
}
} else {
print " expected symlink from: \'$rules->{exp_name}\' to \'$rules->{exp_target}\'\n";
print "symlink: not created";
if ($rules->{exp_add_error}) {
print " as expected\n";
} else {
print "\n";
$error++;
sleep(1);
}
}
}
sub make_udev_root {
system("rm -rf $udev_root");
mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
# setting group and mode of udev_root ensures the tests work
# even if the parent directory has setgid bit enabled.
}
sub run_test {
print "TEST $number: $rules->{desc}\n";
if ($rules->{exp_target}) {
print "device \'$rules->{devpath}\' expecting link '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
} else {
}
if (defined($rules->{not_exp_name})) {
if ((-e "$PWD/$udev_root$rules->{not_exp_name}") ||
(-l "$PWD/$udev_root$rules->{not_exp_name}")) {
print "nonexistent: error \'$rules->{not_exp_name}\' not expected to be there\n";
$error++;
sleep(1);
}
}
if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
(-l "$PWD/$udev_root$rules->{exp_name}")) {
}
if (defined($rules->{exp_majorminor})) {
}
if (defined($rules->{exp_target})) {
}
print "add: ok\n";
} else {
print "add: error";
if ($rules->{exp_add_error}) {
print " as expected\n";
} else {
print "\n";
system("tree $udev_root");
print "\n";
$error++;
sleep(1);
}
}
print "\n\n";
return;
}
if ((-e "$PWD/$udev_root$rules->{exp_name}") ||
(-l "$PWD/$udev_root$rules->{exp_name}")) {
print "remove: error";
if ($rules->{exp_rem_error}) {
print " as expected\n";
} else {
print "\n";
system("tree $udev_root");
print "\n";
$error++;
sleep(1);
}
} else {
print "remove: ok\n";
}
print "\n";
make_udev_root ();
}
}
# only run if we have root permissions
# due to mknod restrictions
if (!($<==0)) {
print "Must have root permissions to run properly.\n";
exit;
}
# prepare
# create config file
print CONF "udev_root=\"$udev_root\"\n";
print CONF "udev_run=\"$udev_root/.udev\"\n";
print CONF "udev_rules=\"$PWD\"\n";
print CONF "udev_log=\"err\"\n";
close CONF;
my $test_num = 1;
my @list;
$valgrind = 1;
printf("using valgrind\n");
} else {
}
}
if ($list[0]) {
print "udev-test will run test number $arg:\n\n";
} else {
print "test does not exist.\n";
}
}
} else {
# test all
print "\nudev-test will run ".($#tests + 1)." tests:\n\n";
$test_num++;
}
}
print "$error errors occured\n\n";
# cleanup
system("rm -rf $udev_root");
unlink($udev_rules);
unlink($udev_conf);
if ($error > 0) {
exit(1);
}
exit(0);