richardphibel / rpms / systemd

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