< prev index next >

test/jdk/jdk/net/Sockets/Test.java

Print this page
rev 51542 : 8210039: move OSInfo to top level testlibrary
Reviewed-by: duke


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8032808 8044773
  27  * @modules jdk.net
  28  * @library /lib/testlibrary
  29  * @build jdk.testlibrary.*
  30  * @run main/othervm -Xcheck:jni Test success
  31  * @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
  32  * @run main/othervm/policy=policy.success -Xcheck:jni Test success
  33  */
  34 
  35 import jdk.net.ExtendedSocketOptions;
  36 import jdk.net.SocketFlow;
  37 import jdk.net.Sockets;
  38 import jdk.testlibrary.OSInfo;

  39 
  40 import java.io.IOException;
  41 import java.net.*;
  42 import java.nio.channels.AsynchronousSocketChannel;
  43 import java.nio.channels.DatagramChannel;
  44 import java.nio.channels.SocketChannel;
  45 import java.util.concurrent.Future;
  46 
  47 import static java.lang.System.out;
  48 import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
  49 
  50 public class Test {
  51 
  52     interface Runner { void run() throws Exception; }
  53 
  54     static boolean expectSuccess;
  55     private static final boolean expectSupport = checkExpectedOptionSupport();
  56     private static final double solarisVersionToCheck = 11.2;
  57 
  58     public static void main(String[] args) throws Exception {
  59 
  60         // quick check to see if supportedOptions() working before
  61         // creating any sockets and libnet loaded
  62 
  63         Sockets.supportedOptions(Socket.class);
  64 
  65         expectSuccess = args[0].equals("success");
  66 
  67         // Main thing is to check for JNI problems
  68         // Doesn't matter if currently setting the option with the loopback
  69         // interface doesn't work
  70 
  71         boolean sm = System.getSecurityManager() != null;
  72         out.println("Security Manager enabled: " + sm);
  73         out.println("Success expected: " + expectSuccess);
  74 
  75         SocketFlow flowIn = SocketFlow.create()
  76                                       .bandwidth(1000)


 173         } catch (UnsupportedOperationException e) {
 174             if (expectSupport) {
 175                 throw new RuntimeException("Test failed: " +
 176                         "unexpected UnsupportedOperationException");
 177             }
 178             out.println("UnsupportedOperationException as expected");
 179             return;
 180         } catch (IOException e) {
 181             // Probably a permission error, but we're not
 182             // going to check unless a specific permission exception
 183             // is defined.
 184             System.out.println(e);
 185         }
 186         if (!expectSupport) {
 187             throw new RuntimeException("Test failed: " +
 188                     "UnsupportedOperationException was not thrown");
 189         }
 190     }
 191 
 192     private static boolean checkExpectedOptionSupport() {
 193         if (OSInfo.getOSType().equals(OSInfo.OSType.SOLARIS)) {
 194             double solarisVersion = OSInfo.getSolarisVersion();
 195             if (solarisVersion >= solarisVersionToCheck) {

 196                 System.out.println("This Solaris version (" + solarisVersion
 197                         + ") should support SO_FLOW_SLA option");
 198                 return true;
 199             } else {
 200                 System.out.println("This Solaris version (" + solarisVersion
 201                         + ") should not support SO_FLOW_SLA option");
 202             }
 203         } else {
 204             System.out.println("Not Solaris, SO_FLOW_SLA should not be " +
 205                     "supported");
 206         }
 207         return false;
 208     }
 209 
 210 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8032808 8044773
  27  * @modules jdk.net
  28  * @library /test/lib
  29  * @build jdk.test.lib.OSVersion jdk.test.lib.Platform
  30  * @run main/othervm -Xcheck:jni Test success
  31  * @run main/othervm/policy=policy.fail -Xcheck:jni Test fail
  32  * @run main/othervm/policy=policy.success -Xcheck:jni Test success
  33  */
  34 

  35 import jdk.net.SocketFlow;
  36 import jdk.net.Sockets;
  37 import jdk.test.lib.Platform;
  38 import jdk.test.lib.OSVersion;
  39 
  40 import java.io.IOException;
  41 import java.net.*;
  42 import java.nio.channels.AsynchronousSocketChannel;
  43 import java.nio.channels.DatagramChannel;
  44 import java.nio.channels.SocketChannel;
  45 import java.util.concurrent.Future;
  46 
  47 import static java.lang.System.out;
  48 import static jdk.net.ExtendedSocketOptions.SO_FLOW_SLA;
  49 
  50 public class Test {
  51 
  52     interface Runner { void run() throws Exception; }
  53 
  54     static boolean expectSuccess;
  55     private static final boolean expectSupport = checkExpectedOptionSupport();

  56 
  57     public static void main(String[] args) throws Exception {
  58 
  59         // quick check to see if supportedOptions() working before
  60         // creating any sockets and libnet loaded
  61 
  62         Sockets.supportedOptions(Socket.class);
  63 
  64         expectSuccess = args[0].equals("success");
  65 
  66         // Main thing is to check for JNI problems
  67         // Doesn't matter if currently setting the option with the loopback
  68         // interface doesn't work
  69 
  70         boolean sm = System.getSecurityManager() != null;
  71         out.println("Security Manager enabled: " + sm);
  72         out.println("Success expected: " + expectSuccess);
  73 
  74         SocketFlow flowIn = SocketFlow.create()
  75                                       .bandwidth(1000)


 172         } catch (UnsupportedOperationException e) {
 173             if (expectSupport) {
 174                 throw new RuntimeException("Test failed: " +
 175                         "unexpected UnsupportedOperationException");
 176             }
 177             out.println("UnsupportedOperationException as expected");
 178             return;
 179         } catch (IOException e) {
 180             // Probably a permission error, but we're not
 181             // going to check unless a specific permission exception
 182             // is defined.
 183             System.out.println(e);
 184         }
 185         if (!expectSupport) {
 186             throw new RuntimeException("Test failed: " +
 187                     "UnsupportedOperationException was not thrown");
 188         }
 189     }
 190 
 191     private static boolean checkExpectedOptionSupport() {
 192         if (Platform.isSolaris()) {
 193             OSVersion solarisVersion = OSVersion.current();
 194             OSVersion solarisVersionToCheck = new OSVersion(11, 2);
 195             if (solarisVersion.compareTo(solarisVersionToCheck) >= 0) {
 196                 System.out.println("This Solaris version (" + solarisVersion
 197                         + ") should support SO_FLOW_SLA option");
 198                 return true;
 199             } else {
 200                 System.out.println("This Solaris version (" + solarisVersion
 201                         + ") should not support SO_FLOW_SLA option");
 202             }
 203         } else {
 204             System.out.println("Not Solaris, SO_FLOW_SLA should not be " +
 205                     "supported");
 206         }
 207         return false;
 208     }
 209 
 210 }
< prev index next >