tests: skip systemd activation test if FDs 3/4/5 are open

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>
This commit is contained in:
Daniel P. Berrangé 2019-07-12 17:55:13 +01:00
parent 597bded48d
commit ff09b1f62b

View File

@ -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;
}