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