< prev index next >

test/lib/jdk/test/lib/Platform.java

Print this page
rev 2229 : 8165235: [TESTBUG] RTM tests must check OS version

@@ -26,10 +26,13 @@
 import java.util.regex.Pattern;
 
 public class Platform {
     public  static final String vmName      = System.getProperty("java.vm.name");
     public  static final String vmInfo      = System.getProperty("java.vm.info");
+    private static final String osVersion   = System.getProperty("os.version");
+    private static       int osVersion_major = -1;
+    private static       int osVersion_minor = -1;
     private static final String osName      = System.getProperty("os.name");
     private static final String dataModel   = System.getProperty("sun.arch.data.model");
     private static final String vmVersion   = System.getProperty("java.vm.version");
     private static final String jdkDebug    = System.getProperty("jdk.debug");
     private static final String osArch      = System.getProperty("os.arch");

@@ -110,10 +113,39 @@
 
     public static String getOsName() {
         return osName;
     }
 
+    // Os version support.
+    private static void init_version() {
+        try {
+            final String[] tokens = osVersion.split("\\.");
+            if (tokens.length > 0) {
+                osVersion_major = Integer.parseInt(tokens[0]);
+                if (tokens.length > 1) {
+                    osVersion_minor = Integer.parseInt(tokens[1]);
+                }
+            }
+        } catch (NumberFormatException e) {
+            osVersion_major = osVersion_minor = 0;
+        }
+    }
+
+    // Returns major version number from os.version system property.
+    // E.g. 5 on Solaris 10 and 3 on SLES 11.3 (for the linux kernel version).
+    public static int getOsVersionMajor() {
+        if (osVersion_major == -1) init_version();
+        return osVersion_major;
+    }
+
+    // Returns major version number from os.version system property.
+    // E.g. 10 on Solaris 10 and 0 on SLES 11.3 (for the linux kernel version).
+    public static int getOsVersionMinor() {
+        if (osVersion_minor == -1) init_version();
+        return osVersion_minor;
+    }
+
     public static boolean isDebugBuild() {
         return (jdkDebug.toLowerCase().contains("debug"));
     }
 
     public static String getVMVersion() {
< prev index next >