21255d
From 8ee1cc626f616a2022d641a464fbde9108dd8ad9 Mon Sep 17 00:00:00 2001
21255d
From: Martin Wilck <mwilck@suse.com>
21255d
Date: Tue, 24 Apr 2018 10:50:24 +0200
21255d
Subject: [PATCH] test/udev-test.pl: test correctness of symlink targets
21255d
21255d
Test if symlinks are created correctly by comparing the symlink
21255d
targets to the devnode path. This implies (for the symlink) that
21255d
major/minor numbers and permissions are correct, as we have tested
21255d
that on the devnode already.
21255d
21255d
(cherry picked from commit 997683c8f152e1c139a7ce537de81a0aeae4627f)
21255d
21255d
Related: #1642728
21255d
---
21255d
 test/udev-test.pl | 23 ++++++++++++++++++-----
21255d
 1 file changed, 18 insertions(+), 5 deletions(-)
21255d
21255d
diff --git a/test/udev-test.pl b/test/udev-test.pl
21255d
index aa9a8dc2ff..2e3089c5e0 100755
21255d
--- a/test/udev-test.pl
21255d
+++ b/test/udev-test.pl
21255d
@@ -22,6 +22,7 @@ use POSIX qw(WIFEXITED WEXITSTATUS);
21255d
 use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
21255d
 use IPC::Semaphore;
21255d
 use Time::HiRes qw(usleep);
21255d
+use Cwd qw(getcwd abs_path);
21255d
 
21255d
 my $udev_bin            = "./test-udev";
21255d
 my $valgrind            = 0;
21255d
@@ -2243,14 +2244,26 @@ sub check_add {
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
-                print "add $device->{devpath}:         ok\n";
21255d
+        my @st = lstat("$udev_dev/$device->{exp_name}");
21255d
+        if (-l _) {
21255d
+                my $cwd = getcwd();
21255d
+                my $dir = "$udev_dev/$device->{exp_name}";
21255d
+                $dir =~ s!/[^/]*$!!;
21255d
+                my $tgt = readlink("$udev_dev/$device->{exp_name}");
21255d
+                $tgt = abs_path("$dir/$tgt");
21255d
+                $tgt =~ s!^$cwd/!!;
21255d
+
21255d
+                if ($tgt ne $devnode) {
21255d
+                        print "symlink $device->{exp_name}:         error, found -> $tgt\n";
21255d
+                        $error++;
21255d
+                        system("tree", "$udev_dev");
21255d
+                } else {
21255d
+                        print "symlink $device->{exp_name}:         ok\n";
21255d
+                }
21255d
         } else {
21255d
-                print "add  $device->{devpath}:         error";
21255d
+                print "symlink $device->{exp_name}:         error";
21255d
                 if ($device->{exp_add_error}) {
21255d
                         print " as expected\n";
21255d
                 } else {