< prev index next >

test/java/net/ipv6tests/Tests.java

Print this page
rev 14513 : 8177536: Avoid Apple Peer-to-Peer interfaces in networking tests
Reviewed-by: michaelm, rriggs


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.net.*;
  25 import java.io.*;
  26 import java.util.*;
  27 
  28 public class Tests {
  29 
  30     static boolean isWindows = System.getProperty("os.name").startsWith("Windows");



  31 
  32     /**
  33      * performs a simple exchange of data between the two sockets
  34      * and throws an exception if there is any problem.
  35      */
  36     public static void simpleDataExchange (Socket s1, Socket s2)
  37         throws Exception {
  38 
  39         InputStream i1 = s1.getInputStream();
  40         InputStream i2 = s2.getInputStream();
  41         OutputStream o1 = s1.getOutputStream();
  42         OutputStream o2 = s2.getOutputStream();
  43 
  44         startSimpleWriter("SimpleWriter-1", o1, 100);
  45         startSimpleWriter("SimpleWriter-2", o2, 200);
  46         simpleRead (i2, 100);
  47         simpleRead (i1, 200);
  48     }
  49 
  50     static void startSimpleWriter(String threadName, final OutputStream os, final int start) {


 261                             && !addr.isAnyLocalAddress()) {
 262                         if (Arrays.equals (addr.getAddress(), fe80_loopback)) {
 263                             continue;
 264                         }
 265                         return addr;
 266                     }
 267                 }
 268                 currIf = null;
 269             }
 270         }
 271 
 272         private NetworkInterface getNextIf () {
 273             if (ifs != null) {
 274                 while (ifs.hasMoreElements()) {
 275                     NetworkInterface nic = (NetworkInterface)ifs.nextElement();
 276                     // Skip (Windows)Teredo Tunneling Pseudo-Interface
 277                     if (isWindows) {
 278                         String dName = nic.getDisplayName();
 279                         if (dName != null && dName.contains("Teredo"))
 280                             continue;


 281                     }
 282                     try {
 283                         if (nic.isUp() && !nic.isLoopback())
 284                             return nic;
 285                     } catch (SocketException e) {
 286                         // ignore
 287                     }
 288                 }
 289             }
 290 
 291             return null;
 292         }
 293     }
 294 
 295     /**
 296      * Throws a RuntimeException if the boolean condition is false
 297      */
 298     public static void t_assert (boolean assertion) {
 299         if (assertion) {
 300             return;




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.net.*;
  25 import java.io.*;
  26 import java.util.*;
  27 
  28 public class Tests {
  29 
  30     static final boolean isWindows =
  31             System.getProperty("os.name").startsWith("Windows");
  32     static final boolean isMacOS =
  33             System.getProperty("os.name").contains("OS X");
  34 
  35     /**
  36      * performs a simple exchange of data between the two sockets
  37      * and throws an exception if there is any problem.
  38      */
  39     public static void simpleDataExchange (Socket s1, Socket s2)
  40         throws Exception {
  41 
  42         InputStream i1 = s1.getInputStream();
  43         InputStream i2 = s2.getInputStream();
  44         OutputStream o1 = s1.getOutputStream();
  45         OutputStream o2 = s2.getOutputStream();
  46 
  47         startSimpleWriter("SimpleWriter-1", o1, 100);
  48         startSimpleWriter("SimpleWriter-2", o2, 200);
  49         simpleRead (i2, 100);
  50         simpleRead (i1, 200);
  51     }
  52 
  53     static void startSimpleWriter(String threadName, final OutputStream os, final int start) {


 264                             && !addr.isAnyLocalAddress()) {
 265                         if (Arrays.equals (addr.getAddress(), fe80_loopback)) {
 266                             continue;
 267                         }
 268                         return addr;
 269                     }
 270                 }
 271                 currIf = null;
 272             }
 273         }
 274 
 275         private NetworkInterface getNextIf () {
 276             if (ifs != null) {
 277                 while (ifs.hasMoreElements()) {
 278                     NetworkInterface nic = (NetworkInterface)ifs.nextElement();
 279                     // Skip (Windows)Teredo Tunneling Pseudo-Interface
 280                     if (isWindows) {
 281                         String dName = nic.getDisplayName();
 282                         if (dName != null && dName.contains("Teredo"))
 283                             continue;
 284                     } else if (isMacOS && nic.getName().contains("awdl")) {
 285                         continue;
 286                     }
 287                     try {
 288                         if (nic.isUp() && !nic.isLoopback())
 289                             return nic;
 290                     } catch (SocketException e) {
 291                         // ignore
 292                     }
 293                 }
 294             }
 295 
 296             return null;
 297         }
 298     }
 299 
 300     /**
 301      * Throws a RuntimeException if the boolean condition is false
 302      */
 303     public static void t_assert (boolean assertion) {
 304         if (assertion) {
 305             return;


< prev index next >