author | jboes |
Fri, 08 Nov 2019 11:15:16 +0000 | |
changeset 59029 | 3786a0962570 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
47125
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
2 |
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4422122 |
|
27 |
* @summary Test that MulticastSocket.getInterface returns the |
|
28 |
* same InetAddress set by MulticastSocket.setInterface |
|
47125
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
29 |
* @library /test/lib |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
30 |
* @build jdk.test.lib.NetworkConfiguration |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
31 |
* jdk.test.lib.Platform |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
32 |
* @run main TestInterfaces |
2 | 33 |
*/ |
47125
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
34 |
import jdk.test.lib.NetworkConfiguration; |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
35 |
|
2 | 36 |
import java.net.*; |
25654
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
37 |
import java.util.Arrays; |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
38 |
import java.util.Collections; |
2 | 39 |
import java.util.Enumeration; |
40 |
import java.io.IOException; |
|
41 |
||
42 |
public class TestInterfaces { |
|
43 |
||
21629
c347092074d9
8022963: java/net/NetworkInterface/Equals.java fails equality for Windows Teredo Interface
tyan
parents:
5506
diff
changeset
|
44 |
static final boolean isWindows = System.getProperty("os.name").startsWith("Windows"); |
c347092074d9
8022963: java/net/NetworkInterface/Equals.java fails equality for Windows Teredo Interface
tyan
parents:
5506
diff
changeset
|
45 |
|
2 | 46 |
public static void main(String args[]) throws Exception { |
47 |
int failures = 0; |
|
48 |
||
49 |
MulticastSocket soc = new MulticastSocket(); |
|
50 |
||
51 |
Enumeration nifs = NetworkInterface.getNetworkInterfaces(); |
|
52 |
while (nifs.hasMoreElements()) { |
|
53 |
NetworkInterface ni = (NetworkInterface)nifs.nextElement(); |
|
54 |
||
30809
2c40760f65a9
8041677: java/net/MulticastSocket/TestInterfaces failed on Oracle VM Virtual Ethernet Adapter
msheppar
parents:
25654
diff
changeset
|
55 |
// JDK-8022963, Skip (Windows) Teredo Tunneling Pseudo-Interface |
2c40760f65a9
8041677: java/net/MulticastSocket/TestInterfaces failed on Oracle VM Virtual Ethernet Adapter
msheppar
parents:
25654
diff
changeset
|
56 |
String dName = ni.getDisplayName(); |
2c40760f65a9
8041677: java/net/MulticastSocket/TestInterfaces failed on Oracle VM Virtual Ethernet Adapter
msheppar
parents:
25654
diff
changeset
|
57 |
if (isWindows && dName != null && dName.contains("Teredo")) |
2c40760f65a9
8041677: java/net/MulticastSocket/TestInterfaces failed on Oracle VM Virtual Ethernet Adapter
msheppar
parents:
25654
diff
changeset
|
58 |
continue; |
2c40760f65a9
8041677: java/net/MulticastSocket/TestInterfaces failed on Oracle VM Virtual Ethernet Adapter
msheppar
parents:
25654
diff
changeset
|
59 |
|
47125
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
60 |
// Skip those interfaces not up or not support multicast |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
61 |
if (!ni.isUp() || !ni.supportsMulticast()) |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
62 |
continue; |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
63 |
|
2 | 64 |
/* |
65 |
* Test MulticastSocket.getInterface |
|
66 |
*/ |
|
25654
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
67 |
System.out.println("Testing network interface " + ni); |
2 | 68 |
Enumeration addrs = ni.getInetAddresses(); |
69 |
while (addrs.hasMoreElements()) { |
|
70 |
InetAddress ia = (InetAddress)addrs.nextElement(); |
|
71 |
||
72 |
System.out.println("********************************"); |
|
73 |
System.out.println("MulticastSocket.setInterface(" + ia + ")"); |
|
74 |
||
75 |
try { |
|
76 |
soc.setInterface(ia); |
|
77 |
} catch (IOException ioe) { |
|
78 |
System.err.println("Can't set interface to: " + ia |
|
79 |
+ " " + ioe.getMessage()); |
|
80 |
continue; |
|
81 |
} |
|
82 |
||
83 |
InetAddress curr = soc.getInterface(); |
|
84 |
if (!curr.equals(ia)) { |
|
25654
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
85 |
System.err.println("NetworkInterface under test " + ni); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
86 |
displayInterfaceInformation(ni); |
2 | 87 |
System.err.println("MulticastSocket.getInterface returned: " + curr); |
88 |
System.err.println("Failed! Expected: " + ia); |
|
89 |
failures++; |
|
90 |
} else { |
|
91 |
System.out.println("Passed."); |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
/* |
|
96 |
* Test MulticastSocket.getNetworkInterface |
|
97 |
*/ |
|
98 |
System.out.println("********************************"); |
|
99 |
System.out.println("MulticastSocket.setNetworkInterface(" + |
|
100 |
ni.getName() + ")"); |
|
101 |
||
102 |
try { |
|
103 |
soc.setNetworkInterface(ni); |
|
104 |
} catch (IOException ioe) { |
|
105 |
System.err.println("Can't set interface to: " + ni.getName() |
|
106 |
+ " " + ioe.getMessage()); |
|
107 |
continue; |
|
108 |
} |
|
109 |
||
21629
c347092074d9
8022963: java/net/NetworkInterface/Equals.java fails equality for Windows Teredo Interface
tyan
parents:
5506
diff
changeset
|
110 |
|
2 | 111 |
NetworkInterface curr = soc.getNetworkInterface(); |
112 |
if (!curr.equals(ni)) { |
|
113 |
System.err.println("MulticastSocket.getNetworkInterface returned: " + curr); |
|
114 |
System.err.println("Failed! Expected: " + ni); |
|
25654
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
115 |
System.err.println("NetworkInterface details for curr variable "); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
116 |
displayInterfaceInformation(curr); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
117 |
System.err.println("NetworkInterface details for ni variable "); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
118 |
displayInterfaceInformation(ni) ; |
2 | 119 |
failures++; |
120 |
} else { |
|
121 |
System.out.println("Passed."); |
|
122 |
} |
|
123 |
||
124 |
} |
|
125 |
||
126 |
if (failures > 0) { |
|
47125
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
127 |
System.err.println("********************************"); |
46ab150d59cd
8134989: java/net/MulticastSocket/TestInterfaces.java failed due to unexpected IP address
xiaofeya
parents:
38471
diff
changeset
|
128 |
NetworkConfiguration.printSystemConfiguration(System.err); |
2 | 129 |
System.out.println("********************************"); |
130 |
throw new Exception(failures + " test(s) failed!!!"); |
|
131 |
} |
|
132 |
||
133 |
} |
|
134 |
||
25654
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
135 |
static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
136 |
System.err.println("Display name: " + netint.getDisplayName()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
137 |
System.err.println("Name: " + netint.getName()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
138 |
Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
139 |
|
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
140 |
for (InetAddress inetAddress : Collections.list(inetAddresses)) |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
141 |
System.err.println("InetAddress: " + inetAddress); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
142 |
|
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
143 |
System.err.println("Up? " + netint.isUp()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
144 |
System.err.println("Loopback? " + netint.isLoopback()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
145 |
System.err.println("PointToPoint? " + netint.isPointToPoint()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
146 |
System.err.println("Supports multicast? " + netint.supportsMulticast()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
147 |
System.err.println("Virtual? " + netint.isVirtual()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
148 |
System.err.println("Hardware address: " + |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
149 |
Arrays.toString(netint.getHardwareAddress())); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
150 |
System.err.println("MTU: " + netint.getMTU()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
151 |
System.err.println("Index: " + netint.getIndex()); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
152 |
System.err.println(); |
bab08a81b601
8050922: add additional diagnostic to java/net/MulticastSocket/TestInterfaces
msheppar
parents:
23045
diff
changeset
|
153 |
} |
2 | 154 |
} |