From b86691919a5687c3749d8e3324dd3b8eae22a435 Mon Sep 17 00:00:00 2001 From: "greg@kroah.com" Date: Thu, 15 Apr 2004 23:14:49 -0700 Subject: [PATCH] [PATCH] Added expanded tests to the test framework from Leann Ogasawara --- test/udev-test.pl | 707 +++++++++++++++++++++++++++++++++++------- test/udev.permissions | 16 + 2 files changed, 604 insertions(+), 119 deletions(-) diff --git a/test/udev-test.pl b/test/udev-test.pl index 31bc990b..ebd3c6a8 100644 --- a/test/udev-test.pl +++ b/test/udev-test.pl @@ -16,7 +16,12 @@ # # 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 use warnings; use strict; @@ -304,24 +309,6 @@ EOF exp_name => "my-foo8" , conf => < "program result substitution (numbered part of)", - subsys => "block", - devpath => "/block/sda/sda3", - exp_name => "link1" , - conf => < "program result substitution (numbered part of+)", - subsys => "block", - devpath => "/block/sda/sda3", - exp_name => "link3" , - conf => < "symlink creation (same directory)", - subsys => "tty", - devpath => "/class/tty/ttyUSB0", - exp_name => "visor0" , - conf => < "symlink creation (relative link back)", - subsys => "block", - devpath => "/block/sda/sda2", - exp_name => "1/2/a/b/symlink" , - conf => < "symlink creation (relative link forward)", - subsys => "block", - devpath => "/block/sda/sda2", - exp_name => "1/2/symlink" , - conf => < "symlink creation (relative link back and forward)", - subsys => "block", - devpath => "/block/sda/sda2", - exp_name => "1/2/c/d/symlink" , - conf => < "multiple symlinks", - subsys => "tty", - devpath => "/class/tty/ttyUSB0", - exp_name => "second-0" , - conf => < "SYMLINK only rule", + desc => "permissions test", subsys => "block", devpath => "/block/sda", - exp_name => "symlink-only2", + exp_name => "node", + exp_perms => "5000::0444", conf => < "permissions test", + desc => "permissions ttyUSB0:root:uucp:0660", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "0:14:0660", + conf => < "permissions tty0::root:0444", + subsys => "tty", + devpath => "/class/tty/tty0", + exp_name => "tty0", + exp_perms => "0:0:0444", + conf => < "permissions tty1:root::0555", + subsys => "tty", + devpath => "/class/tty/tty1", + exp_name => "tty1", + exp_perms => "0:0:0555", + conf => < "permissions tty2:::0777", + subsys => "tty", + devpath => "/class/tty/tty2", + exp_name => "tty2", + exp_perms => "0:0:0777", + conf => < "permissions tty3:::", + subsys => "tty", + devpath => "/class/tty/tty3", + exp_name => "tty3", + exp_perms => "0:0:0", + conf => < "permissions i2c-300:root:sys:0744", + subsys => "i2c-dev", + devpath => "/class/i2c-dev/i2c-300", + exp_name => "i2c-300", + exp_perms => "0:3:0744", + conf => < "permissions i2c-fake1:root:7:0007", + subsys => "i2c-dev", + devpath => "/class/i2c-dev/i2c-fake1", + exp_name => "i2c-fake1", + exp_perms => "0:7:0007", + conf => < "permissions ttyS[01]:0:5:0700", + subsys => "tty", + devpath => "/class/tty/ttyS1", + exp_name => "ttyS1", + exp_perms => "0:5:0700", + conf => < "permissions ttyS[4-9]:tty:5:0060", + subsys => "tty", + devpath => "/class/tty/ttyS7", + exp_name => "ttyS7", + exp_perms => "0:5:0060", + conf => < "permissions tty4:0:5:0707", + subsys => "ttyS4", + devpath => "/class/tty/tty4", + exp_name => "tty4", + exp_perms => "0:5:0707", + conf => < "permissions tty4?:0:5:0007", + subsys => "tty", + devpath => "/class/tty/tty44", + exp_name => "tty44", + exp_perms => "0:5:0007", + conf => < "permissions tty3[!3]:::0467", + subsys => "tty", + devpath => "/class/tty/tty35", + exp_name => "tty35", + exp_perms => "0:0:0467", + conf => < "permissions tty33:bad:name:0500", + subsys => "tty", + devpath => "/class/tty/tty33", + exp_name => "tty33", + exp_perms => "0:0:0500", + conf => < "permissions rtc:0:users:0600", + subsys => "misc", + devpath => "/class/misc/rtc", + exp_name => "misc/rtc", + exp_perms => "0:100:0600", + conf => < "permissions misc:0:users:0600", + subsys => "misc", + devpath => "/class/misc/psaux", + exp_name => "misc/psaux", + exp_perms => "0:100:0600", + conf => < "permissions set OWNER=5000", subsys => "block", devpath => "/block/sda", exp_name => "node", - exp_perms => "5000::0444", + exp_perms => "5000::0600", conf => < "permissions set GROUP=100", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => ":100:0600", + conf => < "permissions set mode=0777", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => "::0777", + conf => < "permissions set OWNER=5000 GROUP=100 MODE=0777", + subsys => "block", + devpath => "/block/sda", + exp_name => "node", + exp_perms => "5000:100:0777", + conf => < "permissions override OWNER to 5000", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "5000:14:0660", + conf => < "permissions override GROUP to 100", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => ":100:0660", + conf => < "permissions override MODE to 0060", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => ":14:0060", + conf => < "permissions override OWNER, GROUP, MODE", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "ttyUSB0", + exp_perms => "5000:100:0777", + conf => < "4094:89999", conf => < "symlink creation (same directory)", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "visor0", + exp_target => "ttyUSB0", + conf => < "symlink creation (relative link forward)", + subsys => "block", + devpath => "/block/sda/sda2", + exp_name => "1/2/symlink" , + exp_target => "a/b/node", + conf => < "symlink creation (relative link back and forward)", + subsys => "block", + devpath => "/block/sda/sda2", + exp_name => "1/2/c/d/symlink" , + exp_target => "../../a/b/node", + conf => < "multiple symlinks", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "second-0" , + exp_target => "visor" , + conf => < "symlink only rule", + subsys => "block", + devpath => "/block/sda", + exp_name => "symlink-only2", + exp_target => "link", + conf => < "symlink name empty", + subsys => "block", + devpath => "/block/sda", + exp_name => "", + exp_target => "link", + exp_error => "yes", + conf => < "symlink name '.'", + subsys => "block", + devpath => "/block/sda", + exp_name => ".", + exp_target => "link", + exp_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 => < "symlink node to itself", + subsys => "tty", + devpath => "/class/tty/tty0", + exp_name => "link", + exp_target => "link", + conf => < "symlink %n substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "symlink0", + exp_target => "ttyUSB0", + conf => < "symlink %k substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "symlink-ttyUSB0", + exp_target => "ttyUSB0", + conf => < "symlink %M:%m substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "major-188:0", + exp_target => "ttyUSB0", + conf => < "symlink %b substitution", + subsys => "block", + devpath => "/block/sda", + exp_name => "symlink-0:0:0:0", + exp_target => "node", + conf => < "symlink %c substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "test", + exp_target => "ttyUSB0", + conf => < "symlink %c{N} substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "test", + exp_target => "ttyUSB0", + conf => < "symlink %c{N+} substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "this", + exp_target => "ttyUSB0", + conf => < "symlink only rule with %c{N+}", + subsys => "block", + devpath => "/block/sda", + exp_name => "test", + exp_target => "link", + conf => < "symlink %s{filename} substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "188:0", + exp_target => "ttyUSB0", + conf => < "symlink %Ns{filename} substitution", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "188", + exp_target => "ttyUSB0", + conf => < "symlink with '%' in name", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "percent%sign", + exp_target => "ttyUSB0", + conf => < "symlink with '%' in name", + subsys => "tty", + devpath => "/class/tty/ttyUSB0", + exp_name => "%ttyUSB0_name", + exp_target => "ttyUSB0", + conf => < "program result substitution (numbered part of)", + subsys => "block", + devpath => "/block/sda/sda3", + exp_name => "link1", + exp_target => "node", + conf => < "program result substitution (numbered part of+)", + subsys => "block", + devpath => "/block/sda/sda3", + exp_name => "link4", + exp_target => "node", + conf => <{exp_perms} =~ m/^(.*):(.*):(.*)$/; + if ($1 ne "") { + if ($uid != $1) { $wrong = 1; }; + } + if ($2 ne "") { + if ($gid != $2) { $wrong = 1; }; + } + if ($3 ne "") { + if (($mode & 07777) != oct($3)) { $wrong = 1; }; + } + if ($wrong == 0) { + print "permissions: ok "; + } 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; + $error++; + } +} + +sub major_minor_test { + my($config, $rdev) = @_; + + my $major = ($rdev >> 8) & 0xfff; + my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); + my $wrong = 0; + + $config->{exp_majorminor} =~ m/^(.*):(.*)$/; + if ($1 ne "") { + if ($major != $1) { $wrong = 1; }; + } + if ($2 ne "") { + if ($minor != $2) { $wrong = 1; }; + } + if ($wrong == 0) { + print "major:minor: ok "; + } 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 "; + $error++; + } +} + +sub symlink_test { + my ($config) = @_; + + my $output = `ls -l $PWD/$udev_root$config->{exp_name}`; + + if ($output =~ m/(.*)-> (.*)/) { + if ($2 eq $config->{exp_target}) { + print "symlink: ok "; + } 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 "; + } else { + $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 "; + } else { + $error++; + } + } +} + sub run_test { my ($config, $number) = @_; print "TEST $number: $config->{desc}\n"; - print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n"; + + if ($config->{exp_target}) { + print "device \'$config->{devpath}\' expecting symlink '$config->{exp_name}' to node \'$config->{exp_target}\'\n"; + } else { + print "device \'$config->{devpath}\' expecting node \'$config->{exp_name}\'\n"; + } + udev("add", $config->{subsys}, $config->{devpath}, \$config->{conf}); - if (-e "$PWD/$udev_root$config->{exp_name}") { + + if ((-e "$PWD/$udev_root$config->{exp_name}") || + (-l "$PWD/$udev_root$config->{exp_name}")) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat("$PWD/$udev_root$config->{exp_name}"); if (defined($config->{exp_perms})) { - my $wrong = 0; - $config->{exp_perms} =~ m/^(.*):(.*):(.*)$/; - if ($1 ne "") { - if ($uid != $1) { $wrong = 1; }; - } - if ($2 ne "") { - if ($gid != $2) { $wrong = 1; }; - } - if ($3 ne "") { - if (($mode & 07777) != oct($3)) { $wrong = 1; }; - } - if ($wrong == 0) { - print "permissions: ok "; - } 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; - $error++; - } + permissions_test($config, $uid, $gid, $mode); } - if (defined($config->{exp_majorminor})) { - my $major = ($rdev >> 8) & 0xfff; - my $minor = ($rdev & 0xff) | (($rdev >> 12) & 0xfff00); - - my $wrong = 0; - $config->{exp_majorminor} =~ m/^(.*):(.*)$/; - if ($1 ne "") { - if ($major != $1) { $wrong = 1; }; - } - if ($2 ne "") { - if ($minor != $2) { $wrong = 1; }; - } - if ($wrong == 0) { - print "major:minor: ok "; - } else { - printf "expected major:minor is: %i:%i\n", $1, $2; - printf "created major:minor is : %i:%i\n", $major, $minor; - $error++; - } + major_minor_test($config, $rdev); + } + if (defined($config->{exp_target})) { + symlink_test($config); } - print "add: ok "; } else { - print "add: error\n"; - system("tree $udev_root"); - print "\n"; - $error++; + print "add: error "; + if ($config->{exp_error}) { + print "as expected "; + } else { + print "\n\n"; + system("tree $udev_root"); + print "\n"; + $error++; + } } 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\n\n"; - system("tree $udev_root"); - $error++; + print "remove: error "; + if ($config->{exp_error}) { + print "as expected\n\n"; + } else { + print "\n\n"; + system("tree $udev_root"); + print "\n"; + $error++; + } } else { print "remove: ok\n\n"; } diff --git a/test/udev.permissions b/test/udev.permissions index 44ef3d43..b7baeea7 100644 --- a/test/udev.permissions +++ b/test/udev.permissions @@ -4,3 +4,19 @@ ttyUSB1:root:uucp:0666 visor:500:500:0666 dsp1:::0666 boot_disk?:::0666 + +#used for permissions tests in udev-test.pl +tty0::root:0444 +tty1:root::0555 +tty2:::0777 +tty3::: +rtc:0:6:0770 +misc/*:0:users:0600 +i2c-fake1:root:7:0007 +i2c*:root:sys:0744 +ttyS[01]:0:5:0700 +ttyS[5-9]:root:5:0060 +tty4::tty:0707 +tty4?::tty:0007 +tty3[!3]:::0467 +tty33:bad:name:0500 -- 2.39.5