X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=test%2Fudev-test.pl;h=6cde54ffabf3d3809998fd09f2ac2d6b66ea5b48;hp=8ee8ba5414698f35ce9846584e1bdf27e1dd7268;hb=0bb438770742815c5839f3fbf1aca967fa6e4a15;hpb=8b36cc0f179ee35176016ab67ae53078df4110fa diff --git a/test/udev-test.pl b/test/udev-test.pl index 8ee8ba541..6cde54ffa 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,14 +14,8 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# happy testing, # Kay Sievers , 2003 -# -# Modified April 9, 2004 by Leann Ogasawara -# - expanded @tests array to add more symlinks and permissions tests -# - some of the symlinks tests also test lack of node creation -# - added symlink_test() function -# - moved permissions and major_minor tests into their own functions +# Leann Ogasawara , 2004 use warnings; use strict; @@ -45,8 +39,8 @@ my @tests = ( devpath => "/block/sda", exp_name => "boot_disk" , conf => < "/block/sda/sda1", exp_name => "boot_disk1" , conf => < "/block/sda/sda1", exp_name => "boot_disk1" , conf => < "/block/sda/sda1", exp_name => "boot_disk1" , conf => < "/block/sda/sda1", exp_name => "boot_disk1" , conf => < "/class/tty/ttyUSB0", exp_name => "visor/0" , conf => < "/class/tty/ttyUSB0", exp_name => "visor/0" , conf => < "/class/tty/ttyUSB0", exp_name => "visor/0" , conf => < "/class/tty/ttyUSB0", exp_name => "visor/0" , conf => < "/class/tty/ttyUSB0", exp_name => "visor" , conf => < "visor" , conf => < "visor" , conf => < "visor" , conf => < "Handle backslashed multi lines in config file (and replace kernel name)", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "visor" , + conf => < "preserve backslashes, if they are not for a newline", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "aaa", + conf => < "Handle stupid backslashed multi lines in config file (and replace kernel name)", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "visor" , + conf => < "/class/tty/ttyUSB0", exp_name => "sub/direct/ory/visor" , conf => < "/block/sda/sda3", exp_name => "first_disk3" , conf => < "/block/sda/sda3", exp_name => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" , conf => < "/block/sda/sda3", exp_name => "M8-m3-n3-b0:0-sIBM" , conf => < "old style SYSFS_ attribute", - subsys => "block", - devpath => "/block/sda", - exp_name => "good" , - conf => < "/block/sda", exp_name => "disk-IBM-ESXS-sda" , conf => < "/block/sda/sda3", exp_name => "special-device-3" , conf => < "/block/sda/sda3", exp_name => "subsys_block" , conf => < "/block/sda/sda3", exp_name => "newline_removed" , conf => < "/block/sda/sda3", exp_name => "test-0:0:0:0" , conf => < "/block/sda/sda3", exp_name => "escape-3" , conf => < "/block/sda/sda3", exp_name => "foo9" , conf => < "/block/sda/sda3", exp_name => "bar9" , conf => < "/block/sda/sda3", exp_name => "foo7" , conf => < "/block/sda/sda3", exp_name => "my-foo9" , conf => < "/block/sda/sda3", exp_name => "my-foo8" , conf => < "/class/tty/console", exp_name => "TTY" , conf => < "/class/tty/console", exp_name => "foo" , conf => < "/class/tty/console", exp_name => "TTY" , conf => < "/class/tty/console", exp_name => "foo" , conf => < "/block/sda", exp_name => "scsi-0:0:0:0" , conf => < "/block/sda", exp_name => "boot_disk15" , conf => < "/class/tty/ttyUSB0", exp_name => "visor" , conf => < "/block/rd!c0d0", exp_name => "rd/c0d0" , conf => < "/block/rd!c0d0", exp_name => "rd/c0d0" , conf => < "/block/cciss!c0d0/cciss!c0d0p1", exp_name => "cciss/c0d0p1" , conf => < "/block/sda", exp_name => "scsi-0:0:0:0", conf => < "/block/sda", exp_name => "scsi-0:0:0:0", conf => < "/block/sda", exp_name => "scsi-0:0:0:0", conf => < "/block/sda", exp_name => "scsi-0:0:0:0", conf => < "/block/sda", exp_name => "ignored", conf => < "/block/sda", exp_name => "matched-with-space", conf => < "tty", devpath => "/class/tty/tty33", exp_name => "tty33", - exp_perms => "0:0:0600", + exp_perms => "0:0:0660", conf => < "block", devpath => "/block/sda", exp_name => "node", - exp_perms => "5000::0600", + exp_perms => "5000::0660", conf => < "block", devpath => "/block/sda", exp_name => "node", - exp_perms => ":100:0600", + exp_perms => ":100:0660", + conf => < "textual user id", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => "nobody::0660", + conf => < "textual group id", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => ":daemon:0660", + conf => < "textual user/group id", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => "root:mail:0660", conf => < "node", exp_perms => "::0777", conf => < "node", exp_perms => "5000:100:0777", conf => < "ttyUSB0", exp_perms => "5000::", conf => < "tty", devpath => "/class/tty/ttyUSB0", exp_name => "ttyUSB0", - exp_perms => ":100:0600", + exp_perms => ":100:0660", conf => < "ttyUSB0", exp_perms => "::0060", conf => < "ttyUSB0", exp_perms => "5000:100:0777", conf => < "permissions only rule", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "5000:100:0777", + conf => < "multiple permissions only rule", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "3000:4000:0777", + conf => < "permissions only rule with override at NAME rule", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "3000:8000:0777", + conf => < "node", exp_majorminor => "8:0", conf => < "node", exp_majorminor => "89:300", conf => < "node", exp_majorminor => "4095:1", conf => < "node", exp_majorminor => "4094:89999", conf => < "symlink2-ttyUSB0", exp_target => "ttyUSB0", conf => < "visor0", exp_target => "ttyUSB0", conf => < "1/2/symlink" , exp_target => "a/b/node", conf => < "1/2/c/d/symlink" , exp_target => "../../a/b/node", conf => < "second-0" , exp_target => "visor" , conf => < "symlink-only2", exp_target => "link", conf => < "symlink name empty", - subsys => "block", - devpath => "/block/sda", - exp_name => "", - exp_target => "link", - exp_error => "yes", - conf => < "/block/sda", exp_name => ".", exp_target => "link", - exp_error => "yes", + exp_add_error => "yes", + exp_rem_error => "yes", conf => < "symlink to empty name", - subsys => "block", - devpath => "/block/sda", - exp_name => "symlink", - exp_target => "", - exp_error => "yes", - conf => < "symlink and name empty", - subsys => "block", - devpath => "/block/sda", - exp_name => "", - exp_target => "", - exp_error => "yes", - conf => < "/class/tty/tty0", exp_name => "link", exp_target => "link", + exp_rem_error => "yes", + option => "clear", conf => < "symlink0", exp_target => "ttyUSB0", conf => < "symlink-ttyUSB0", exp_target => "ttyUSB0", conf => < "major-188:0", exp_target => "ttyUSB0", conf => < "symlink-0:0:0:0", exp_target => "node", conf => < "test", exp_target => "ttyUSB0", conf => < "test", exp_target => "ttyUSB0", conf => < "this", exp_target => "ttyUSB0", conf => < "test", exp_target => "link", conf => < "188:0", exp_target => "ttyUSB0", conf => < "188", exp_target => "ttyUSB0", conf => < "percent%sign", exp_target => "ttyUSB0", conf => < "%ttyUSB0_name", exp_target => "ttyUSB0", conf => < "link1", exp_target => "node", conf => < "link4", exp_target => "node", conf => < "/block/sda", exp_name => "cdrom", conf => < "enumeration char test sequence (1/5 keep)", + desc => "enumeration char test sequence 1/5 (keep)", subsys => "block", devpath => "/block/sda", exp_name => "cdrom", option => "keep", conf => < "enum", option => "keep", conf => < "cdrom1", option => "keep", conf => < "enum1", option => "keep", conf => < "cdrom2", option => "clear", conf => < "/block/sda", exp_name => "cdrom", conf => < "ignore rule test", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_add_error => "yes", + conf => < "all_partitions, option-only rule", + subsys => "block", + devpath => "/block/sda", + exp_name => "node6", + conf => < "all_partitions, option-only rule (fail on partition)", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "node6", + exp_add_error => "yes", + conf => < "block", devpath => "/block/sda", exp_name => "node", - exp_error => "yes", + exp_rem_error => "yes", conf => < "block", devpath => "/block/sda", exp_name => "node14", - exp_error => "yes", + exp_rem_error => "yes", option => "clear", conf => < "/block/sda", exp_name => "node", conf => < "/block/sda", exp_name => "node", conf => < "temporary node creation test", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + conf => < "devpath substitution test", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + conf => < "parent node name substitution test sequence 1/2 (keep)", + subsys => "block", + devpath => "/block/sda", + exp_name => "main_device", + option => "keep", + conf => < "parent node name substitution test sequence 2/2 (clean)", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "main_device-part-1", + option => "clean", + conf => < "udev_root substitution", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "start-udev-root-end", + conf => < "last_rule option", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "last", + conf => < "negation KERNEL!=", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "match", + conf => < "negation SUBSYSTEM!=", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "not-anything", + conf => < "negation PROGRAM!= exit code", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "nonzero-program", + conf => < "test for whitespace between the operator", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "true", + conf => < "ENV{} test", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "true", + conf => < "ENV{} test", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "true", + conf => <{exp_perms} =~ m/^(.*):(.*):(.*)$/; if ($1 ne "") { - if ($uid != $1) { $wrong = 1; }; + if (defined(getpwnam($1))) { + $userid = int(getpwnam($1)); + } else { + $userid = $1; + } + if ($uid != $userid) { $wrong = 1; } } if ($2 ne "") { - if ($gid != $2) { $wrong = 1; }; + if (defined(getgrnam($2))) { + $groupid = int(getgrnam($2)); + } else { + $groupid = $2; + } + if ($gid != $groupid) { $wrong = 1; } } if ($3 ne "") { if (($mode & 07777) != oct($3)) { $wrong = 1; }; } if ($wrong == 0) { - print "permissions: ok "; + print "permissions: ok\n"; } else { - printf "expected permissions are: %i:%i:%#o\n", $1, $2, oct($3); - printf "created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; + printf " expected permissions are: %s:%s:%#o\n", $1, $2, oct($3); + printf " created permissions are : %i:%i:%#o\n", $uid, $gid, $mode & 07777; + print "permissions: error\n"; $error++; } } @@ -1062,11 +1293,11 @@ sub major_minor_test { if ($minor != $2) { $wrong = 1; }; } if ($wrong == 0) { - print "major:minor: ok "; + print "major:minor: ok\n"; } else { - printf "expected major:minor is: %i:%i\n", $1, $2; - printf "created major:minor is : %i:%i\n", $major, $minor; - print "major:minor: error "; + printf " expected major:minor is: %i:%i\n", $1, $2; + printf " created major:minor is : %i:%i\n", $major, $minor; + print "major:minor: error\n"; $error++; } } @@ -1078,22 +1309,25 @@ sub symlink_test { if ($output =~ m/(.*)-> (.*)/) { if ($2 eq $config->{exp_target}) { - print "symlink: ok "; + print "symlink: ok\n"; } else { - print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; - print "created symlink from: \'$config->{exp_name}\' to \'$2\'\n"; - if ($config->{exp_error}) { - print "as expected "; + print " expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; + print " created symlink from: \'$config->{exp_name}\' to \'$2\'\n"; + print "symlink: error"; + if ($config->{exp_add_error}) { + print " as expected\n"; } else { + print "\n"; $error++; } } } else { - print "expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; - print "symlink: not created "; - if ($config->{exp_error}) { - print "as expected "; + print " expected symlink from: \'$config->{exp_name}\' to \'$config->{exp_target}\'\n"; + print "symlink: not created"; + if ($config->{exp_add_error}) { + print " as expected\n"; } else { + print "\n"; $error++; } } @@ -1127,13 +1361,13 @@ sub run_test { if (defined($config->{exp_target})) { symlink_test($config); } - print "add: ok "; + print "add: ok\n"; } else { - print "add: error "; - if ($config->{exp_error}) { - print "as expected "; + print "add: error"; + if ($config->{exp_add_error}) { + print " as expected\n"; } else { - print "\n\n"; + print "\n"; system("tree $udev_root"); print "\n"; $error++; @@ -1148,19 +1382,21 @@ sub run_test { udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); if ((-e "$PWD/$udev_root$config->{exp_name}") || (-l "$PWD/$udev_root$config->{exp_name}")) { - print "remove: error "; - if ($config->{exp_error}) { - print "as expected\n\n"; + print "remove: error"; + if ($config->{exp_rem_error}) { + print " as expected\n"; } else { - print "\n\n"; + print "\n"; system("tree $udev_root"); print "\n"; $error++; } } else { - print "remove: ok\n\n"; + print "remove: ok\n"; } + print "\n"; + if (defined($config->{option}) && $config->{option} eq "clear") { system("rm -rf $udev_db"); system("rm -rf $udev_root"); @@ -1185,9 +1421,6 @@ open CONF, ">$main_conf" || die "unable to create config file: $main_conf"; print CONF "udev_root=\"$udev_root\"\n"; print CONF "udev_db=\"$udev_db\"\n"; print CONF "udev_rules=\"$conf_tmp\"\n"; -print CONF "default_mode=\"0600\"\n"; -print CONF "default_owner=\"root\"\n"; -print CONF "default_group=\"root\"\n"; close CONF; my $test_num = 1;