< prev index next >

test/jdk/com/sun/management/OperatingSystemMXBean/TestTotalSwap.java

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

@@ -27,10 +27,11 @@
  * @summary Basic unit test of OperatingSystemMXBean.getTotalSwapSpaceSize()
  * @author  Steve Bohne
  * @author  Jaroslav Bachorik
  *
  * @library /lib/testlibrary
+ * @library /test/lib
  *
  * @build TestTotalSwap jdk.testlibrary.*
  * @run main TestTotalSwap
  */
 

@@ -53,11 +54,11 @@
  */
 
 import com.sun.management.OperatingSystemMXBean;
 import java.lang.management.*;
 
-import jdk.testlibrary.OSInfo;
+import jdk.test.lib.Platform;
 import jdk.testlibrary.ProcessTools;
 import jdk.testlibrary.OutputAnalyzer;
 
 public class TestTotalSwap {
 

@@ -108,24 +109,19 @@
 
         System.out.println("Test passed.");
     }
 
     private static long getSwapSizeFromOs() throws Throwable {
-        OSInfo.OSType os = OSInfo.getOSType();
-
-        switch (os) {
+        if (Platform.isLinux()) {
             // total       used       free     shared    buffers     cached
             // Mem:    16533540864 13638467584 2895073280  534040576 1630248960 6236909568
             // -/+ buffers/cache: 5771309056 10762231808
             // Swap:   15999168512          0 15999168512
-
-            case LINUX: {
                 String swapSizeStr = ProcessTools.executeCommand("free", "-b")
                                         .firstMatch("Swap:\\s+([0-9]+)\\s+.*", 1);
                 return Long.parseLong(swapSizeStr);
-            }
-            case SOLARIS: {
+        } else if (Platform.isSolaris()) {
                 // swapfile             dev   swaplo blocks   free
                 // /dev/dsk/c0t0d0s1   136,1      16 1638608 1600528
                 OutputAnalyzer out= ProcessTools.executeCommand(
                     "/usr/sbin/swap",
                     "-l"

@@ -141,12 +137,11 @@
                         swapSize += Long.parseLong(vals[3]) * 512; // size is reported in 512b blocks
                     }
                 }
 
                 return swapSize;
-            }
-            case MACOSX: {
+        } else if (Platform.isOSX()) {
                 // total = 8192.00M used = 7471.11M free = 720.89M (encrypted)
                 String swapSizeStr = ProcessTools.executeCommand(
                     "/usr/sbin/sysctl",
                     "-n",
                     "vm.swapusage"

@@ -154,14 +149,12 @@
                 if (swapSizeStr.toLowerCase().endsWith("m")) {
                     swapSizeStr = swapSizeStr.substring(0, swapSizeStr.length() - 1);
                     return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024); // size in MB
                 }
                 return (long)(Double.parseDouble(swapSizeStr) * 1024 * 1024);
-            }
-            default: {
-                System.err.println("Unsupported operating system: " + os);
-            }
+        } else {
+            System.err.println("Unsupported operating system: " + Platform.getOsName());
         }
 
         return -1;
     }
 }
< prev index next >