X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=test%2Fudev-test.pl;h=a83b156d784b62e21c58dfdabc341f8d1210042a;hp=2549c7ee69ac4f6862f75c851d4d7c726caa471a;hb=37a123a9bccd448333fcd83abec926f195dbed9e;hpb=53899a171ea862124b49c75b7511b7eb30742ef9 diff --git a/test/udev-test.pl b/test/udev-test.pl index 2549c7ee6..a83b156d7 100755 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -14,32 +14,49 @@ # After creation and removal the result is checked against the # expected value and the result is printed. # -# Kay Sievers , 2003 -# Leann Ogasawara , 2004 +# Copyright (C) 2004-2006 Kay Sievers +# Copyright (C) 2004 Leann Ogasawara use warnings; use strict; -my $PWD = $ENV{PWD}; -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"; - -# uncomment following line to run udev with valgrind. -# Should make this a runtime option to the script someday... -#my $udev_bin = "valgrind --tool=memcheck --leak-check=yes ../udev"; +my $PWD = $ENV{PWD}; +my $sysfs = "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 $udev_conf = "udev-test.conf"; +my $udev_rules = "udev-test.rules"; my @tests = ( + { + desc => "label test of scsi disc (old key names)", + subsys => "block", + devpath => "/block/sda", + exp_name => "boot_disk" , + rules => < "label test of scsi disc (old key names)", + subsys => "block", + devpath => "/block/sda", + exp_name => "boot_disk" , + rules => < "label test of scsi disc", subsys => "block", devpath => "/block/sda", exp_name => "boot_disk" , rules => < "/block/sda/sda1", exp_name => "boot_disk1" , rules => < "/block/sda/sda1", exp_name => "boot_disk1" , rules => < "/block/sda/sda1", exp_name => "boot_disk1" , rules => < "/block/sda/sda1", exp_name => "boot_disk1" , rules => < "place on bus of scsi partition", + desc => "parent device name match of scsi partition", subsys => "block", devpath => "/block/sda/sda3", exp_name => "first_disk3" , rules => < "test substitution chars (old key names)", + subsys => "block", + devpath => "/block/sda/sda3", + exp_name => "Major:8:minor:3:kernelnumber:3:id:0:0:0:0" , + rules => < "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 => < "/block/sda/sda3", exp_name => "M8-m3-n3-b0:0-sIBM" , rules => < "import of shell-value file", subsys => "block", devpath => "/block/sda", - exp_name => "subdir/info/node" , + exp_name => "subdir/err/node" , rules => < "/block/sda", exp_name => "node12345678", rules => < "/block/sda", exp_name => "disk-IBM-ESXS-sda" , rules => < "/block/sda/sda3", exp_name => "special-device-3" , rules => < "program result substitution (no argument should be subsystem)", - subsys => "block", - devpath => "/block/sda/sda3", - exp_name => "subsys_block" , - rules => < "/block/sda/sda3", exp_name => "newline_removed" , rules => < "/block/sda/sda3", exp_name => "test-0:0:0:0" , rules => < "/block/sda/sda3", exp_name => "escape-3" , rules => < "/block/sda/sda3", exp_name => "foo9" , rules => < "/block/sda/sda3", exp_name => "bar9" , rules => < "/block/sda/sda3", exp_name => "foo7" , rules => < "/block/sda/sda3", exp_name => "my-foo9" , rules => < "/block/sda/sda3", exp_name => "my-foo8" , rules => < "test substitution by variable name", 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 => < "test substitution by variable name 2", 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 => < "/block/sda/sda3", exp_name => "830:0:0:03" , rules => < "/block/sda/sda3", exp_name => "833" , rules => < "/block/sda/sda3", exp_name => "8330:0:0:0" , rules => < "invalid program for device with no bus", - subsys => "tty", - devpath => "/class/tty/console", - exp_name => "TTY" , - rules => < "valid program for device with no bus", + desc => "non matching SUBSYSTEMS for device with no parent", subsys => "tty", devpath => "/class/tty/console", - exp_name => "foo" , + exp_name => "TTY", rules => < "invalid label for device with no bus", + desc => "non matching SUBSYSTEMS", subsys => "tty", devpath => "/class/tty/console", exp_name => "TTY" , rules => < "valid label for device with no bus", + desc => "ATTRS match", subsys => "tty", devpath => "/class/tty/console", exp_name => "foo" , rules => < "/block/sda", exp_name => "scsi-0:0:0:0" , rules => < "boot_disk15" , exp_majorminor => "8:15", rules => < "/class/tty/ttyUSB0", exp_name => "visor" , rules => < "/block/rd!c0d0", exp_name => "rd/c0d0" , rules => < "/block/cciss!c0d0/cciss!c0d0p1", exp_name => "cciss/c0d0p1" , rules => < "ID rule", + desc => "KERNELS rule", subsys => "block", devpath => "/block/sda", exp_name => "scsi-0:0:0:0", rules => < "ID wildcard all", + desc => "KERNELS wildcard all", subsys => "block", devpath => "/block/sda", exp_name => "scsi-0:0:0:0", rules => < "ID wildcard partial", + desc => "KERNELS wildcard partial", subsys => "block", devpath => "/block/sda", exp_name => "scsi-0:0:0:0", rules => < "ID wildcard partial 2", + desc => "KERNELS wildcard partial 2", subsys => "block", devpath => "/block/sda", exp_name => "scsi-0:0:0:0", rules => < "ignore SYSFS attribute whitespace", + desc => "substitute attr with link target value (first match)", + subsys => "block", + devpath => "/block/sda", + exp_name => "driver-is-sd", + rules => < "substitute attr with link target value (currently selected device)", + subsys => "block", + devpath => "/block/sda", + exp_name => "driver-is-aic7xxx", + rules => < "ignore ATTRS attribute whitespace", subsys => "block", devpath => "/block/sda", exp_name => "ignored", rules => < "do not ignore SYSFS attribute whitespace", + desc => "do not ignore ATTRS attribute whitespace", subsys => "block", devpath => "/block/sda", exp_name => "matched-with-space", rules => < "node", exp_perms => "5000::0660", rules => < "node", exp_perms => ":100:0660", rules => < "node", exp_perms => "nobody::0660", rules => < "node", exp_perms => ":daemon:0660", rules => < "node", exp_perms => "root:mail:0660", rules => < "node", exp_perms => "::0777", rules => < "node", exp_perms => "5000:100:0777", rules => < "node", exp_majorminor => "8:0", rules => < "1/2/symlink" , exp_target => "a/b/node", rules => < "1/2/c/d/symlink" , exp_target => "../../a/b/node", rules => < "symlink-only2", exp_target => "link", rules => < "yes", exp_rem_error => "yes", rules => < "/class/tty/tty0", exp_name => "link", exp_target => "link", + exp_add_error => "yes", exp_rem_error => "yes", option => "clean", rules => < "symlink-0:0:0:0", exp_target => "node", rules => < "test", exp_target => "link", rules => < "ttyUSB0", rules => < "symlink with '%' in name", - subsys => "tty", - devpath => "/class/tty/ttyUSB0", - exp_name => "percent%sign", - exp_target => "ttyUSB0", - rules => < "symlink with '%' in name", - subsys => "tty", - devpath => "/class/tty/ttyUSB0", - exp_name => "%ttyUSB0_name", - exp_target => "ttyUSB0", - rules => < "link1", exp_target => "node", rules => < "link4", exp_target => "node", rules => < "enumeration char test (single test)", - subsys => "block", - devpath => "/block/sda", - exp_name => "cdrom", - rules => < "enumeration char test sequence 1/5 (keep)", - subsys => "block", - devpath => "/block/sda", - exp_name => "cdrom", - option => "keep", - rules => < "enumeration char test sequence 2/5 (keep)", - subsys => "block", - devpath => "/block/sda/sda1", - exp_name => "enum", - option => "keep", - rules => < "enumeration char test sequence 3/5 (keep)", - subsys => "block", - devpath => "/block/sda/sda2", - exp_name => "cdrom1", - option => "keep", - rules => < "enumeration char test sequence 4/5 (keep)", - subsys => "block", - devpath => "/block/sda/sda3", - exp_name => "enum1", - option => "keep", - rules => < "enumeration char test sequence 5/5 (clean)", - subsys => "block", - devpath => "/block/sda/sda4", - exp_name => "cdrom2", - option => "clean", - rules => < "enumeration char test after cleanup (single test)", - subsys => "block", - devpath => "/block/sda", - exp_name => "cdrom", - rules => < "node", exp_add_error => "yes", rules => < "node6", rules => < "yes", rules => < "node", exp_rem_error => "yes", rules => < "yes", option => "clean", rules => < "/block/sda", exp_name => "node", rules => < "DRIVER match test", + desc => "DRIVERS match test", subsys => "block", devpath => "/block/sda", exp_name => "node", rules => < "/block/sda", exp_name => "node", rules => < "/block/sda", exp_name => "sda", rules => < "main_device", option => "keep", rules => < "main_device-part-1", option => "clean", rules => < "/block/sda/sda1", exp_name => "start-udev-root-end", rules => < "/block/sda/sda1", exp_name => "last", rules => < "/block/sda/sda1", exp_name => "match", rules => < "/block/sda/sda1", exp_name => "not-anything", rules => < "nonzero-program", rules => < "true", rules => < "/block/sda/sda1", exp_name => "true", rules => < "/block/sda/sda1", exp_name => "true", rules => < "/block/sda/sda1", exp_name => "true", rules => < "ENV{} test (assign 2 times)", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "true", + rules => < "/block/sda/sda1", exp_name => "part", rules => < "/block/sda/sda1", exp_name => "sane", rules => < "/block/sda/sda1", exp_name => "uber", rules => < "/block/sda/sda1", exp_name => "replaced", rules => < "/block/sda", exp_name => "ok", rules => < "NAME compare test", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "link", + exp_target => "node", + not_exp_name => "wronglink", + rules => < "NAME compare test 2", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "link2", + exp_target => "sda1", + not_exp_name => "link", + rules => < "invalid key operation", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "yes", + rules => < "operator chars in attribute", + subsys => "block", + devpath => "/block/sda", + exp_name => "yes", + rules => < "overlong comment line", + subsys => "block", + devpath => "/block/sda/sda1", + exp_name => "yes", + rules => < "magic subsys/kernel lookup", + subsys => "block", + devpath => "/block/sda", + exp_name => "00:e0:00:fb:04:e1", + rules => < "TEST absolute path", + subsys => "block", + devpath => "/block/sda", + exp_name => "there", + rules => < "TEST subsys/kernel lookup", + subsys => "block", + devpath => "/block/sda", + exp_name => "yes", + rules => < "TEST relative path", + subsys => "block", + devpath => "/block/sda", + exp_name => "relative", + rules => < "TEST wildcard substitution (find queue/nr_requests)", + subsys => "block", + devpath => "/block/sda", + exp_name => "found-subdir", + rules => < "TEST MODE=0000", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + exp_perms => "0:0:0000", + rules => < "TEST PROGRAM feeds MODE", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + exp_perms => "0:0:0400", + rules => < "TEST PROGRAM feeds MODE with overflow", + subsys => "block", + devpath => "/block/sda", + exp_name => "sda", + exp_perms => "0:0:0400", + rules => < 0) { + system("$udev_bin_valgrind $subsys"); + } else { + system("$udev_bin $subsys"); + } } my $error = 0; @@ -1668,6 +1755,15 @@ sub symlink_test { } } +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. + chown (0, 0, $udev_root) || die "unable to chown $udev_root\n"; + chmod (0755, $udev_root) || die "unable to chmod $udev_root\n"; +} + sub run_test { my ($rules, $number) = @_; @@ -1740,9 +1836,7 @@ sub run_test { 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"; + make_udev_root (); } } @@ -1755,28 +1849,35 @@ if (!($<==0)) { } # prepare -system("rm -rf $udev_root"); -mkdir($udev_root) || die "unable to create udev_root: $udev_root\n"; +make_udev_root(); # 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"; +print CONF "udev_rules=\"$PWD\"\n"; +print CONF "udev_log=\"err\"\n"; close CONF; my $test_num = 1; +my @list; -if ($ARGV[0]) { - # only run one test - $test_num = $ARGV[0]; - - if (defined($tests[$test_num-1]->{desc})) { - print "udev-test will run test number $test_num only:\n\n"; - run_test($tests[$test_num-1], $test_num); +foreach my $arg (@ARGV) { + if ($arg =~ m/--valgrind/) { + $valgrind = 1; + printf("using valgrind\n"); } else { - print "test does not exist.\n"; + push(@list, $arg); + } +} + +if ($list[0]) { + foreach my $arg (@list) { + if (defined($tests[$arg-1]->{desc})) { + print "udev-test will run test number $arg:\n\n"; + run_test($tests[$arg-1], $arg); + } else { + print "test does not exist.\n"; + } } } else { # test all @@ -1791,7 +1892,6 @@ if ($ARGV[0]) { print "$error errors occured\n\n"; # cleanup -system("rm -rf $udev_db"); system("rm -rf $udev_root"); unlink($udev_rules); unlink($udev_conf);