Disable IPv6 interface tests if IPv6 is not available at runtime

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2018-10-24 00:13:16 +02:00
parent fbde1ba5b8
commit 0324f36dd2

View file

@ -16,9 +16,38 @@
on a given host. To properly test all combinations the abstracted
operating system functions must be mocked. */
/* FIXME: It's possible that IPv6 is available in the network stack, but
disabled in the kernel. Travis CI for example has build environments
that do not have IPv6 enabled. */
#ifdef OS_SOCKET_HAS_IPV6
static int ipv6_enabled = 1;
#endif
CUnit_Suite_Initialize(os_getifaddrs)
{
os_osInit();
#ifdef OS_SOCKET_HAS_IPV6
#ifdef __linux
FILE *fh;
const char *const *path;
static const char *const paths[] = {
"/proc/sys/net/ipv6/conf/all/disable_ipv6",
"/proc/sys/net/ipv6/conf/default/disable_ipv6",
NULL
};
for (path = paths; ipv6_enabled == 1 && *path != NULL; path++) {
if ((fh = fopen(*path, "r")) != NULL) {
ipv6_enabled = (fgetc(fh) == '0');
fclose(fh);
fh = NULL;
}
}
#endif /* __linux */
#endif /* OS_SOCKET_HAS_IPV6 */
return 0;
}
@ -90,7 +119,9 @@ CUnit_Test(os_getifaddrs, empty_filter)
#ifdef OS_SOCKET_HAS_IPV6
CUnit_Test(os_getifaddrs, ipv6)
{
if (ipv6_enabled == 1) {
int err;
int have_ipv6 = 0;
os_ifaddrs_t *ifa_root, *ifa;
const int afs[] = { AF_INET6, 0 };
@ -99,6 +130,7 @@ CUnit_Test(os_getifaddrs, ipv6)
for (ifa = ifa_root; ifa; ifa = ifa->next) {
CU_ASSERT_EQUAL(ifa->addr->sa_family, AF_INET6);
if (ifa->addr->sa_family == AF_INET6) {
have_ipv6 = 1;
if (ifa->flags & IFF_LOOPBACK) {
CU_ASSERT(os_sockaddrIsLoopback(ifa->addr));
} else {
@ -107,13 +139,21 @@ CUnit_Test(os_getifaddrs, ipv6)
}
}
CU_ASSERT_EQUAL(have_ipv6, 1);
os_freeifaddrs(ifa_root);
CU_PASS("IPv6 enabled in test environment");
} else {
CU_PASS("IPv6 disabled in test environment");
}
}
/* Assume at least one IPv4 and one IPv6 interface are available when IPv6 is
available on the platform. */
CUnit_Test(os_getifaddrs, ipv4_n_ipv6)
{
if (ipv6_enabled == 1) {
int err;
int have_ipv4 = 0;
int have_ipv6 = 0;
@ -136,6 +176,11 @@ CUnit_Test(os_getifaddrs, ipv4_n_ipv6)
CU_ASSERT_EQUAL(have_ipv6, 1);
os_freeifaddrs(ifa_root);
CU_PASS("IPv6 enabled in test environment");
} else {
CU_PASS("IPv6 disabled in test environment");
}
}
#endif /* OS_SOCKET_HAS_IPV6 */