udev-test.pl revision eef5447934a07279bc76f3f65b0302ddea8556ab
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# Provides automated testing of the udev binary.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# The whole test is self contained in this file, except the matching sysfs tree.
8c6fb701605a315f86160241e36fa643f8158ddevboxsync# Simply extend the @tests array, to add a new test variant.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# Every test is driven by its own temporary config file.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# This program prepares the environment, creates the config and calls udev.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# udev parses the rules, looks at the provided sysfs and
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# first creates and then removes the device node.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# After creation and removal the result is checked against the
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# expected value and the result is printed.
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync# Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync# Copyright (C) 2004 Leann Ogasawara <ogasawara@osdl.org>
4b9d6701570cb98fd36e209314239d104ec584d3vboxsyncuse warnings;
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncmy $udev_root = "udev-root/"; # !!! directory will be removed !!!
8c5d1958147c3988a7693b5a7666f5fe21a93b7bvboxsync# uncomment following line to run udev with valgrind.
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync# Should make this a runtime option to the script someday...
7bff28e0cedd8656acd24b420759649184d8cf00vboxsync#my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev";
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", SYSFS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="?IBM-ESXS", NAME="boot_disk%n-1"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS?", NAME="boot_disk%n-2"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ES??", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXSS", NAME="boot_disk%n-3"
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", ATTRS{model}=="ST336605LW !#", NAME="boot_diskX%n"
7bff28e0cedd8656acd24b420759649184d8cf00vboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", ATTRS{model}=="ST336605LW !#", NAME="boot_disk%n"
f44e23b1649344fbcc0e91b8699965f13d3bc4f7vboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", ATTRS{model}=="ST336605LW !#", ATTRS{scsi_level}=="4", ATTRS{rev}=="B245", ATTRS{type}=="0", ATTRS{queue_depth}=="32", NAME="boot_diskXX%n"
f44e23b1649344fbcc0e91b8699965f13d3bc4f7vboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", ATTRS{model}=="ST336605LW !#", ATTRS{scsi_level}=="4", ATTRS{rev}=="B245", ATTRS{type}=="0", NAME="boot_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "Handle comment lines in config file (and replace kernel name)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync# this is a comment
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "Handle comment lines in config file with whitespace (and replace kernel name)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync # this is a comment with whitespace before the comment
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "Handle whitespace only lines (and replace kernel name)",
af8ba507921d1f8c4e22a120b24de396b08e19efvboxsync # this is a comment with whitespace before the comment
2ebf77e955a41ebc4eaa4a0d2a9aaf05540d2e4dvboxsync desc => "Handle empty lines in config file (and replace kernel name)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "Handle backslashed multi lines in config file (and replace kernel name)",
6f17b5db855742e2cf9d2902a53b58c020f6bba9vboxsync desc => "preserve backslashes, if they are not for a newline",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncKERNEL=="ttyUSB0", PROGRAM=="/bin/echo -e \\101", RESULT=="A", NAME="aaa"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "Handle stupid backslashed multi lines in config file (and replace kernel name)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "parent device name match of scsi partition",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="first_disk%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync exp_name => "Major:8:minor:3:kernelnumber:3:id:0:0:0:0" ,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncBUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync exp_name => "Major:8:minor:3:kernelnumber:3:id:0:0:0:0" ,
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
f339edb4ba0e574e342ab15370e695f2a7f5fb25vboxsync desc => "test substitution chars (with length limit)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", IMPORT{file}="udev-test.conf", NAME="subdir/%E{udev_log}/node"
f339edb4ba0e574e342ab15370e695f2a7f5fb25vboxsync desc => "import of shell-value returned from program",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678 \\n TEST_key2=98765 \'", NAME="node\$env{TEST_KEY}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", ATTRS{vendor}=="IBM-ESXS", NAME="disk-%s{vendor}-%k"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="-special-*", NAME="%c-1-%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special--*", NAME="%c-2-%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-devic", NAME="%c-4-%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", NAME="%c-%n"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "program result substitution (newline removal)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo test", RESULT=="test", NAME="newline_removed"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "program with escaped format char (tricky: callout returns format char!)",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda3", NAME="%c"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="%c{7}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/sh -c 'echo foo3 foo4 foo5 foo6 foo7 foo8 foo9 | sed s/foo9/bar9/'", KERNEL=="sda3", NAME="%c{7}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "program arguments combined with apostrophes",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n 'foo3 foo4' 'foo5 foo6 foo7 foo8'", KERNEL=="sda3", NAME="%c{5}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsync desc => "characters before the %c{N} substitution",
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{7}"
1ace73711fa06807748eff26632c7273a1f7c2dbvboxsyncSUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL=="sda3", NAME="my-%c{6}"
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", DEVPATH=="*/sda/*", NAME="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2} %c{3}"
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}"
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"
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", NAME="sane"
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", NAME="uber"
SUBSYSTEMS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", NAME="replaced"
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
# 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
sub udev {
close CONF;
sub permissions_test {
my $userid;
my $groupid;
$error++;
sub major_minor_test {
$error++;
sub symlink_test {
my ($rules) = @_;
if ($output =~ m/(.*)-> (.*)/) {
$error++;
$error++;
sub run_test {
print "device \'$rules->{devpath}\' expecting symlink '$rules->{exp_name}' to node \'$rules->{exp_target}\'\n";
$error++
$error++;
$error++;
close CONF;
$test_num++;
unlink($udev_rules);
unlink($udev_conf);