changeset 4697:789287639365

7129308: Handle different format of OperatingSystemMXBean.getSystemLoadAverage() output on macosx Reviewed-by: michaelm
author juh
date Mon, 30 Jan 2012 07:37:43 +0000
parents 5599aa5a4a51
children 7929ac999cde
files test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java	Sat Jan 28 11:37:15 2012 +0000
+++ b/test/java/lang/management/OperatingSystemMXBean/GetSystemLoadAverage.java	Mon Jan 30 07:37:43 2012 +0000
@@ -79,7 +79,11 @@
         System.out.println("Test passed.");
     }
 
-    private static String LOAD_AVERAGE_TEXT = "load average:";
+    private static String LOAD_AVERAGE_TEXT
+            = System.getProperty("os.name").startsWith("Mac OS")
+                ? "load averages:"
+                : "load average:";
+
     private static void checkLoadAvg() throws Exception {
         // Obtain load average from OS command
         ProcessBuilder pb = new ProcessBuilder("/usr/bin/uptime");
@@ -91,11 +95,13 @@
 
         // verify if two values are close
         output = output.substring(output.lastIndexOf(LOAD_AVERAGE_TEXT) +
-                                  LOAD_AVERAGE_TEXT.length());
+                                  LOAD_AVERAGE_TEXT.length() + 1);
         System.out.println("Load average returned from uptime = " + output);
         System.out.println("getSystemLoadAverage() returned " + loadavg);
 
-        String[] lavg = output.split(",");
+        String[] lavg = System.getProperty("os.name").startsWith("Mac OS")
+                ? output.split(" ")
+                : output.split(",");
         double expected = Double.parseDouble(lavg[0]);
         double lowRange = expected * (1 - DELTA);
         double highRange = expected * (1 + DELTA);