[libvirt] [PATCH] tests: skip systemd activation test if FDs 3/4/5 are open

Daniel P. Berrangé posted 1 patch 4 years, 9 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190712171343.29342-1-berrange@redhat.com
tests/virsystemdtest.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
[libvirt] [PATCH] tests: skip systemd activation test if FDs 3/4/5 are open
Posted by Daniel P. Berrangé 4 years, 9 months ago
With systemd activation the passed in file descriptors are required to
be numbered from STDERR_FILENO + 1 onwards. The unit tests thus require
FDs 3, 4 and 5 to be available.

This may not be the case in all environments in which the tests run. For
example on RHEL7 it was seen that a library constructor (gcrypt probably)
opens /dev/urandom and leaves the file handle open. This means FD 3 is
not available and the activation tests fail.

The best way to deal with this would be to create a standalone helper
program for the tests, but that's much more work than just skipping the
tests if we notice we have the problem.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---

Pushed as a CI build fix

 tests/virsystemdtest.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index 586c512fca..cd031914ab 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -23,6 +23,7 @@
 #if defined(WITH_DBUS) && defined(__linux__)
 
 # include <dbus/dbus.h>
+# include <fcntl.h>
 
 # define LIBVIRT_VIRSYSTEMDPRIV_H_ALLOW
 # include "virsystemdpriv.h"
@@ -762,10 +763,17 @@ mymain(void)
 
     if (virTestRun("Test activation empty", testActivationEmpty, NULL) < 0)
         ret = -1;
-    if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
-        ret = -1;
-    if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
-        ret = -1;
+
+    if (fcntl(STDERR_FILENO + 1, F_GETFL) == -1 && errno == EBADF &&
+        fcntl(STDERR_FILENO + 2, F_GETFL) == -1 && errno == EBADF &&
+        fcntl(STDERR_FILENO + 3, F_GETFL) == -1 && errno == EBADF) {
+        if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
+            ret = -1;
+        if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
+            ret = -1;
+    } else {
+        VIR_INFO("Skipping activation tests as FD 3/4/5 is open");
+    }
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list