ryantimwilson / rpms / systemd

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