8136933: Additional tests for Solaris SO_FLOW_SLA socket option in JDK 9
Reviewed-by: chegar
This commit is contained in:
parent
9009c5951c
commit
600aaed0a7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -25,24 +25,35 @@
|
|||||||
* @test
|
* @test
|
||||||
* @bug 8032808 8044773
|
* @bug 8032808 8044773
|
||||||
* @modules jdk.net
|
* @modules jdk.net
|
||||||
|
* @library /lib/testlibrary
|
||||||
|
* @build jdk.testlibrary.*
|
||||||
* @run main/othervm -Xcheck:jni Test success
|
* @run main/othervm -Xcheck:jni Test success
|
||||||
* @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
|
* @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
|
||||||
* @run main/othervm/policy=policy.success -Xcheck:jni Test success
|
* @run main/othervm/policy=policy.success -Xcheck:jni Test success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.*;
|
import jdk.net.ExtendedSocketOptions;
|
||||||
|
import jdk.net.SocketFlow;
|
||||||
|
import jdk.net.Sockets;
|
||||||
|
import jdk.testlibrary.OSInfo;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.*;
|
import java.net.*;
|
||||||
import java.util.concurrent.*;
|
import java.nio.channels.AsynchronousSocketChannel;
|
||||||
import java.util.Set;
|
import java.nio.channels.DatagramChannel;
|
||||||
import jdk.net.*;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import static java.lang.System.out;
|
import static java.lang.System.out;
|
||||||
|
import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
interface Runner { void run() throws Exception; }
|
interface Runner { void run() throws Exception; }
|
||||||
|
|
||||||
static boolean expectSuccess;
|
static boolean expectSuccess;
|
||||||
|
private static final boolean expectSupport = checkExpectedOptionSupport();
|
||||||
|
private static final double solarisVersionToCheck = 11.2;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
@ -54,9 +65,8 @@ public class Test {
|
|||||||
expectSuccess = args[0].equals("success");
|
expectSuccess = args[0].equals("success");
|
||||||
|
|
||||||
// Main thing is to check for JNI problems
|
// Main thing is to check for JNI problems
|
||||||
// Doesn't matter if current system does not support the option
|
// Doesn't matter if currently setting the option with the loopback
|
||||||
// and currently setting the option with the loopback interface
|
// interface doesn't work
|
||||||
// doesn't work either
|
|
||||||
|
|
||||||
boolean sm = System.getSecurityManager() != null;
|
boolean sm = System.getSecurityManager() != null;
|
||||||
out.println("Security Manager enabled: " + sm);
|
out.println("Security Manager enabled: " + sm);
|
||||||
@ -75,56 +85,70 @@ public class Test {
|
|||||||
|
|
||||||
final int udp_port = dg.getLocalPort();
|
final int udp_port = dg.getLocalPort();
|
||||||
|
|
||||||
// If option not available, end test
|
|
||||||
Set<SocketOption<?>> options = dg.supportedOptions();
|
|
||||||
if (!options.contains(ExtendedSocketOptions.SO_FLOW_SLA)) {
|
|
||||||
System.out.println("SO_FLOW_SLA not supported");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Socket s = new Socket("127.0.0.1", tcp_port);
|
final Socket s = new Socket("127.0.0.1", tcp_port);
|
||||||
final SocketChannel sc = SocketChannel.open();
|
final SocketChannel sc = SocketChannel.open();
|
||||||
sc.connect(new InetSocketAddress("127.0.0.1", tcp_port));
|
sc.connect(new InetSocketAddress("127.0.0.1", tcp_port));
|
||||||
|
|
||||||
doTest("Sockets.setOption Socket", () -> {
|
doTest("Sockets.setOption Socket", () -> {
|
||||||
out.println(flowIn);
|
out.println(flowIn);
|
||||||
Sockets.setOption(s, ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
|
if (s.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
|
Sockets.setOption(s, SO_FLOW_SLA, flowIn);
|
||||||
out.println(flowIn);
|
out.println(flowIn);
|
||||||
});
|
});
|
||||||
doTest("Sockets.getOption Socket",() -> {
|
|
||||||
Sockets.getOption(s, ExtendedSocketOptions.SO_FLOW_SLA);
|
doTest("Sockets.getOption Socket", () -> {
|
||||||
|
Sockets.getOption(s, SO_FLOW_SLA);
|
||||||
out.println(flowIn);
|
out.println(flowIn);
|
||||||
});
|
});
|
||||||
doTest("Sockets.setOption SocketChannel",() ->
|
|
||||||
sc.setOption(ExtendedSocketOptions.SO_FLOW_SLA, flowIn)
|
doTest("Sockets.setOption SocketChannel", () -> {
|
||||||
|
if (sc.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
|
sc.setOption(SO_FLOW_SLA, flowIn);
|
||||||
|
});
|
||||||
|
doTest("Sockets.getOption SocketChannel", () ->
|
||||||
|
sc.getOption(SO_FLOW_SLA)
|
||||||
);
|
);
|
||||||
doTest("Sockets.getOption SocketChannel",() ->
|
doTest("Sockets.setOption DatagramSocket", () -> {
|
||||||
sc.getOption(ExtendedSocketOptions.SO_FLOW_SLA)
|
|
||||||
);
|
|
||||||
doTest("Sockets.setOption DatagramSocket",() -> {
|
|
||||||
try (DatagramSocket dg1 = new DatagramSocket(0)) {
|
try (DatagramSocket dg1 = new DatagramSocket(0)) {
|
||||||
|
if (dg1.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
|
|
||||||
dg1.connect(loop, udp_port);
|
dg1.connect(loop, udp_port);
|
||||||
Sockets.setOption(dg1, ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
|
Sockets.setOption(dg1, SO_FLOW_SLA, flowIn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
doTest("Sockets.setOption DatagramSocket 2", () -> {
|
doTest("Sockets.setOption DatagramSocket 2", () -> {
|
||||||
try (DatagramChannel dg2 = DatagramChannel.open()) {
|
try (DatagramChannel dg2 = DatagramChannel.open()) {
|
||||||
|
if (dg2.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
dg2.bind(new InetSocketAddress(loop, 0));
|
dg2.bind(new InetSocketAddress(loop, 0));
|
||||||
dg2.connect(new InetSocketAddress(loop, udp_port));
|
dg2.connect(new InetSocketAddress(loop, udp_port));
|
||||||
dg2.setOption(ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
|
dg2.setOption(SO_FLOW_SLA, flowIn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
doTest("Sockets.setOption MulticastSocket", () -> {
|
doTest("Sockets.setOption MulticastSocket", () -> {
|
||||||
try (MulticastSocket mc1 = new MulticastSocket(0)) {
|
try (MulticastSocket mc1 = new MulticastSocket(0)) {
|
||||||
|
if (mc1.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
mc1.connect(loop, udp_port);
|
mc1.connect(loop, udp_port);
|
||||||
Sockets.setOption(mc1, ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
|
Sockets.setOption(mc1, SO_FLOW_SLA, flowIn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
doTest("Sockets.setOption AsynchronousSocketChannel", () -> {
|
doTest("Sockets.setOption AsynchronousSocketChannel", () -> {
|
||||||
try (AsynchronousSocketChannel asc = AsynchronousSocketChannel.open()) {
|
try (AsynchronousSocketChannel asc = AsynchronousSocketChannel.open()) {
|
||||||
|
if (asc.supportedOptions().contains(SO_FLOW_SLA) != expectSupport) {
|
||||||
|
throw new RuntimeException("Unexpected supportedOptions()");
|
||||||
|
}
|
||||||
Future<Void> f = asc.connect(loopad);
|
Future<Void> f = asc.connect(loopad);
|
||||||
f.get();
|
f.get();
|
||||||
asc.setOption(ExtendedSocketOptions.SO_FLOW_SLA, flowIn);
|
asc.setOption(SO_FLOW_SLA, flowIn);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -144,14 +168,43 @@ public class Test {
|
|||||||
throw new RuntimeException("Unexpected SecurityException", e);
|
throw new RuntimeException("Unexpected SecurityException", e);
|
||||||
} else {
|
} else {
|
||||||
out.println("Caught expected: " + e);
|
out.println("Caught expected: " + e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
System.out.println(e);
|
if (expectSupport) {
|
||||||
|
throw new RuntimeException("Test failed: " +
|
||||||
|
"unexpected UnsupportedOperationException");
|
||||||
|
}
|
||||||
|
out.println("UnsupportedOperationException as expected");
|
||||||
|
return;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Probably a permission error, but we're not
|
// Probably a permission error, but we're not
|
||||||
// going to check unless a specific permission exception
|
// going to check unless a specific permission exception
|
||||||
// is defined.
|
// is defined.
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
|
if (!expectSupport) {
|
||||||
|
throw new RuntimeException("Test failed: " +
|
||||||
|
"UnsupportedOperationException was not thrown");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean checkExpectedOptionSupport() {
|
||||||
|
if (OSInfo.getOSType().equals(OSInfo.OSType.SOLARIS)) {
|
||||||
|
double solarisVersion = OSInfo.getSolarisVersion();
|
||||||
|
if (solarisVersion >= solarisVersionToCheck) {
|
||||||
|
System.out.println("This Solaris version (" + solarisVersion
|
||||||
|
+ ") should support SO_FLOW_SLA option");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
System.out.println("This Solaris version (" + solarisVersion
|
||||||
|
+ ") should not support SO_FLOW_SLA option");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("Not Solaris, SO_FLOW_SLA should not be " +
|
||||||
|
"supported");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
grant {
|
grant {
|
||||||
|
permission java.util.PropertyPermission "os.name", "read";
|
||||||
|
permission java.io.FilePermission "<<ALL FILES>>", "execute";
|
||||||
|
permission java.util.PropertyPermission "line.separator", "read";
|
||||||
|
permission java.io.FilePermission "/etc/release", "read";
|
||||||
permission java.net.SocketPermission "127.0.0.1", "connect,accept" ;
|
permission java.net.SocketPermission "127.0.0.1", "connect,accept" ;
|
||||||
permission java.net.SocketPermission "localhost", "listen" ;
|
permission java.net.SocketPermission "localhost", "listen" ;
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
grant {
|
grant {
|
||||||
|
permission java.util.PropertyPermission "os.name", "read";
|
||||||
|
permission java.io.FilePermission "<<ALL FILES>>", "execute";
|
||||||
|
permission java.util.PropertyPermission "line.separator", "read";
|
||||||
|
permission java.io.FilePermission "/etc/release", "read";
|
||||||
permission java.net.SocketPermission "127.0.0.1", "connect,accept" ;
|
permission java.net.SocketPermission "127.0.0.1", "connect,accept" ;
|
||||||
permission java.net.SocketPermission "localhost", "listen" ;
|
permission java.net.SocketPermission "localhost", "listen" ;
|
||||||
permission jdk.net.NetworkPermission "setOption.SO_FLOW_SLA";
|
permission jdk.net.NetworkPermission "setOption.SO_FLOW_SLA";
|
||||||
|
@ -28,6 +28,9 @@ package jdk.testlibrary;
|
|||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
import static jdk.testlibrary.OSInfo.OSType.*;
|
import static jdk.testlibrary.OSInfo.OSType.*;
|
||||||
|
|
||||||
@ -147,6 +150,28 @@ public class OSInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double getSolarisVersion() {
|
||||||
|
try {
|
||||||
|
OutputAnalyzer output = ProcessTools.executeProcess("uname", "-v");
|
||||||
|
System.out.println("'uname -v' finished with code "
|
||||||
|
+ output.getExitValue());
|
||||||
|
return Double.parseDouble(output.getOutput());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("First attempt failed with: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Try to get Solaris version from /etc/release
|
||||||
|
try (BufferedReader in =
|
||||||
|
new BufferedReader(new FileReader("/etc/release"))) {
|
||||||
|
String line = in.readLine().trim().split(" ")[2];
|
||||||
|
return Double.parseDouble(line);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Second attempt failed with: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Unable to get Solaris version");
|
||||||
|
}
|
||||||
|
|
||||||
public static class WindowsVersion implements Comparable<WindowsVersion> {
|
public static class WindowsVersion implements Comparable<WindowsVersion> {
|
||||||
private final int major;
|
private final int major;
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ public final class ProcessTools {
|
|||||||
* @param cmds The command line to execute.
|
* @param cmds The command line to execute.
|
||||||
* @return The output from the process.
|
* @return The output from the process.
|
||||||
*/
|
*/
|
||||||
public static OutputAnalyzer executeProcess(String... cmds) throws Throwable {
|
public static OutputAnalyzer executeProcess(String... cmds) throws Exception {
|
||||||
return executeProcess(new ProcessBuilder(cmds));
|
return executeProcess(new ProcessBuilder(cmds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user