From fd7123b2684f393761f879ec16e5a1f4929fe5a8 Mon Sep 17 00:00:00 2001
From: Jie Fu <jiefu@openjdk.org>
Date: Sat, 13 Jun 2020 14:29:08 +0800
Subject: [PATCH] 8247463: java/nio/channels/etc/OpenAndConnect.java fails due
 to IPv6 not available

Reviewed-by: dfuchs, alanb
---
 .../java/nio/channels/etc/OpenAndConnect.java | 95 ++++++++++++-------
 1 file changed, 60 insertions(+), 35 deletions(-)

diff --git a/test/jdk/java/nio/channels/etc/OpenAndConnect.java b/test/jdk/java/nio/channels/etc/OpenAndConnect.java
index 01c38c2ec91..b183076e49d 100644
--- a/test/jdk/java/nio/channels/etc/OpenAndConnect.java
+++ b/test/jdk/java/nio/channels/etc/OpenAndConnect.java
@@ -94,12 +94,23 @@ public class OpenAndConnect {
     @DataProvider(name = "openConnect")
     public Object[][] openConnect() {
         LinkedList<Object[]>  l = new LinkedList<>();
-        l.addAll(openConnectGenTests);
-        if (IA4LOCAL != null) {
-            l.addAll(openConnectV4LocalTests);
+        if (IPSupport.hasIPv4()) {
+            l.addAll(openConnectV4Tests);
+            if (IA4LOCAL != null) {
+                l.addAll(openConnectV4LocalTests);
+            }
         }
-        if (IA6LOCAL != null) {
-            l.addAll(openConnectV6LocalTests);
+        if (IPSupport.hasIPv6()) {
+            l.addAll(openConnectV6Tests);
+            if (IA6LOCAL != null) {
+                l.addAll(openConnectV6LocalTests);
+            }
+        }
+        if (IPSupport.hasIPv4() && IPSupport.hasIPv6()) {
+            l.addAll(openConnectV4AndV6Tests);
+            if (IA4LOCAL != null) {
+                l.addAll(openConnectV4LocalAndV6Tests);
+            }
         }
         return l.toArray(new Object[][]{});
     }
@@ -122,40 +133,20 @@ public class OpenAndConnect {
     //            +       +              +        +
     //      {   sfam,   saddr,         cfam,    caddr,      }
 
-    public static List<Object[]> openConnectGenTests =
+    // Basic tests for when an IPv4 is available
+    public static List<Object[]> openConnectV4Tests =
         Arrays.asList(new Object[][] {
             {   INET,   IA4LOOPBACK,   INET,    IA4LOOPBACK },
             {   INET,   IA4LOOPBACK,   null,    IA4LOOPBACK },
             {   INET,   IA4ANYLOCAL,   null,    IA4LOOPBACK },
             {   INET,   IA4ANYLOCAL,   INET,    IA4LOOPBACK },
-            {   INET6,  IA6ANYLOCAL,   null,    IA6LOOPBACK },
-            {   INET6,  IA6ANYLOCAL,   INET6,   IA6LOOPBACK },
-            {   INET6,  IA6LOOPBACK,   INET6,   IA6LOOPBACK },
             {   null,   IA4LOOPBACK,   INET,    IA4ANYLOCAL },
             {   null,   IA4LOOPBACK,   INET,    IA4LOOPBACK },
             {   null,   IA4LOOPBACK,   INET,    null        },
-            {   null,   IA4LOOPBACK,   INET6,   IA6ANYLOCAL },
-            {   null,   IA6LOOPBACK,   INET6,   IA6ANYLOCAL },
-            {   null,   IA6LOOPBACK,   INET6,   IA6LOOPBACK },
-            {   null,   IA6LOOPBACK,   INET6,   DONT_BIND   },
-            {   null,   IA4LOOPBACK,   INET6,   DONT_BIND   },
-            {   null,   IA4LOOPBACK,   INET6,   null        },
-            {   null,   IA6LOOPBACK,   INET6,   null        },
-            {   null,   IA4LOOPBACK,   null,    IA6ANYLOCAL },
-            {   null,   IA6LOOPBACK,   null,    IA6ANYLOCAL },
-            {   null,   IA6LOOPBACK,   null,    IA6LOOPBACK },
-            {   null,   IA4LOOPBACK,   null,    null        },
-            {   null,   IA6LOOPBACK,   null,    null        },
-            {   null,   IA6ANYLOCAL,   null,    IA6LOCAL    },
-            {   null,   IA6ANYLOCAL,   null,    IA6LOOPBACK },
-            {   null,   IA6ANYLOCAL,   INET6,   IA6LOCAL    },
-            {   null,   IA6ANYLOCAL,   INET6,   IA6LOOPBACK },
-            {   INET6,  IA6LOOPBACK,   INET6,   IA6LOOPBACK }
+            {   null,   IA4LOOPBACK,   null,    null        }
         });
 
-    // Additional tests for when an IPv4 local address or V6
-    // local address is available
-
+    // Additional tests for when an IPv4 local address is available
     public List<Object[]>  openConnectV4LocalTests =
         Arrays.asList(new Object[][] {
             {   INET,   IA4LOCAL,      INET,    IA4LOCAL    },
@@ -166,11 +157,28 @@ public class OpenAndConnect {
             {   null,   IA4LOCAL,      INET,    IA4ANYLOCAL },
             {   null,   IA4LOCAL,      INET,    IA4LOCAL    },
             {   null,   IA4LOCAL,      INET,    null        },
-            {   null,   IA4LOCAL,      INET6,   IA6ANYLOCAL },
-            {   null,   IA4LOCAL,      INET6,   null        },
-            {   null,   IA4LOCAL,      null,    IA6ANYLOCAL }
+            {   null,   IA4LOCAL,      null,    null        }
         });
 
+    // Basic tests for when an IPv6 is available
+    public List<Object[]> openConnectV6Tests =
+        Arrays.asList(new Object[][] {
+            {   INET6,  IA6ANYLOCAL,   null,    IA6LOOPBACK },
+            {   INET6,  IA6ANYLOCAL,   INET6,   IA6LOOPBACK },
+            {   INET6,  IA6LOOPBACK,   INET6,   IA6LOOPBACK },
+            {   INET6,  IA6LOOPBACK,   INET6,   IA6LOOPBACK },
+            {   null,   IA6ANYLOCAL,   null,    IA6LOOPBACK },
+            {   null,   IA6ANYLOCAL,   INET6,   IA6LOOPBACK },
+            {   null,   IA6LOOPBACK,   INET6,   IA6LOOPBACK },
+            {   null,   IA6LOOPBACK,   INET6,   DONT_BIND   },
+            {   null,   IA6LOOPBACK,   INET6,   null        },
+            {   null,   IA6LOOPBACK,   null,    IA6LOOPBACK },
+            {   null,   IA6LOOPBACK,   null,    null        },
+            {   null,   IA6LOOPBACK,   INET6,   IA6ANYLOCAL },
+            {   null,   IA6LOOPBACK,   null,    IA6ANYLOCAL }
+        });
+
+    // Additional tests for when an IPv6 local address is available
     public List<Object[]> openConnectV6LocalTests =
         Arrays.asList(new Object[][] {
             {   INET6,  IA6ANYLOCAL,   null,    IA6LOCAL    },
@@ -178,16 +186,33 @@ public class OpenAndConnect {
             {   INET6,  IA6LOCAL,      INET6,   IA6LOCAL    },
             {   INET6,  IA6LOCAL,      null,    IA6LOCAL    },
             {   INET6,  IA6LOCAL,      null,    DONT_BIND   },
+            {   INET6,  IA6LOCAL,      INET6,   IA6LOCAL    },
+            {   null,   IA6ANYLOCAL,   null,    IA6LOCAL    },
+            {   null,   IA6ANYLOCAL,   INET6,   IA6LOCAL    },
             {   null,   IA6LOCAL,      INET6,   IA6LOCAL    },
             {   null,   IA6LOCAL,      INET6,   IA6ANYLOCAL },
             {   null,   IA6LOCAL,      null,    IA6ANYLOCAL },
             {   null,   IA6LOCAL,      null,    IA6LOCAL    },
             {   null,   IA6LOCAL,      INET6,   null        },
-            {   null,   IA6LOCAL,      null,    null        },
-            {   null,   IA4LOCAL,      null,    null        },
-            {   INET6,  IA6LOCAL,      INET6,   IA6LOCAL    }
+            {   null,   IA6LOCAL,      null,    null        }
         });
 
+    // Additional tests for when IPv4 and IPv6 are available
+     public List<Object[]> openConnectV4AndV6Tests =
+        Arrays.asList(new Object[][] {
+            {   null,   IA4LOOPBACK,   INET6,   IA6ANYLOCAL },
+            {   null,   IA4LOOPBACK,   null,    IA6ANYLOCAL },
+            {   null,   IA4LOOPBACK,   INET6,   DONT_BIND   },
+            {   null,   IA4LOOPBACK,   INET6,   null        }
+        });
+
+    // Additional tests for when IPv4 local address and IPv6 are available
+    public List<Object[]> openConnectV4LocalAndV6Tests =
+        Arrays.asList(new Object[][] {
+            {   null,   IA4LOCAL,      INET6,   IA6ANYLOCAL },
+            {   null,   IA4LOCAL,      INET6,   null        },
+            {   null,   IA4LOCAL,      null,    IA6ANYLOCAL }
+        });
 
     /**
      * If the destination address is the wildcard, it is replaced by the alternate