Skip to content

Commit

Permalink
8314517: some tests fail in case ipv6 is disabled on the machine
Browse files Browse the repository at this point in the history
Backport-of: 703817d21f6fd8b24cc670695625dfdb09d3592c
  • Loading branch information
MBaesken committed Aug 24, 2023
1 parent 5ad0c0c commit 5c84a01
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @test
* @summary Positive tests for java -m jdk.httpserver command
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @modules jdk.httpserver
* @run testng/othervm CommandLinePositiveTest
*/
Expand All @@ -35,6 +36,7 @@
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import jdk.test.lib.Platform;
import jdk.test.lib.net.IPSupport;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
Expand Down Expand Up @@ -154,10 +156,12 @@ public void testBindAllInterfaces(String opt) throws Throwable {
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
simpleserver(JAVA, "-m", "jdk.httpserver", opt, "::0")
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
if (IPSupport.hasIPv6()) {
simpleserver(JAVA, "-m", "jdk.httpserver", opt, "::0")
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
}
}

@Test(dataProvider = "bindOptions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @test
* @summary Positive tests for the jwebserver command-line tool
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @modules jdk.httpserver
* @run testng/othervm CommandLinePositiveTest
*/
Expand All @@ -35,6 +36,7 @@
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import jdk.test.lib.Platform;
import jdk.test.lib.net.IPSupport;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
Expand Down Expand Up @@ -154,10 +156,12 @@ public void testBindAllInterfaces(String opt) throws Throwable {
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
simpleserver(JWEBSERVER, opt, "::0")
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
if (IPSupport.hasIPv6()) {
simpleserver(JWEBSERVER, opt, "::0")
.shouldHaveExitValue(NORMAL_EXIT_CODE)
.shouldContain("Serving " + TEST_DIR_STR + " and subdirectories on 0.0.0.0 (all interfaces) port")
.shouldContain("URL http://" + InetAddress.getLocalHost().getHostAddress());
}
}

@Test(dataProvider = "bindOptions")
Expand Down
7 changes: 7 additions & 0 deletions test/jdk/java/net/InetAddress/HostsFileOrderingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.test.lib.net.IPSupport;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.testng.Assert;


/* @test
* @bug 8244958
* @library /test/lib
* @build jdk.test.lib.Platform jdk.test.lib.net.IPSupport
* @summary Test that "jdk.net.hosts.file" NameService implementation returns addresses
* with respect to "java.net.preferIPv4Stack" and "java.net.preferIPv6Addresses" system
* property values
Expand Down Expand Up @@ -106,6 +110,9 @@ static ExpectedOrder getExpectedOrderFromSystemProperties() {
PREFER_IPV4_STACK_VALUE.equalsIgnoreCase("true")) {
return ExpectedOrder.IPV4_ONLY;
}
if (!IPSupport.hasIPv6()) {
return ExpectedOrder.IPV4_ONLY;
}

if (PREFER_IPV6_ADDRESSES_VALUE != null) {
return switch(PREFER_IPV6_ADDRESSES_VALUE.toLowerCase()) {
Expand Down
25 changes: 14 additions & 11 deletions test/jdk/java/net/InetAddress/InternalNameServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* the system property jdk.net.hosts.file. This property specifies
* a file name that contains address host mappings, similar to those in
* /etc/hosts file.
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @run main/othervm -Djdk.net.hosts.file=TestHosts -Dsun.net.inetaddr.ttl=0
* InternalNameServiceTest
*/
Expand All @@ -38,6 +40,8 @@
import java.net.UnknownHostException;
import java.util.Arrays;

import jdk.test.lib.net.IPSupport;

public class InternalNameServiceTest {

static final String HOSTS_FILE_NAME = System.getProperty("jdk.net.hosts.file");
Expand Down Expand Up @@ -128,17 +132,16 @@ private static void testHostToIPAddressMappings(String hostsFileName)
}

// IPV6 tests

// IPV6 tests
addMappingToHostsFile("host-ipv6.sample-domain", "::1", hostsFileName,
true);
testAddress = InetAddress.getByName("host-ipv6.sample-domain");
retrievedIpAddr = testAddress.getAddress();
if (!Arrays.equals(retrievedIpAddr, expectedIpAddrIpv6_1)) {
System.out.println("retrieved ipv6 addr == " + Arrays.toString(retrievedIpAddr));
System.out.println("expected ipv6 addr == " + Arrays.toString(expectedIpAddrIpv6_1));
throw new RuntimeException(
"retrieved IPV6 Addr not equal to expected IPV6 Addr");
if (IPSupport.hasIPv6()) {
addMappingToHostsFile("host-ipv6.sample-domain", "::1", hostsFileName, true);
testAddress = InetAddress.getByName("host-ipv6.sample-domain");
retrievedIpAddr = testAddress.getAddress();
if (!Arrays.equals(retrievedIpAddr, expectedIpAddrIpv6_1)) {
System.out.println("retrieved ipv6 addr == " + Arrays.toString(retrievedIpAddr));
System.out.println("expected ipv6 addr == " + Arrays.toString(expectedIpAddrIpv6_1));
throw new RuntimeException(
"retrieved IPV6 Addr not equal to expected IPV6 Addr");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* a file name that contains address host mappings, similar to those in
* /etc/hosts file. TestHosts-III file exist, with a set of ipv4 and ipv6
* mappings
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @run main/othervm -Djdk.net.hosts.file=${test.src}/TestHosts-III -Dsun.net.inetaddr.ttl=0
* InternalNameServiceWithHostsFileTest
*/
Expand All @@ -36,6 +38,8 @@
import java.net.UnknownHostException;
import java.util.Arrays;

import jdk.test.lib.net.IPSupport;

public class InternalNameServiceWithHostsFileTest {
public static void main(String args[]) throws Exception {
// fe80::1
Expand All @@ -52,26 +56,31 @@ public static void main(String args[]) throws Exception {

// 10.2.3.4 testHost.testDomain
testHostsMapping(expectedIpv4Address, "testHost.testDomain");
// ::1 ip6-localhost ip6-loopback
testHostsMapping(expectedIpv6LocalhostAddress, "ip6-localhost");
// fe00::0 ip6-localnet
testHostsMapping(expectedIpv6LocalAddress, "ip6-localnet");
// fe80::1 link-local-host
testHostsMapping(expectedIpv6Address, "link-local-host");

if (IPSupport.hasIPv6()) {
// ::1 ip6-localhost ip6-loopback
testHostsMapping(expectedIpv6LocalhostAddress, "ip6-localhost");
// fe00::0 ip6-localnet
testHostsMapping(expectedIpv6LocalAddress, "ip6-localnet");
// fe80::1 link-local-host
testHostsMapping(expectedIpv6Address, "link-local-host");
}

testReverseLookup("10.2.3.4", "testHost.testDomain");

testReverseLookup("::1", "ip6-localhost");
testReverseLookup("0:0:0:0:0:0:0:1", "ip6-localhost");
testReverseLookup("0000:0000:0000:0000:0000:0000:0000:0001", "ip6-localhost");
if (IPSupport.hasIPv6()) {
testReverseLookup("::1", "ip6-localhost");
testReverseLookup("0:0:0:0:0:0:0:1", "ip6-localhost");
testReverseLookup("0000:0000:0000:0000:0000:0000:0000:0001", "ip6-localhost");

testReverseLookup("fe00::0", "ip6-localnet");
testReverseLookup("fe00:0:0:0:0:0:0:0", "ip6-localnet");
testReverseLookup("fe00:0000:0000:0000:0000:0000:0000:0000", "ip6-localnet");
testReverseLookup("fe00::0", "ip6-localnet");
testReverseLookup("fe00:0:0:0:0:0:0:0", "ip6-localnet");
testReverseLookup("fe00:0000:0000:0000:0000:0000:0000:0000", "ip6-localnet");

testReverseLookup("fe80::1", "link-local-host");
testReverseLookup("fe80:000:0:00:0:000:00:1", "link-local-host");
testReverseLookup("fe80:0000:0000:0000:0000:0000:0000:0001", "link-local-host");
testReverseLookup("fe80::1", "link-local-host");
testReverseLookup("fe80:000:0:00:0:000:00:1", "link-local-host");
testReverseLookup("fe80:0000:0000:0000:0000:0000:0000:0001", "link-local-host");
}
}

private static void testHostsMapping(byte[] expectedIpAddress, String hostName)
Expand Down
34 changes: 20 additions & 14 deletions test/jdk/jdk/net/ExtendedSocketOption/DontFragmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @bug 8243099 8285671
* @modules jdk.net
* @library /test/lib
* @build jdk.test.lib.Platform
* @build jdk.test.lib.Platform jdk.test.lib.net.IPSupport
* @run main/othervm DontFragmentTest ipv4
* @run main/othervm DontFragmentTest ipv6
*/
Expand All @@ -35,6 +35,7 @@
import java.net.*;
import java.nio.channels.*;
import jdk.test.lib.Platform;
import jdk.test.lib.net.IPSupport;
import static java.net.StandardProtocolFamily.INET;
import static java.net.StandardProtocolFamily.INET6;
import static jdk.net.ExtendedSocketOptions.IP_DONTFRAGMENT;
Expand All @@ -45,19 +46,24 @@ public class DontFragmentTest {

public static void main(String[] args) throws IOException {
isMacos = Platform.isOSX();
testDatagramChannel();
StandardProtocolFamily fam = args[0].equals("ipv4") ? INET : INET6;
System.out.println("Family = " + fam);
testDatagramChannel(args, fam);
try (DatagramSocket c = new DatagramSocket()) {
testDatagramSocket(c);
}
try (DatagramChannel dc = DatagramChannel.open(fam)) {
var c = dc.socket();
testDatagramSocket(c);
}
try (MulticastSocket mc = new MulticastSocket()) {
testDatagramSocket(mc);
boolean ipv6 = args[0].equals("ipv6");
if (ipv6 && !IPSupport.hasIPv6()) {
System.out.println("No IPv6 support detected, skipping IPv6 test case");
} else {
testDatagramChannel();
StandardProtocolFamily fam = ipv6 ? INET6 : INET;
System.out.println("Family = " + fam);
testDatagramChannel(args, fam);
try (DatagramSocket c = new DatagramSocket()) {
testDatagramSocket(c);
}
try (DatagramChannel dc = DatagramChannel.open(fam)) {
var c = dc.socket();
testDatagramSocket(c);
}
try (MulticastSocket mc = new MulticastSocket()) {
testDatagramSocket(mc);
}
}
}

Expand Down

1 comment on commit 5c84a01

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.