udev-test.pl revision 9dae0e89b9d2138e028c2a69170ba2a96503b766
# 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" ,
},
{
desc => "label test of scsi disc (old key names)",
subsys => "block",
exp_name => "boot_disk" ,
SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
},
{
desc => "label test of scsi disc (old key names)",
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", NAME="boot_diskXX%n"
SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", ATTRS{model}=="ST910021AS", ATTRS{scsi_level}=="6", ATTRS{rev}=="4.06", ATTRS{type}=="0", NAME="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", \\
NAME="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", \\
NAME="modem"
},
{
desc => "subdirectory handling",
subsys => "tty",
},
{
desc => "parent device name match of scsi partition",
subsys => "block",
exp_name => "first_disk5" ,
},
{
desc => "test substitution chars (old key names)",
subsys => "block",
exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
},
{
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\'", NAME="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" ,
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n"
},
{
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", NAME="%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", NAME="%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", NAME="%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", NAME="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", NAME="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", NAME="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/*", NAME="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 => "create all possible partitions",
subsys => "block",
exp_name => "boot_disk15" ,
exp_majorminor => "8:15",
},
{
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",
},
{
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:0660",
},
{
desc => "permissions OWNER=5000",
subsys => "block",
exp_name => "node",
exp_perms => "5000::0660",
},
{
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::0660",
},
{
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 NAME 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",
exp_target => "ttyACM-0",
},
{
desc => "multiple symlinks with a lot of s p a c e s",
subsys => "tty",
exp_name => "one",
not_exp_name => " ",
exp_target => "ttyACM0",
},
{
desc => "symlink creation (same directory)",
subsys => "tty",
exp_name => "modem0",
exp_target => "ttyACM0",
},
{
desc => "symlink creation (relative link forward)",
subsys => "block",
exp_name => "1/2/symlink" ,
exp_target => "a/b/node",
},
{
desc => "symlink creation (relative link back and forward)",
subsys => "block",
exp_target => "../../a/b/node",
},
{
desc => "multiple symlinks",
subsys => "tty",
exp_name => "second-0" ,
exp_target => "modem" ,
},
{
desc => "symlink only rule",
subsys => "block",
exp_name => "symlink-only2",
exp_target => "link",
},
{
desc => "symlink name '.'",
subsys => "block",
exp_name => ".",
exp_target => "link",
exp_add_error => "yes",
exp_rem_error => "yes",
},
{
desc => "symlink node to itself",
subsys => "tty",
exp_name => "link",
exp_target => "link",
exp_add_error => "yes",
exp_rem_error => "yes",
option => "clean",
},
{
desc => "symlink %n substitution",
subsys => "tty",
exp_name => "symlink0",
exp_target => "ttyACM0",
},
{
desc => "symlink %k substitution",
subsys => "tty",
exp_name => "symlink-ttyACM0",
exp_target => "ttyACM0",
},
{
desc => "symlink %M:%m substitution",
subsys => "tty",
exp_name => "major-166:0",
exp_target => "ttyACM0",
},
{
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",
exp_target => "ttyACM0",
},
{
desc => "symlink %c{N} substitution",
subsys => "tty",
exp_name => "test",
exp_target => "ttyACM0",
},
{
desc => "symlink %c{N+} substitution",
subsys => "tty",
exp_name => "this",
exp_target => "ttyACM0",
},
{
desc => "symlink only rule with %c{N+}",
subsys => "block",
exp_name => "test",
exp_target => "link",
},
{
desc => "symlink %s{filename} substitution",
subsys => "tty",
exp_name => "166:0",
exp_target => "ttyACM0",
},
{
desc => "program result substitution (numbered part of)",
subsys => "block",
exp_name => "link1",
exp_target => "node",
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2} %c{3}"
},
{
desc => "program result substitution (numbered part of+)",
subsys => "block",
exp_name => "link4",
exp_target => "node",
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}"
},
{
desc => "ignore rule test",
subsys => "block",
exp_name => "nothing",
not_exp_name => "node",
exp_add_error => "yes",
},
{
desc => "all_partitions, option-only rule",
subsys => "block",
exp_name => "node6",
},
{
desc => "all_partitions, option-only rule (fail on partition)",
subsys => "block",
exp_name => "node6",
exp_add_error => "yes",
},
{
desc => "ignore remove event test",
subsys => "block",
exp_name => "node",
exp_rem_error => "yes",
},
{
desc => "ignore remove event test (with all partitions)",
subsys => "block",
exp_name => "node14",
exp_rem_error => "yes",
option => "clean",
},
{
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 => "devpath substitution test",
subsys => "block",
exp_name => "sda",
SUBSYSTEMS=="scsi", KERNEL=="sda", PROGRAM=="/bin/echo %p", RESULT=="/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda" NAME="%k"
},
{
desc => "parent node name substitution test sequence 1/2 (keep)",
subsys => "block",
exp_name => "main_device",
option => "keep",
},
{
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", NAME="no"
SUBSYSTEMS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="*/block/sda/sda1", NAME="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_", NAME="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", NAME="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", NAME="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 => "apply NAME final",
subsys => "block",
exp_name => "link",
exp_target => "ok",
},
{
desc => "test RUN key",
subsys => "block",
exp_name => "testsymlink",
exp_target => "ok",
exp_rem_error => "yes",
option => "clean",
},
{
desc => "test RUN key and DEVNAME",
subsys => "block",
exp_name => "testsymlink",
exp_target => "ok",
exp_rem_error => "yes",
option => "clean",
},
{
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",
exp_target => "node",
},
{
desc => "test empty NAME",
subsys => "tty",
exp_name => "<none>",
not_exp_name => "ttyACM0",
exp_add_error => "yes",
},
{
desc => "test empty NAME (empty override)",
subsys => "tty",
exp_name => "<none>",
not_exp_name => "wrong",
exp_add_error => "yes",
},
{
desc => "test empty NAME (non-empty override)",
subsys => "tty",
exp_name => "right",
},
{
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",
},
{
desc => "GOTO test",
subsys => "block",
exp_name => "right",
LABEL="end"
},
{
desc => "GOTO label does not exist",
subsys => "block",
exp_name => "right",
LABEL="exists"
},
{
desc => "NAME compare test",
subsys => "block",
exp_name => "link",
exp_target => "node",
not_exp_name => "wronglink",
},
{
desc => "NAME compare test 2",
subsys => "block",
exp_name => "link2",
exp_target => "sda1",
not_exp_name => "link",
},
{
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",
},
{
desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
subsys => "block",
exp_name => "sda",
exp_perms => "5000:100:0400",
},
{
desc => "TEST PROGRAM feeds MODE with overflow",
subsys => "block",
exp_name => "sda",
exp_perms => "0:0:0660",
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:0660",
},
);
# 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++;
}
}
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++;
}
}
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++;
}
}
} 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++;
}
}
}
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 symlink '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
} else {
print "device \'$rules->{devpath}\' expecting node \'$rules->{exp_name}\'\n";
}
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++
}
}
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++;
}
}
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++;
}
} 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_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);