daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
bd1529
From 5f34ea55a8c6723240eb1641a655db7df3c428a2 Mon Sep 17 00:00:00 2001
bd1529
From: Martin Wilck <mwilck@suse.com>
bd1529
Date: Tue, 24 Apr 2018 09:38:26 +0200
bd1529
Subject: [PATCH] test/udev-test.pl: use computed devnode name
bd1529
bd1529
More often than not, the created devnode is the basename of the
bd1529
sysfs entry. The "devnode" device may be used to override the
bd1529
auto-detected node name.
bd1529
bd1529
Permissions and major/minor number are now verified on the devnode
bd1529
itself, not on symlinks.
bd1529
bd1529
For those tests where exp_name is set to the computed devnode name,
bd1529
the explicit "exp_name" can be removed. "exp_name" is only required for
bd1529
symlinks.
bd1529
bd1529
This allows separate testing for devnodes and symlinks an a follow-up
bd1529
patch.
bd1529
bd1529
(cherry picked from commit f0dccf01a7b4e72278e14effd74782ea83d0a73b)
bd1529
bd1529
Related: #1642728
bd1529
---
bd1529
 test/udev-test.pl | 92 +++++++++++++++++++++++++++++++++--------------
bd1529
 1 file changed, 66 insertions(+), 26 deletions(-)
bd1529
bd1529
diff --git a/test/udev-test.pl b/test/udev-test.pl
bd1529
index db25ef13c1..aa9a8dc2ff 100755
bd1529
--- a/test/udev-test.pl
bd1529
+++ b/test/udev-test.pl
bd1529
@@ -55,12 +55,10 @@ my @tests = (
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
bd1529
-                                exp_name        => "sda" ,
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         },
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1",
bd1529
-                                exp_name        => "sda1" ,
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -644,6 +642,7 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/virtual/block/fake!blockdev0",
bd1529
+                                devnode         => "fake/blockdev0",
bd1529
                                 exp_name        => "is/a/fake/blockdev0" ,
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -657,7 +656,7 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/virtual/block/fake!blockdev0",
bd1529
-                                exp_name        => "fake/blockdev0" ,
bd1529
+                                devnode         => "fake/blockdev0",
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -768,7 +767,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/virtual/tty/tty33",
bd1529
-                                exp_name        => "tty33",
bd1529
                                 exp_perms       => "0:0:0600",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -864,7 +862,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "1::",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -876,7 +873,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => ":1:0660",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -888,7 +884,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "::0060",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -900,7 +895,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "1:1:0777",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -912,7 +906,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "1:1:0777",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -926,7 +919,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "1:1:0777",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -942,7 +934,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1d.7/usb5/5-2/5-2:1.0/tty/ttyACM0",
bd1529
-                                exp_name        => "ttyACM0",
bd1529
                                 exp_perms       => "1:2:0777",
bd1529
                         }],
bd1529
                 rules           => <
bd1529
@@ -1922,7 +1913,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
bd1529
-                                exp_name        => "sda",
bd1529
                                 exp_perms       => "0:0:0000",
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         }],
bd1529
@@ -1935,7 +1925,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
bd1529
-                                exp_name        => "sda",
bd1529
                                 exp_perms       => "1:1:0400",
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         }],
bd1529
@@ -1949,7 +1938,6 @@ EOF
bd1529
                 devices => [
bd1529
                         {
bd1529
                                 devpath         => "/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda",
bd1529
-                                exp_name        => "sda",
bd1529
                                 exp_perms       => "0:0:0440",
bd1529
                                 exp_rem_error   => "yes",
bd1529
                         }],
bd1529
@@ -2203,6 +2191,44 @@ sub udev_setup {
bd1529
         return 1;
bd1529
 }
bd1529
 
