use strict;
my $PWD = $ENV{PWD};
-my $sysfs = "sys/";
-my $udev_bin = "../udev/test-udev";
+my $sysfs = "test/sys/";
+my $udev_bin = "udev/test-udev";
my $valgrind = 0;
my $udev_bin_valgrind = "valgrind --tool=memcheck --leak-check=yes --quiet $udev_bin";
my $udev_root = "udev-root/";
my @tests = (
{
- desc => "label test of scsi disc (old key names)",
+ desc => "no rules",
+ subsys => "block",
+ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
+ exp_name => "sda" ,
+ rules => <<EOF
+EOF
+ },
+ {
+ desc => "label test of scsi disc",
subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "boot_disk" ,
rules => <<EOF
-SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="boot_disk%n"
+SUBSYSTEMS=="scsi", ATTRS{vendor}=="ATA", NAME="boot_disk%n", RUN+="socket:@/org/kernel/udev/monitor"
KERNEL=="ttyACM0", NAME="modem"
EOF
},
{
- desc => "label test of scsi disc (old key names)",
+ desc => "label test of scsi disc",
subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "boot_disk" ,
exp_name => "first_disk5" ,
rules => <<EOF
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="first_disk%n"
-EOF
- },
- {
- desc => "test substitution chars (old key names)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
- exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
- rules => <<EOF
-BUS=="scsi", ID=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
EOF
},
{
exp_name => "Major:8:minor:5:kernelnumber:5:id:0:0:0:0" ,
rules => <<EOF
SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:id:%b"
-EOF
- },
- {
- desc => "test substitution chars (with length limit)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
- exp_name => "M8-m5-n5-b0:0-xAT" ,
- rules => <<EOF
-SUBSYSTEMS=="scsi", KERNELS=="0:0:0:0", NAME="M%M-m%m-n%n-b%3b-x%2s{vendor}"
EOF
},
{
exp_name => "test-0:0:0:0" ,
rules => <<EOF
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n test-%b", RESULT=="test-0:0*", NAME="%c"
-EOF
- },
- {
- desc => "program with escaped format char (tricky: callout returns format char!)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5",
- exp_name => "escape-5" ,
- rules => <<EOF
-SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n escape-%%n", KERNEL=="sda5", NAME="%c"
EOF
},
{
rules => <<EOF
KERNEL=="console", NAME="TTY"
ATTRS{dev}=="5:1", NAME="foo"
+EOF
+ },
+ {
+ desc => "ATTR (empty file)",
+ subsys => "tty",
+ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
+ exp_name => "empty" ,
+ rules => <<EOF
+KERNEL=="sda", ATTR{test_empty_file}=="?*", NAME:="something"
+KERNEL=="sda", ATTR{test_empty_file}!="", NAME:="not-empty"
+KERNEL=="sda", ATTR{test_empty_file}=="", NAME:="empty"
+KERNEL=="sda", ATTR{test_empty_file}!="?*", NAME:="not-something"
+KERNEL=="sda", NAME="wrong"
+EOF
+ },
+ {
+ desc => "ATTR (non-existent file)",
+ subsys => "tty",
+ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
+ exp_name => "non-existent" ,
+ rules => <<EOF
+KERNEL=="sda", ATTR{nofile}=="?*", NAME:="something"
+KERNEL=="sda", ATTR{nofile}!="", NAME:="not-empty"
+KERNEL=="sda", ATTR{nofile}=="", NAME:="empty"
+KERNEL=="sda", ATTR{nofile}!="?*", NAME:="not-something"
+KERNEL=="sda", TEST!="nofile", NAME:="non-existent"
+KERNEL=="sda", NAME="wrong"
EOF
},
{
subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "symlink2-ttyACM0",
- exp_target => "ttyACM0",
+ exp_target => "ttyACM-0",
rules => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
+KERNEL=="ttyACM[0-9]*", NAME="ttyACM-%n", SYMLINK="symlink1-%n symlink2-%k symlink3-%b"
EOF
},
{
exp_target => "ttyACM0",
rules => <<EOF
KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK+="%s{dev}"
-EOF
- },
- {
- desc => "symlink %Ns{filename} substitution",
- subsys => "tty",
- devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
- exp_name => "166",
- exp_target => "ttyACM0",
- rules => <<EOF
-KERNEL=="ttyACM[0-9]*", NAME="ttyACM%n", SYMLINK+="%3s{dev}"
EOF
},
{
exp_target => "node",
rules => <<EOF
SUBSYSTEMS=="scsi", PROGRAM=="/bin/echo -n node link1 link2 link3 link4", RESULT=="node *", NAME="%c{1}", SYMLINK+="%c{2+}"
-EOF
- },
- {
- desc => "ignore rule test",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
- exp_name => "nothing",
- not_exp_name => "node",
- exp_add_error => "yes",
- rules => <<EOF
-SUBSYSTEMS=="scsi", KERNEL=="sda", NAME="node", OPTIONS="ignore"
EOF
},
{
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda",
rules => <<EOF
-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"
+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"
EOF
},
{
subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "<none>",
+ not_exp_name => "ttyACM0",
+ exp_add_error => "yes",
+ rules => <<EOF
+KERNEL=="ttyACM[0-9]*", NAME=""
+EOF
+ },
+ {
+ desc => "test empty NAME (empty override)",
+ subsys => "tty",
+ devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
+ exp_name => "<none>",
not_exp_name => "wrong",
exp_add_error => "yes",
rules => <<EOF
EOF
},
{
- desc => "test empty NAME 2",
+ desc => "test empty NAME (non-empty override)",
subsys => "tty",
devpath => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
exp_name => "right",
KERNEL=="sda1", NAME="wrong"
KERNEL=="sda1", GOTO="BAD"
KERNEL=="sda1", NAME="", LABEL="NO"
-KERNEL=="sda1", NAME="right", LABEL="TEST"
-KERNEL=="sda1", LABEL="BAD"
+KERNEL=="sda1", NAME="right", LABEL="TEST", GOTO="end"
+KERNEL=="sda1", NAME="wrong2", LABEL="BAD"
+LABEL="end"
+EOF
+ },
+ {
+ desc => "GOTO label does not exist",
+ subsys => "block",
+ devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
+ exp_name => "right",
+ rules => <<EOF
+KERNEL=="sda1", GOTO="does-not-exist"
+KERNEL=="sda1", NAME="right",
+LABEL="exists"
EOF
},
{
rules => <<EOF
TEST=="/etc/hosts", NAME="there"
TEST!="/etc/hosts", NAME="notthere"
-EOF
- },
- {
- desc => "TEST invalid NAME= only (skip invalid rule)",
- subsys => "block",
- devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
- exp_name => "yes",
- rules => <<EOF
-SUBSYSTEM=="block", NAME="yes"
-NAME="no"
EOF
},
{
EOF
},
{
- desc => "TEST PROGRAM feeds MODE",
+ desc => "TEST PROGRAM feeds OWNER, GROUP, MODE",
subsys => "block",
devpath => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
exp_name => "sda",
- exp_perms => "0:0:0400",
+ exp_perms => "5000:100:0400",
rules => <<EOF
KERNEL=="sda", MODE="666"
-KERNEL=="sda", PROGRAM=="/bin/echo 0 0 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
+KERNEL=="sda", PROGRAM=="/bin/echo 5000 100 0400", OWNER="%c{1}", GROUP="%c{2}", MODE="%c{3}"
EOF
},
{
exp_name => "sda-8741C4G-end",
exp_perms => "0:0:0660",
rules => <<EOF
-KERNEL=="sda", NAME="%k-%s{[dmi/id]product_name}-end"
+KERNEL=="sda", PROGRAM="/bin/true create-envp"
+KERNEL=="sda", ENV{TESTENV}="change-envp"
+KERNEL=="sda", NAME="%k-%s{[dmi/id]product_name}-end", RUN+="socket:@/org/kernel/udev/monitor"
EOF
},
-
);
# set env
udev("add", $rules->{subsys}, $rules->{devpath}, \$rules->{rules});
+ 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}")) {
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$rules->{exp_name}");
- 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 (defined($rules->{exp_perms})) {
permissions_test($rules, $uid, $gid, $mode);
}