Skip to content

Commit eda416f

Browse files
committed
8380824: java/net/DatagramSocket/SendReceiveMaxSize.java could also test the loopback interface
1 parent 7b7f40b commit eda416f

1 file changed

Lines changed: 62 additions & 3 deletions

File tree

test/jdk/java/net/DatagramSocket/SendReceiveMaxSize.java

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
/*
25-
* @test
25+
* @test id=default
2626
* @bug 8242885 8250886 8240901
2727
* @key randomness
2828
* @summary This test verifies that on macOS, the send buffer size is configured
@@ -34,13 +34,62 @@
3434
* @library /test/lib
3535
* @build jdk.test.lib.net.IPSupport
3636
* @run testng/othervm SendReceiveMaxSize
37+
*/
38+
/*
39+
* @test id=preferIPv4Stack
40+
* @key randomness
41+
* @summary Check that it is possible to send and receive datagrams of
42+
* maximum size on macOS, using an IPv4 only socket.
43+
* @library /test/lib
44+
* @build jdk.test.lib.net.IPSupport
3745
* @run testng/othervm -Djava.net.preferIPv4Stack=true SendReceiveMaxSize
46+
*/
47+
/*
48+
* @test id=preferIPv6Addresses
49+
* @key randomness
50+
* @summary Check that it is possible to send and receive datagrams of
51+
* maximum size on macOS, using a dual socket and prefering
52+
* IPv6 addresses.
53+
* @library /test/lib
54+
* @build jdk.test.lib.net.IPSupport
3855
* @run testng/othervm -Djava.net.preferIPv6Addresses=true SendReceiveMaxSize
3956
*/
57+
/*
58+
* @test id=preferLoopback
59+
* @key randomness
60+
* @summary Check that it is possible to send and receive datagrams of
61+
* maximum size on macOS, using a dual socket and the loopback
62+
* interface.
63+
* @library /test/lib
64+
* @build jdk.test.lib.net.IPSupport
65+
* @run testng/othervm -Dtest.preferLoopback=true SendReceiveMaxSize
66+
*/
67+
/*
68+
* @test id=preferIPv6Loopback
69+
* @key randomness
70+
* @summary Check that it is possible to send and receive datagrams of
71+
* maximum size on macOS, using a dual socket and the loopback
72+
* interface.
73+
* @library /test/lib
74+
* @build jdk.test.lib.net.IPSupport
75+
* @run testng/othervm -Dtest.preferLoopback=true -Djava.net.preferIPv6Addresses=true SendReceiveMaxSize
76+
*/
77+
/*
78+
* @test id=preferIPv4Loopback
79+
* @key randomness
80+
* @summary Check that it is possible to send and receive datagrams of
81+
* maximum size on macOS, using an IPv4 only socket and the
82+
* loopback interface
83+
* @library /test/lib
84+
* @build jdk.test.lib.net.IPSupport
85+
* @run testng/othervm -Dtest.preferLoopback=true -Djava.net.preferIPv4Stack=true SendReceiveMaxSize
86+
*/
4087

4188
import jdk.test.lib.RandomFactory;
4289
import jdk.test.lib.Platform;
4390
import jdk.test.lib.net.IPSupport;
91+
import jtreg.SkippedException;
92+
import org.testng.SkipException;
4493
import org.testng.annotations.BeforeTest;
4594
import org.testng.annotations.DataProvider;
4695
import org.testng.annotations.Test;
@@ -61,6 +110,9 @@
61110
import static org.testng.Assert.expectThrows;
62111

63112
public class SendReceiveMaxSize {
113+
114+
private final static boolean PREFER_LOOPBACK = Boolean.getBoolean("test.preferLoopback");
115+
64116
private int BUF_LIMIT;
65117
private InetAddress HOST_ADDR;
66118
private final static int IPV4_SNDBUF = 65507;
@@ -75,8 +127,15 @@ public interface DatagramSocketSupplier {
75127

76128
@BeforeTest
77129
public void setUp() throws IOException {
78-
IPSupport.throwSkippedExceptionIfNonOperational();
79-
HOST_ADDR = InetAddress.getLocalHost();
130+
try {
131+
// This method throws jtreg.SkippedException, which is
132+
// interpreted as a test failure by testng
133+
IPSupport.throwSkippedExceptionIfNonOperational();
134+
} catch (SkippedException skip) {
135+
// throws the appropriate TestNG SkipException
136+
throw new SkipException(skip.getMessage());
137+
}
138+
HOST_ADDR = PREFER_LOOPBACK ? InetAddress.getLoopbackAddress() : InetAddress.getLocalHost();
80139
BUF_LIMIT = (HOST_ADDR instanceof Inet6Address) ? IPV6_SNDBUF : IPV4_SNDBUF;
81140
System.out.printf("Host address: %s, Buffer limit: %d%n", HOST_ADDR, BUF_LIMIT);
82141
}

0 commit comments

Comments
 (0)