bd1529
+sub get_devnode {
bd1529
+        my ($device) = @_;
bd1529
+        my $devnode;
bd1529
+
bd1529
+        if (defined($device->{devnode})) {
bd1529
+                $devnode = "$udev_dev/$device->{devnode}";
bd1529
+        } else {
bd1529
+                $devnode = "$device->{devpath}";
bd1529
+                $devnode =~ s!.*/!$udev_dev/!;
bd1529
+        }
bd1529
+        return $devnode;
bd1529
+}
bd1529
+
bd1529
+sub check_devnode {
bd1529
+        my ($device) = @_;
bd1529
+        my $devnode = get_devnode($device);
bd1529
+
bd1529
+        my @st = lstat("$devnode");
bd1529
+        if (! (-b _  || -c _)) {
bd1529
+                print "add $devnode:         error\n";
bd1529
+                system("tree", "$udev_dev");
bd1529
+                $error++;
bd1529
+                return undef;
bd1529
+        }
bd1529
+
bd1529
+        my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
bd1529
+            $atime, $mtime, $ctime, $blksize, $blocks) = @st;
bd1529
+
bd1529
+        if (defined($device->{exp_perms})) {
bd1529
+                permissions_test($device, $uid, $gid, $mode);
bd1529
+        }
bd1529
+        if (defined($device->{exp_majorminor})) {
bd1529
+                major_minor_test($device, $rdev);
bd1529
+        }
bd1529
+        print "add $devnode:         ok\n";
bd1529
+        return $devnode;
bd1529
+}
bd1529
+
bd1529
 sub check_add {
bd1529
         my ($device) = @_;
bd1529
 
bd1529
@@ -2215,19 +2241,13 @@ sub check_add {
bd1529
                 }
bd1529
         }
bd1529
 
bd1529
+        my $devnode = check_devnode($device);
bd1529
+
bd1529
         print "device \'$device->{devpath}\' expecting node/link \'$device->{exp_name}\'\n";
bd1529
+        return if (!defined($device->{exp_name}));
bd1529
+
bd1529
         if ((-e "$udev_dev/$device->{exp_name}") ||
bd1529
             (-l "$udev_dev/$device->{exp_name}")) {
bd1529
-
bd1529
-                my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
bd1529
-                    $atime, $mtime, $ctime, $blksize, $blocks) = stat("$udev_dev/$device->{exp_name}");
bd1529
-
bd1529
-                if (defined($device->{exp_perms})) {
bd1529
-                        permissions_test($device, $uid, $gid, $mode);
bd1529
-                }
bd1529
-                if (defined($device->{exp_majorminor})) {
bd1529
-                        major_minor_test($device, $rdev);
bd1529
-                }
bd1529
                 print "add $device->{devpath}:         ok\n";
bd1529
         } else {
bd1529
                 print "add  $device->{devpath}:         error";
bd1529
@@ -2243,12 +2263,32 @@ sub check_add {
bd1529
         }
bd1529
 }
bd1529
 
bd1529
+sub check_remove_devnode {
bd1529
+        my ($device) = @_;
bd1529
+        my $devnode = get_devnode($device);
bd1529
+
bd1529
+        if (-e "$devnode") {
bd1529
+                print "remove  $devnode:      error";
bd1529
+                print "\n";
bd1529
+                system("tree", "$udev_dev");
bd1529
+                print "\n";
bd1529
+                $error++;
bd1529
+                sleep(1);
bd1529
+        } else {
bd1529
+                print "remove $devnode:         ok\n";
bd1529
+        }
bd1529
+}
bd1529
+
bd1529
 sub check_remove {
bd1529
         my ($device) = @_;
bd1529
 
bd1529
+        check_remove_devnode($device);
bd1529
+
bd1529
+        return if (!defined($device->{exp_name}));
bd1529
+
bd1529
         if ((-e "$udev_dev/$device->{exp_name}") ||
bd1529
             (-l "$udev_dev/$device->{exp_name}")) {
bd1529
-                print "remove  $device->{devpath}:      error";
bd1529
+                print "remove  $device->{exp_name}:      error";
bd1529
                 if ($device->{exp_rem_error}) {
bd1529
                         print " as expected\n";
bd1529
                 } else {
bd1529
@@ -2259,7 +2299,7 @@ sub check_remove {
bd1529
                         sleep(1);
bd1529
                 }
bd1529
         } else {
bd1529
-                print "remove  $device->{devpath}:      ok\n";
bd1529
+                print "remove  $device->{exp_name}:      ok\n";
bd1529
         }
bd1529
 }
bd1529