From df9ad2af75bae7c56077313185e523a13f205242 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 23 May 2019 10:06:37 -0700 Subject: [PATCH] 8224645: Only test multicast interfaces if they exist Reviewed-by: alanb, dfuchs, chegar --- .../DatagramChannel/BasicMulticastTests.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/test/jdk/java/nio/channels/DatagramChannel/BasicMulticastTests.java b/test/jdk/java/nio/channels/DatagramChannel/BasicMulticastTests.java index fcea4edcf5e..8002f381bfe 100644 --- a/test/jdk/java/nio/channels/DatagramChannel/BasicMulticastTests.java +++ b/test/jdk/java/nio/channels/DatagramChannel/BasicMulticastTests.java @@ -38,7 +38,6 @@ import java.util.*; import java.io.IOException; import jdk.test.lib.NetworkConfiguration; -import jdk.test.lib.net.IPSupport; public class BasicMulticastTests { @@ -120,7 +119,10 @@ public class BasicMulticastTests { InetAddress loopback) throws IOException { - System.out.println("Exception Tests"); + System.out.format("Exception Tests using %s, %s @ %s\n", + group.getHostAddress(), + notGroup.getHostAddress(), + nif.getName()); DatagramChannel dc = DatagramChannel.open(family) .setOption(StandardSocketOptions.SO_REUSEADDR, true) @@ -200,28 +202,36 @@ public class BasicMulticastTests { * and invoke tests. */ public static void main(String[] args) throws IOException { + NetworkConfiguration.printSystemConfiguration(System.out); + NetworkConfiguration config = NetworkConfiguration.probe(); // test IPv4 if available - if (IPSupport.hasIPv4()) { + { + var multicastInterfaces = config.ip4MulticastInterfaces().iterator(); InetAddress group = InetAddress.getByName("225.4.5.6"); InetAddress notGroup = InetAddress.getByName("1.2.3.4"); InetAddress loopback = InetAddress.getByName("127.0.0.1"); - NetworkInterface nif = config.ip4MulticastInterfaces().iterator().next(); - InetAddress anySource = config.ip4Addresses(nif).iterator().next(); - membershipKeyTests(StandardProtocolFamily.INET, group, nif, anySource); - exceptionTests(StandardProtocolFamily.INET, group, notGroup, nif, loopback); + while (multicastInterfaces.hasNext()) { + NetworkInterface nif = multicastInterfaces.next(); + InetAddress anySource = config.ip4Addresses(nif).iterator().next(); + membershipKeyTests(StandardProtocolFamily.INET, group, nif, anySource); + exceptionTests(StandardProtocolFamily.INET, group, notGroup, nif, loopback); + } } // test IPv6 if available - if (IPSupport.hasIPv6()) { + { + var multicastInterfaces = config.ip6MulticastInterfaces().iterator(); InetAddress group = InetAddress.getByName("ff02::a"); InetAddress notGroup = InetAddress.getByName("fe80::1234"); InetAddress loopback = InetAddress.getByName("::1"); - NetworkInterface nif = config.ip6MulticastInterfaces().iterator().next(); - InetAddress anySource = config.ip6Addresses(nif).iterator().next(); - membershipKeyTests(StandardProtocolFamily.INET6, group, nif, anySource); - exceptionTests(StandardProtocolFamily.INET6, group, notGroup, nif, loopback); + while (multicastInterfaces.hasNext()) { + NetworkInterface nif = multicastInterfaces.next(); + InetAddress anySource = config.ip6Addresses(nif).iterator().next(); + membershipKeyTests(StandardProtocolFamily.INET6, group, nif, anySource); + exceptionTests(StandardProtocolFamily.INET6, group, notGroup, nif, loopback); + } } } }