8313873: java/nio/channels/DatagramChannel/SendReceiveMaxSize.java fails on AIX due to small default RCVBUF size and different IPv6 Header interpretation

Reviewed-by: clanger, mbaesken
This commit is contained in:
Thomas Obermeier 2023-08-31 09:51:13 +00:00 committed by Thomas Stuefe
parent b0353addf2
commit 486fa08d4b
2 changed files with 33 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,6 +55,7 @@ import java.util.function.Predicate;
import static java.net.StandardProtocolFamily.INET;
import static java.net.StandardProtocolFamily.INET6;
import static java.net.StandardSocketOptions.SO_SNDBUF;
import static java.net.StandardSocketOptions.SO_RCVBUF;
import static jdk.test.lib.net.IPSupport.hasIPv4;
import static jdk.test.lib.net.IPSupport.hasIPv6;
import static jdk.test.lib.net.IPSupport.preferIPv4Stack;
@ -63,8 +64,6 @@ import static org.testng.Assert.assertThrows;
import static org.testng.Assert.assertTrue;
public class SendReceiveMaxSize {
private final static int IPV4_SNDBUF = 65507;
private final static int IPV6_SNDBUF = 65527;
private final static Class<IOException> IOE = IOException.class;
private final static Random random = RandomFactory.getRandom();
@ -89,12 +88,12 @@ public class SendReceiveMaxSize {
.orElse((Inet4Address) InetAddress.getByName("127.0.0.1"));
testcases.add(new Object[]{
supplier(() -> DatagramChannel.open()),
IPV4_SNDBUF,
IPSupport.getMaxUDPSendBufSizeIPv4(),
IPv4Addr
});
testcases.add(new Object[]{
supplier(() -> DatagramChannel.open(INET)),
IPV4_SNDBUF,
IPSupport.getMaxUDPSendBufSizeIPv4(),
IPv4Addr
});
}
@ -105,12 +104,12 @@ public class SendReceiveMaxSize {
.orElse((Inet6Address) InetAddress.getByName("::1"));
testcases.add(new Object[]{
supplier(() -> DatagramChannel.open()),
IPV6_SNDBUF,
IPSupport.getMaxUDPSendBufSizeIPv6(),
IPv6Addr
});
testcases.add(new Object[]{
supplier(() -> DatagramChannel.open(INET6)),
IPV6_SNDBUF,
IPSupport.getMaxUDPSendBufSizeIPv6(),
IPv6Addr
});
}
@ -132,6 +131,10 @@ public class SendReceiveMaxSize {
throws IOException {
try (var receiver = DatagramChannel.open()) {
receiver.bind(new InetSocketAddress(host, 0));
assertTrue(receiver.getOption(SO_RCVBUF) >= capacity,
receiver.getOption(SO_RCVBUF) +
" for UDP receive buffer too small to hold capacity " +
capacity);
var port = receiver.socket().getLocalPort();
var addr = new InetSocketAddress(host, port);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,6 +23,8 @@
package jdk.test.lib.net;
import jdk.test.lib.Platform;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@ -48,6 +50,9 @@ public class IPSupport {
private static final boolean hasIPv6;
private static final boolean preferIPv4Stack;
private static final boolean preferIPv6Addresses;
private static final int IPV4_SNDBUF = 65507;
private static final int IPV6_SNDBUF = 65527;
private static final int IPV6_SNDBUF_AIX = 65487;
static {
hasIPv4 = runPrivilegedAction(() -> isSupported(Inet4Address.class));
@ -111,7 +116,6 @@ public class IPSupport {
return preferIPv6Addresses;
}
/**
* Whether or not the current networking configuration is valid or not.
*
@ -154,4 +158,21 @@ public class IPSupport {
out.println("preferIPv6Addresses: " + preferIPv6Addresses());
}
/**
* Return current platform's maximum size for IPv4 UDP send buffer
*/
public static final int getMaxUDPSendBufSizeIPv4() {
return IPV4_SNDBUF;
}
/**
* Return current platform's maximum size for IPv6 UDP send buffer
*/
public static final int getMaxUDPSendBufSizeIPv6() {
if (Platform.isAix()) {
return IPV6_SNDBUF_AIX;
} else {
return IPV6_SNDBUF;
}
}
}