8351002: com/sun/management/OperatingSystemMXBean cpuLoad tests fail intermittently

Reviewed-by: sspitsyn, lmesnik
This commit is contained in:
Kevin Walls 2025-03-26 09:03:19 +00:00
parent e32a0c90fe
commit eb6e8288c6
4 changed files with 65 additions and 20 deletions

View File

@ -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

View File

@ -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 class GetProcessCpuLoad {
e.printStackTrace();
}
}
if (ex != null) {
throw ex;
}
}
}

View File

@ -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 class GetProcessCpuTime {
}
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) {

View File

@ -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 class GetSystemCpuLoad {
e.printStackTrace();
}
}
if (ex != null) {
throw ex;
}
}
}