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
Reviewed-by: mdoerr, lucy, jpai, dfuchs
  • Loading branch information
MBaesken committed Aug 23, 2023
1 parent 742e319 commit 703817d
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

5 comments on commit 703817d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 703817d Aug 23, 2023

Choose a reason for hiding this comment

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

@MBaesken the backport was successfully created on the branch MBaesken-backport-703817d2 in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 703817d2 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 23 Aug 2023 and was reviewed by Martin Doerr, Lutz Schmidt, Jaikiran Pai and Daniel Fuchs.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:

$ git fetch https://github.com/openjdk-bots/jdk21u.git MBaesken-backport-703817d2:MBaesken-backport-703817d2
$ git checkout MBaesken-backport-703817d2
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git MBaesken-backport-703817d2

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 703817d Aug 28, 2023

Choose a reason for hiding this comment

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

@MBaesken Could not automatically backport 703817d2 to openjdk/jdk17u-dev due to conflicts in the following files:

  • test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePositiveTest.java
  • test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePositiveTest.java
  • test/jdk/jdk/net/ExtendedSocketOption/DontFragmentTest.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b MBaesken-backport-703817d2

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 703817d21f6fd8b24cc670695625dfdb09d3592c

# Backport the commit
$ git cherry-pick --no-commit 703817d21f6fd8b24cc670695625dfdb09d3592c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 703817d21f6fd8b24cc670695625dfdb09d3592c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport 703817d21f6fd8b24cc670695625dfdb09d3592c.

Please sign in to comment.