my $sysfs = "sys/";
my $udev_bin = "../udev";
my $udev_root = "udev-root/"; # !!! directory will be removed !!!
-my $udev_db = ".udevdb";
my $udev_conf = "udev-test.conf";
my $udev_rules = "udev-test.rules";
EOF
},
{
- desc => "place on bus of scsi partition",
+ desc => "parent device name match of scsi partition",
subsys => "block",
devpath => "/block/sda/sda3",
exp_name => "first_disk3" ,
EOF
},
{
- desc => "test NAME substitution chars",
+ desc => "test substitution chars",
subsys => "block",
devpath => "/block/sda/sda3",
- exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
+ exp_name => "Major:8:minor:3:kernelnumber:3:id:0:0:0:0" ,
rules => <<EOF
-BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
+BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
EOF
},
{
- desc => "test NAME substitution chars (with length limit)",
+ desc => "test substitution chars (with length limit)",
subsys => "block",
devpath => "/block/sda/sda3",
exp_name => "M8-m3-n3-b0:0-sIBM" ,
rules => <<EOF
BUS=="scsi", ID=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-s%3s{vendor}"
+EOF
+ },
+ {
+ desc => "import of shell-value file",
+ subsys => "block",
+ devpath => "/block/sda",
+ exp_name => "subdir/info/node" ,
+ rules => <<EOF
+BUS=="scsi", IMPORT{file}="udev-test.conf", NAME="subdir/%E{udev_log}/node"
+KERNEL=="ttyUSB0", NAME="visor"
+EOF
+ },
+ {
+ desc => "import of shell-value returned from program",
+ subsys => "block",
+ devpath => "/block/sda",
+ exp_name => "node12345678",
+ rules => <<EOF
+BUS=="scsi", IMPORT="/bin/echo -e \' TEST_KEY=12345678 \\n TEST_key2=98765 \'", NAME="node\$env{TEST_KEY}"
+KERNEL=="ttyUSB0", NAME="visor"
EOF
},
{
BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-device-", NAME="%c-3-%n"
BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-devic", NAME="%c-4-%n"
BUS=="scsi", PROGRAM=="/bin/echo -n special-device", RESULT=="special-*", NAME="%c-%n"
-EOF
- },
- {
- desc => "program result substitution (no argument should be subsystem)",
- subsys => "block",
- devpath => "/block/sda/sda3",
- exp_name => "subsys_block" ,
- rules => <<EOF
-BUS=="scsi", PROGRAM=="/bin/echo", RESULT=="block", NAME="subsys_block"
EOF
},
{
EOF
},
{
- desc => "invalid program for device with no bus",
- subsys => "tty",
- devpath => "/class/tty/console",
- exp_name => "TTY" ,
+ desc => "test substitution by variable name",
+ subsys => "block",
+ devpath => "/block/sda/sda3",
+ exp_name => "Major:8-minor:3-kernelnumber:3-id:0:0:0:0",
rules => <<EOF
-BUS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo"
-KERNEL=="console", NAME="TTY"
+BUS=="scsi", ID=="0:0:0:0", NAME="Major:\$major-minor:\$minor-kernelnumber:\$number-id:\$id"
+EOF
+ },
+ {
+ desc => "test substitution by variable name 2",
+ subsys => "block",
+ devpath => "/block/sda/sda3",
+ exp_name => "Major:8-minor:3-kernelnumber:3-id:0:0:0:0",
+ rules => <<EOF
+BUS=="scsi", ID=="0:0:0:0", DEVPATH=="*/sda/*", NAME="Major:\$major-minor:%m-kernelnumber:\$number-id:\$id"
+EOF
+ },
+ {
+ desc => "test substitution by variable name 3",
+ subsys => "block",
+ devpath => "/block/sda/sda3",
+ exp_name => "830:0:0:03" ,
+ rules => <<EOF
+BUS=="scsi", ID=="0:0:0:0", DEVPATH=="*/sda/*", NAME="%M%m%b%n"
EOF
},
{
- desc => "valid program for device with no bus",
+ desc => "test substitution by variable name 4",
+ subsys => "block",
+ devpath => "/block/sda/sda3",
+ exp_name => "833" ,
+ rules => <<EOF
+BUS=="scsi", ID=="0:0:0:0", DEVPATH=="*/sda/*", NAME="\$major\$minor\$number"
+EOF
+ },
+ {
+ desc => "test substitution by variable name 5",
+ subsys => "block",
+ devpath => "/block/sda/sda3",
+ exp_name => "8330:0:0:0" ,
+ rules => <<EOF
+BUS=="scsi", ID=="0:0:0:0", DEVPATH=="*/sda/*", NAME="\$major%m%n\$id"
+EOF
+ },
+ {
+ desc => "non matching BUS for device with no parent",
subsys => "tty",
devpath => "/class/tty/console",
- exp_name => "foo" ,
+ exp_name => "TTY",
rules => <<EOF
-PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo"
+BUS=="scsi", PROGRAM=="/bin/echo -n foo", RESULT=="foo", NAME="foo"
KERNEL=="console", NAME="TTY"
EOF
},
{
- desc => "invalid label for device with no bus",
+ desc => "non matching BUS",
subsys => "tty",
devpath => "/class/tty/console",
exp_name => "TTY" ,
EOF
},
{
- desc => "valid label for device with no bus",
+ desc => "SYSFS match",
subsys => "tty",
devpath => "/class/tty/console",
exp_name => "foo" ,
exp_target => "ttyUSB0",
rules => <<EOF
KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
+EOF
+ },
+ {
+ desc => "multiple symlinks with a lot of s p a c e s",
+ subsys => "tty",
+ devpath => "/class/tty/ttyUSB0",
+ exp_name => "one",
+ not_exp_name => " ",
+ exp_target => "ttyUSB0",
+ rules => <<EOF
+KERNEL=="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK=" one two "
EOF
},
{
desc => "ignore rule test",
subsys => "block",
devpath => "/block/sda",
- exp_name => "node",
+ exp_name => "nothing",
+ not_exp_name => "node",
exp_add_error => "yes",
rules => <<EOF
BUS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore"
BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="yes", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sdax1", NAME="no"
BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="test", ENV{ACTION}=="add", ENV{DEVPATH}=="/block/sda/sda1", NAME="true"
BUS=="scsi", KERNEL=="sda1", ENV{ENV_KEY_TEST}=="bad", NAME="bad"
+EOF
+ },
+ {
+ desc => "ENV{} test (assign)",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "true",
+ rules => <<EOF
+BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}="true"
+BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="yes", NAME="no"
+BUS=="scsi", KERNEL=="sda1", ENV{ASSIGN}=="true", NAME="true"
+BUS=="scsi", KERNEL=="sda1", NAME="bad"
+EOF
+ },
+ {
+ desc => "ENV{} test (assign2)",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "part",
+ rules => <<EOF
+SUBSYSTEM=="block", KERNEL=="*[0-9]", ENV{PARTITION}="true", ENV{MAINDEVICE}="false"
+SUBSYSTEM=="block", KERNEL=="*[!0-9]", ENV{PARTITION}="false", ENV{MAINDEVICE}="true"
+ENV{MAINDEVICE}=="true", NAME="disk"
+ENV{PARTITION}=="true", NAME="part"
+NAME="bad"
EOF
},
{
devpath => "/block/sda/sda1",
exp_name => "sane",
rules => <<EOF
-BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT="name_ _/sbin/badprogram_", NAME="sane"
+BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e name; (/sbin/badprogram)", RESULT=="name_ _/sbin/badprogram_", NAME="sane"
+EOF
+ },
+ {
+ desc => "untrusted string sanitize (don't replace utf8)",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "uber",
+ rules => <<EOF
+BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xc3\\xbcber" RESULT=="\xc3\xbcber", NAME="uber"
+EOF
+ },
+ {
+ desc => "untrusted string sanitize (replace invalid utf8)",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "replaced",
+ rules => <<EOF
+BUS=="scsi", KERNEL=="sda1", PROGRAM=="/bin/echo -e \\xef\\xe8garbage", RESULT=="__garbage", NAME="replaced"
EOF
},
{
exp_rem_error => "yes",
option => "clean",
rules => <<EOF
-KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$DEVNAME` %r/testsymlink'"
+KERNEL=="sda", NAME="ok", RUN+="/bin/sh -c 'ln -s `basename \$\$DEVNAME` %r/testsymlink'"
KERNEL=="sda", NAME="not-ok"
EOF
},
KERNEL=="sda", GROUP:="nobody"
SUBSYSTEM=="block", MODE:="640"
KERNEL=="sda", GROUP="not-ok", MODE="0666", NAME="ok"
+EOF
+ },
+ {
+ desc => "env substitution",
+ subsys => "block",
+ devpath => "/block/sda",
+ exp_name => "node-add-me",
+ rules => <<EOF
+KERNEL=="sda", MODE="0666", NAME="node-\$env{ACTION}-me"
EOF
},
{
KERNEL=="ttyUSB[0-9]*", SYMLINK+="two"
KERNEL=="ttyUSB[0-9]*", SYMLINK="three"
KERNEL=="ttyUSB[0-9]*", NAME="node"
+EOF
+ },
+ {
+ desc => "test empty NAME",
+ subsys => "tty",
+ devpath => "/class/tty/ttyUSB0",
+ exp_name => "node",
+ not_exp_name => "wrong",
+ exp_add_error => "yes",
+ rules => <<EOF
+KERNEL=="ttyUSB[0-9]*", NAME=""
+KERNEL=="ttyUSB[0-9]*", NAME="wrong"
+EOF
+ },
+ {
+ desc => "test empty NAME 2",
+ subsys => "tty",
+ devpath => "/class/tty/ttyUSB0",
+ exp_name => "right",
+ rules => <<EOF
+KERNEL=="ttyUSB[0-9]*", NAME="right"
+KERNEL=="ttyUSB[0-9]*", NAME=""
+KERNEL=="ttyUSB[0-9]*", NAME="wrong"
+EOF
+ },
+ {
+ desc => "test multi matches",
+ subsys => "tty",
+ devpath => "/class/tty/ttyUSB0",
+ exp_name => "right",
+ rules => <<EOF
+KERNEL=="ttyUSB*|nothing", NAME="right"
+KERNEL=="ttyUSB*", NAME="wrong"
+EOF
+ },
+ {
+ desc => "test multi matches 2",
+ subsys => "tty",
+ devpath => "/class/tty/ttyUSB0",
+ exp_name => "right",
+ rules => <<EOF
+KERNEL=="dontknow*|*nothing", NAME="nomatch"
+KERNEL=="dontknow*|ttyUSB*|nothing*", NAME="right"
+KERNEL=="ttyUSB*", NAME="wrong"
+EOF
+ },
+ {
+ desc => "IMPORT parent test sequence 1/2 (keep)",
+ subsys => "block",
+ devpath => "/block/sda",
+ exp_name => "parent",
+ option => "keep",
+ rules => <<EOF
+KERNEL=="sda", IMPORT="/bin/echo -e \'PARENT_KEY=parent_right\\nWRONG_PARENT_KEY=parent_wrong'"
+KERNEL=="sda", NAME="parent"
+EOF
+ },
+ {
+ desc => "IMPORT parent test sequence 2/2 (keep)",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "parentenv-parent_right",
+ option => "clean",
+ rules => <<EOF
+KERNEL=="sda1", IMPORT{parent}="PARENT*", NAME="parentenv-\$env{PARENT_KEY}\$env{WRONG_PARENT_KEY}"
+EOF
+ },
+ {
+ desc => "GOTO test",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "right",
+ rules => <<EOF
+KERNEL=="sda1", GOTO="TEST"
+KERNEL=="sda1", NAME="wrong"
+KERNEL=="sda1", NAME="", LABEL="NO"
+KERNEL=="sda1", NAME="right", LABEL="TEST"
+KERNEL=="sda1", NAME="wrong2"
+EOF
+ },
+ {
+ desc => "NAME compare test",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "link",
+ exp_target => "node",
+ not_exp_name => "wronglink",
+ rules => <<EOF
+KERNEL=="sda1", NAME="node"
+KERNEL=="sda2", NAME="wrong"
+KERNEL=="sda1", NAME=="wrong*", SYMLINK+="wronglink"
+KERNEL=="sda1", NAME=="?*", SYMLINK+="link"
+KERNEL=="sda1", NAME=="node*", SYMLINK+="link2"
+EOF
+ },
+ {
+ desc => "NAME compare test 2",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "link2",
+ exp_target => "sda1",
+ not_exp_name => "link",
+ rules => <<EOF
+KERNEL=="sda1", NAME=="?*", SYMLINK+="link"
+KERNEL=="sda1", NAME!="?*", SYMLINK+="link2"
+EOF
+ },
+ {
+ desc => "invalid key operation",
+ subsys => "block",
+ devpath => "/block/sda/sda1",
+ exp_name => "yes",
+ rules => <<EOF
+KERNEL="sda1", NAME=="no"
+KERNEL=="sda1", NAME="yes"
EOF
},
);
print "\n";
if (defined($rules->{option}) && $rules->{option} eq "clean") {
- system("rm -rf $udev_db");
system("rm -rf $udev_root");
mkdir($udev_root) || die "unable to create udev_root: $udev_root\n";
}
# create config file
open CONF, ">$udev_conf" || die "unable to create config file: $udev_conf";
print CONF "udev_root=\"$udev_root\"\n";
-print CONF "udev_db=\"$udev_db\"\n";
print CONF "udev_rules=\"$udev_rules\"\n";
+print CONF "udev_log=\"info\"\n";
close CONF;
my $test_num = 1;
print "$error errors occured\n\n";
# cleanup
-system("rm -rf $udev_db");
system("rm -rf $udev_root");
unlink($udev_rules);
unlink($udev_conf);