]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test/udev-test.pl: test correctness of symlink targets
authorMartin Wilck <mwilck@suse.com>
Tue, 24 Apr 2018 08:50:24 +0000 (10:50 +0200)
committerMichal Sekletár <msekleta@redhat.com>
Mon, 2 Nov 2020 10:43:14 +0000 (11:43 +0100)
Test if symlinks are created correctly by comparing the symlink
targets to the devnode path. This implies (for the symlink) that
major/minor numbers and permissions are correct, as we have tested
that on the devnode already.

test/udev-test.pl

index 1becfab3212f6a27009b15872a3251d26ef3570e..cbe45f37f46f9a408fe0521c5bdc0efc51cd7e62 100755 (executable)
@@ -22,6 +22,7 @@ use POSIX qw(WIFEXITED WEXITSTATUS);
 use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT);
 use IPC::Semaphore;
 use Time::HiRes qw(usleep);
+use Cwd qw(getcwd abs_path);
 
 my $udev_bin            = "./test-udev";
 my $valgrind            = 0;
@@ -2243,14 +2244,26 @@ sub check_add {
 
         my $devnode = check_devnode($device);
 
-        print "device \'$device->{devpath}\' expecting node/link \'$device->{exp_name}\'\n";
         return if (!defined($device->{exp_name}));
 
-        if ((-e "$udev_dev/$device->{exp_name}") ||
-            (-l "$udev_dev/$device->{exp_name}")) {
-                print "add $device->{devpath}:         ok\n";
+        my @st = lstat("$udev_dev/$device->{exp_name}");
+        if (-l _) {
+                my $cwd = getcwd();
+                my $dir = "$udev_dev/$device->{exp_name}";
+                $dir =~ s!/[^/]*$!!;
+                my $tgt = readlink("$udev_dev/$device->{exp_name}");
+                $tgt = abs_path("$dir/$tgt");
+                $tgt =~ s!^$cwd/!!;
+
+                if ($tgt ne $devnode) {
+                        print "symlink $device->{exp_name}:         error, found -> $tgt\n";
+                        $error++;
+                        system("tree", "$udev_dev");
+                } else {
+                        print "symlink $device->{exp_name}:         ok\n";
+                }
         } else {
-                print "add  $device->{devpath}:         error";
+                print "symlink $device->{exp_name}:         error";
                 if ($device->{exp_add_error}) {
                         print " as expected\n";
                 } else {