Disable IPv6 Multicast test on interface
- without IPv6 address
Test: run cts -m CtsLibcoreTestCases --abi arm64-v8a
Bug: 269959909
Change-Id: I84ca268907892f654f39bffd73754c859a79a1a6
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/MulticastSocketTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/MulticastSocketTest.java
index dab784a..b79f7e7 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/MulticastSocketTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/MulticastSocketTest.java
@@ -712,7 +712,7 @@
Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces();
while (theInterfaces.hasMoreElements()) {
NetworkInterface thisInterface = (NetworkInterface) theInterfaces.nextElement();
- if (willWorkForMulticast(thisInterface)) {
+ if (willWorkForMulticast(thisInterface, group)) {
if ((!(thisInterface.getInetAddresses().nextElement()).isLoopbackAddress())) {
MulticastSocket receivingSocket = createReceivingSocket(0);
InetSocketAddress groupAddress =
@@ -907,6 +907,29 @@
&& iface.getInetAddresses().hasMoreElements();
}
+ private static boolean ipv6Assigned(NetworkInterface iface) {
+ Enumeration<InetAddress> addresses = iface.getInetAddresses();
+ while(addresses.hasMoreElements()){
+ InetAddress addr = addresses.nextElement();
+ if(addr instanceof Inet6Address)
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean willWorkForMulticast(NetworkInterface iface, InetAddress group) throws IOException {
+ return iface.isUp()
+ // Typically loopback interfaces do not support multicast, but we rule them out
+ // explicitly anyway.
+ && !iface.isLoopback()
+ // Point-to-point interfaces are known to cause problems. http://b/23279677
+ && !iface.isPointToPoint()
+ && iface.supportsMulticast()
+ && iface.getInetAddresses().hasMoreElements()
+ // To those interfaces don't have ipv6 address assigned, should not test.
+ && ((group instanceof Inet6Address) ? ipv6Assigned(iface) : true);
+ }
+
private static MulticastSocket createReceivingSocket(int aPort) throws IOException {
MulticastSocket ms = new MulticastSocket(aPort);
ms.setSoTimeout(2000);