diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index d954b95b52099..db2fbdb041137 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -536,9 +536,8 @@ java/io/IO/IO.java 8337935 linux-pp # jdk_management -# First bug for AIX, second for Windows -com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java 8030957,8351002 aix-all,windows-all -com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957,8351002 aix-all,windows-all +com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java 8030957 aix-all +com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java index ecb65b7b3eaf5..3ee847b28b154 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuLoad.java @@ -25,23 +25,35 @@ * @test * @bug 7028071 * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() - * + * @library /test/lib * @run main GetProcessCpuLoad */ -import java.lang.management.*; import com.sun.management.OperatingSystemMXBean; +import java.lang.management.*; +import jdk.test.lib.Platform; public class GetProcessCpuLoad { public static void main(String[] argv) throws Exception { OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + + Exception ex = null; double load; - for(int i=0; i<10; i++) { + + for(int i = 0; i < 10; i++) { load = mbean.getProcessCpuLoad(); - if(load<0.0 || load>1.0) { + if (load == -1.0 && Platform.isWindows()) { + // Some Windows 2019 systems can return -1 for the first few reads. + // Remember a -1 in case it never gets better. + ex = new RuntimeException("getProcessCpuLoad() returns " + load + + " which is not in the [0.0,1.0] interval"); + } else if (load < 0.0 || load > 1.0) { throw new RuntimeException("getProcessCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); + } else { + // A good reading: forget any previous -1. + ex = null; } try { Thread.sleep(200); @@ -49,5 +61,9 @@ public static void main(String[] argv) throws Exception { e.printStackTrace(); } } + + if (ex != null) { + throw ex; + } } } diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java index f65b2616ae932..95d7ac9cb5dbe 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetProcessCpuTime.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ * @test * @bug 4858522 * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuTime() + * @library /test/lib * @author Steve Bohne */ @@ -45,6 +46,7 @@ import com.sun.management.OperatingSystemMXBean; import java.lang.management.*; +import jdk.test.lib.Platform; public class GetProcessCpuTime { @@ -55,9 +57,7 @@ public class GetProcessCpuTime { // Careful with these values. private static final long MIN_TIME_FOR_PASS = 1; - private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE; - - // No max time. + private static final long MAX_TIME_FOR_PASS = Long.MAX_VALUE / 10_000_000; private static boolean trace = false; @@ -74,9 +74,22 @@ public static void main(String args[]) throws Exception { } long ns = mbean.getProcessCpuTime(); + if (ns == -1 && Platform.isWindows()) { + // Some Windows 2019 systems can return -1 for the first few reads. + for (int i = 0; i < 10; i++) { + ns = mbean.getProcessCpuTime(); + if (ns != -1) { + break; + } + try { + Thread.sleep(200); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } if (ns == -1) { - System.out.println("getProcessCpuTime() is not supported"); - return; + throw new RuntimeException("getProcessCpuTime() is not supported"); } if (trace) { diff --git a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java index 7bd9d162cb38e..0501cbbcbd7d7 100644 --- a/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java +++ b/test/jdk/com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java @@ -24,24 +24,37 @@ /* * @test * @bug 7028071 - * @summary Basic unit test of OperatingSystemMXBean.getSystemCpuLoad() - * + * @summary Basic unit test of OperatingSystemMXBean.getProcessCpuLoad() + * @library /test/lib * @run main GetSystemCpuLoad */ -import java.lang.management.*; import com.sun.management.OperatingSystemMXBean; +import java.lang.management.*; +import jdk.test.lib.Platform; public class GetSystemCpuLoad { public static void main(String[] argv) throws Exception { OperatingSystemMXBean mbean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + + Exception ex = null; double load; - for(int i=0; i<10; i++) { + + for (int i = 0; i < 10; i++) { load = mbean.getSystemCpuLoad(); - if(load<0.0 || load>1.0) { + if (load == -1.0 && Platform.isWindows()) { + // Some Windows 2019 systems can return -1 for the first few reads. + // Remember a -1 in case it never gets better. + ex = new RuntimeException("getSystemCpuLoad() returns " + load + + " which is not in the [0.0,1.0] interval"); + + } else if (load < 0.0 || load > 1.0) { throw new RuntimeException("getSystemCpuLoad() returns " + load - + " which is not in the [0.0,1.0] interval"); + + " which is not in the [0.0,1.0] interval"); + } else { + // A good reading: forget any previous -1. + ex = null; } try { Thread.sleep(200); @@ -49,5 +62,9 @@ public static void main(String[] argv) throws Exception { e.printStackTrace(); } } + + if (ex != null) { + throw ex; + } } }