ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
6136c1
From 8c82f3a4aa2d029dcc303cbf95a71194aa5ac9c3 Mon Sep 17 00:00:00 2001
6136c1
From: Evgeny Vereshchagin <evvers@ya.ru>
6136c1
Date: Fri, 9 Nov 2018 04:01:15 +0100
6136c1
Subject: [PATCH] udev-test: skip the test only if it can't setup its
6136c1
 environment
6136c1
6136c1
This is basically a replacement for 0eb3cc88504b5d8f74.
6136c1
6136c1
(cherry picked from commit 110a13202eab6d92678abcde08372d4afac1cc45)
6136c1
6136c1
Related: #1642728
6136c1
---
6136c1
 src/test/test-udev.c |  8 ++++++++
6136c1
 test/udev-test.pl    | 24 +++++++++++++++++++++---
6136c1
 2 files changed, 29 insertions(+), 3 deletions(-)
6136c1
6136c1
diff --git a/src/test/test-udev.c b/src/test/test-udev.c
6136c1
index bed51c1270..f098fab721 100644
6136c1
--- a/src/test/test-udev.c
6136c1
+++ b/src/test/test-udev.c
6136c1
@@ -65,6 +65,11 @@ int main(int argc, char *argv[]) {
6136c1
         log_parse_environment();
6136c1
         log_open();
6136c1
 
6136c1
+        if (!IN_SET(argc, 2, 3)) {
6136c1
+                log_error("This program needs one or two arguments, %d given", argc - 1);
6136c1
+                return EXIT_FAILURE;
6136c1
+        }
6136c1
+
6136c1
         err = fake_filesystems();
6136c1
         if (err < 0)
6136c1
                 return EXIT_FAILURE;
6136c1
@@ -73,6 +78,9 @@ int main(int argc, char *argv[]) {
6136c1
         if (udev == NULL)
6136c1
                 return EXIT_FAILURE;
6136c1
 
6136c1
+        if (argc == 2)
6136c1
+                return EXIT_SUCCESS;
6136c1
+
6136c1
         log_debug("version %s", PACKAGE_VERSION);
6136c1
         mac_selinux_init();
6136c1
 
6136c1
diff --git a/test/udev-test.pl b/test/udev-test.pl
6136c1
index 05b3e17188..aa38bae0b1 100755
6136c1
--- a/test/udev-test.pl
6136c1
+++ b/test/udev-test.pl
6136c1
@@ -1537,18 +1537,28 @@ sub udev_setup {
6136c1
         system("umount", $udev_tmpfs);
6136c1
         rmdir($udev_tmpfs);
6136c1
         mkdir($udev_tmpfs) || die "unable to create udev_tmpfs: $udev_tmpfs\n";
6136c1
-        system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs) && die "unable to mount tmpfs";
6136c1
+
6136c1
+        if (system("mount", "-o", "rw,mode=755,nosuid,noexec", "-t", "tmpfs", "tmpfs", $udev_tmpfs)) {
6136c1
+                warn "unable to mount tmpfs";
6136c1
+                return 0;
6136c1
+        }
6136c1
 
6136c1
         mkdir($udev_dev) || die "unable to create udev_dev: $udev_dev\n";
6136c1
         # setting group and mode of udev_dev ensures the tests work
6136c1
         # even if the parent directory has setgid bit enabled.
6136c1
         chown (0, 0, $udev_dev) || die "unable to chown $udev_dev\n";
6136c1
         chmod (0755, $udev_dev) || die "unable to chmod $udev_dev\n";
6136c1
-        system("mknod", $udev_dev . "/null", "c", "1", "3") && die "unable to create $udev_dev/null";
6136c1
+
6136c1
+        if (system("mknod", $udev_dev . "/null", "c", "1", "3")) {
6136c1
+                warn "unable to create $udev_dev/null";
6136c1
+                return 0;
6136c1
+        }
6136c1
 
6136c1
         system("cp", "-r", "test/sys/", $udev_sys) && die "unable to copy test/sys";
6136c1
 
6136c1
         system("rm", "-rf", "$udev_run");
6136c1
+
6136c1
+        return 1;
6136c1
 }
6136c1
 
6136c1
 sub run_test {
6136c1
@@ -1646,7 +1656,15 @@ if ($? >> 8 == 0) {
6136c1
         exit($EXIT_TEST_SKIP);
6136c1
 }
6136c1
 
6136c1
-udev_setup();
6136c1
+if (!udev_setup()) {
6136c1
+        warn "Failed to set up the environment, skipping the test";
6136c1
+        exit($EXIT_TEST_SKIP);
6136c1
+}
6136c1
+
6136c1
+if (!system($udev_bin, "check")) {
6136c1
+        warn "$udev_bin failed to set up the environment, skipping the test";
6136c1
+        exit($EXIT_TEST_SKIP);
6136c1
+}
6136c1
 
6136c1
 my $test_num = 1;
6136c1
 my @list;