< prev index next >
test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java
Print this page
@ rev 58200 : 8240189: [TESTBUG] Some cgroup tests are failing after JDK-8231111
| Reviewed-by: mbaesken
~
*** 36,50 ****
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;
! import jdk.internal.platform.Metrics;
import jdk.internal.platform.CgroupV1Metrics;
public class MetricsTesterCgroupV1 implements CgroupMetricsTester {
private static long unlimited_minimum = 0x7FFFFFFFFF000000L;
long startSysVal;
long startUserVal;
long startUsage;
long startPerCpu[];
--- 36,54 ----
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;
! import jdk.internal.platform.CgroupSubsystem;
import jdk.internal.platform.CgroupV1Metrics;
+ import jdk.internal.platform.Metrics;
+ import jdk.test.lib.Asserts;
public class MetricsTesterCgroupV1 implements CgroupMetricsTester {
+ // Aliased for readability
+ private static final long RETVAL_UNAVAILABLE = CgroupSubsystem.LONG_RETVAL_UNLIMITED;
private static long unlimited_minimum = 0x7FFFFFFFFF000000L;
long startSysVal;
long startUserVal;
long startUsage;
long startPerCpu[];
*** 125,137 ****
// Initialize CPU usage metrics before we do any testing.
startSysVal = metrics.getCpuSystemUsage();
startUserVal = metrics.getCpuUserUsage();
startUsage = metrics.getCpuUsage();
startPerCpu = metrics.getPerCpuUsage();
- if (startPerCpu == null) {
- startPerCpu = new long[0];
- }
try {
Stream<String> lines = Files.lines(Paths.get("/proc/self/mountinfo"));
lines.filter(line -> line.contains(" - cgroup cgroup "))
.map(line -> line.split(" "))
--- 129,138 ----
*** 157,171 ****
}
}
private static long getLongValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
! return (data == null || data.isEmpty()) ? 0L : convertStringToLong(data);
}
private static long convertStringToLong(String strval) {
! return CgroupMetricsTester.convertStringToLong(strval, Long.MAX_VALUE);
}
private static long getLongValueFromFile(Controller subSystem, String metric, String subMetric) {
String stats = getFileContents(subSystem, metric);
String[] tokens = stats.split("[\\r\\n]+");
--- 158,172 ----
}
}
private static long getLongValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
! return (data == null || data.isEmpty()) ? RETVAL_UNAVAILABLE : convertStringToLong(data);
}
private static long convertStringToLong(String strval) {
! return CgroupMetricsTester.convertStringToLong(strval, RETVAL_UNAVAILABLE, Long.MAX_VALUE);
}
private static long getLongValueFromFile(Controller subSystem, String metric, String subMetric) {
String stats = getFileContents(subSystem, metric);
String[] tokens = stats.split("[\\r\\n]+");
*** 173,188 ****
if (tokens[i].startsWith(subMetric)) {
String strval = tokens[i].split("\\s+")[1];
return convertStringToLong(strval);
}
}
! return 0L;
}
private static double getDoubleValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
! return data.isEmpty() ? 0.0 : Double.parseDouble(data);
}
private static void fail(Controller system, String metric, long oldVal, long testVal) {
CgroupMetricsTester.fail(system.value, metric, oldVal, testVal);
}
--- 174,189 ----
if (tokens[i].startsWith(subMetric)) {
String strval = tokens[i].split("\\s+")[1];
return convertStringToLong(strval);
}
}
! return RETVAL_UNAVAILABLE;
}
private static double getDoubleValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
! return data == null || data.isEmpty() ? RETVAL_UNAVAILABLE : Double.parseDouble(data);
}
private static void fail(Controller system, String metric, long oldVal, long testVal) {
CgroupMetricsTester.fail(system.value, metric, oldVal, testVal);
}
*** 201,210 ****
--- 202,218 ----
private static void warn(Controller system, String metric, long oldVal, long testVal) {
CgroupMetricsTester.warn(system.value, metric, oldVal, testVal);
}
+ private Long[] boxedArrayOrNull(long[] primitiveArray) {
+ if (primitiveArray == null) {
+ return null;
+ }
+ return LongStream.of(primitiveArray).boxed().toArray(Long[]::new);
+ }
+
public void testMemorySubsystem() {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
// User Memory
long oldVal = metrics.getMemoryFailCount();
*** 213,223 ****
fail(Controller.MEMORY, "memory.failcnt", oldVal, newVal);
}
oldVal = metrics.getMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? -1L : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemoryMaxUsage();
--- 221,231 ----
fail(Controller.MEMORY, "memory.failcnt", oldVal, newVal);
}
oldVal = metrics.getMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemoryMaxUsage();
*** 239,249 ****
fail(Controller.MEMORY, "memory.kmem.failcnt", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? -1L : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryMaxUsage();
--- 247,257 ----
fail(Controller.MEMORY, "memory.kmem.failcnt", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getKernelMemoryMaxUsage();
*** 265,275 ****
fail(Controller.MEMORY, "memory.kmem.tcp.failcnt", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? -1L : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryMaxUsage();
--- 273,283 ----
fail(Controller.MEMORY, "memory.kmem.tcp.failcnt", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED: newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getTcpMemoryMaxUsage();
*** 291,301 ****
fail(Controller.MEMORY, "memory.memsw.failcnt", oldVal, newVal);
}
oldVal = metrics.getMemoryAndSwapLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? -1L : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemoryAndSwapMaxUsage();
--- 299,309 ----
fail(Controller.MEMORY, "memory.memsw.failcnt", oldVal, newVal);
}
oldVal = metrics.getMemoryAndSwapLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes");
! newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemoryAndSwapMaxUsage();
*** 310,320 ****
fail(Controller.MEMORY, "memory.memsw.usage_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemorySoftLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.soft_limit_in_bytes");
! newVal = newVal > unlimited_minimum ? -1L : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.soft_limit_in_bytes", oldVal, newVal);
}
boolean oomKillEnabled = metrics.isMemoryOOMKillEnabled();
--- 318,328 ----
fail(Controller.MEMORY, "memory.memsw.usage_in_bytes", oldVal, newVal);
}
oldVal = metrics.getMemorySoftLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.soft_limit_in_bytes");
! newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.soft_limit_in_bytes", oldVal, newVal);
}
boolean oomKillEnabled = metrics.isMemoryOOMKillEnabled();
*** 335,359 ****
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
warn(Controller.CPUACCT, "cpuacct.usage", oldVal, newVal);
}
String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu");
! Long[] newVals = new Long[0];
if (newValsStr != null) {
newVals = Stream.of(newValsStr
.split("\\s+"))
.map(Long::parseLong)
.toArray(Long[]::new);
}
! long[] oldValsPrim = metrics.getPerCpuUsage();
! Long[] oldVals = LongStream.of(oldValsPrim == null ? new long[0] : oldValsPrim)
! .boxed().toArray(Long[]::new);
for (int i = 0; i < oldVals.length; i++) {
if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) {
warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]);
}
}
oldVal = metrics.getCpuUserUsage();
newVal = getLongValueFromFile(Controller.CPUACCT, "cpuacct.stat", "user");
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
warn(Controller.CPUACCT, "cpuacct.usage - user", oldVal, newVal);
--- 343,369 ----
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
warn(Controller.CPUACCT, "cpuacct.usage", oldVal, newVal);
}
String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu");
! Long[] newVals = null;
if (newValsStr != null) {
newVals = Stream.of(newValsStr
.split("\\s+"))
.map(Long::parseLong)
.toArray(Long[]::new);
}
! Long[] oldVals = boxedArrayOrNull(metrics.getPerCpuUsage());
! if (oldVals != null) {
for (int i = 0; i < oldVals.length; i++) {
if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) {
warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]);
}
}
+ } else {
+ Asserts.assertNull(newVals, Controller.CPUACCT.value() + "cpuacct.usage_percpu not both null");
+ }
oldVal = metrics.getCpuUserUsage();
newVal = getLongValueFromFile(Controller.CPUACCT, "cpuacct.stat", "user");
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
warn(Controller.CPUACCT, "cpuacct.usage - user", oldVal, newVal);
*** 406,466 ****
}
}
public void testCpuSets() {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
! Integer[] oldVal = Arrays.stream(metrics.getCpuSetCpus()).boxed().toArray(Integer[]::new);
! Arrays.sort(oldVal);
String cpusstr = getFileContents(Controller.CPUSET, "cpuset.cpus");
// Parse range string in the format 1,2-6,7
Integer[] newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! Arrays.sort(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.cpus", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
int [] cpuSets = metrics.getEffectiveCpuSetCpus();
! // Skip this test if this metric is not supported on this platform
! if (cpuSets.length != 0) {
! oldVal = Arrays.stream(cpuSets).boxed().toArray(Integer[]::new);
! Arrays.sort(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_cpus");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! Arrays.sort(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.effective_cpus", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
- }
! oldVal = Arrays.stream(metrics.getCpuSetMems()).boxed().toArray(Integer[]::new);
! Arrays.sort(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.mems");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! Arrays.sort(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.mems", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
int [] cpuSetMems = metrics.getEffectiveCpuSetMems();
! // Skip this test if this metric is not supported on this platform
! if (cpuSetMems.length != 0) {
! oldVal = Arrays.stream(cpuSetMems).boxed().toArray(Integer[]::new);
! Arrays.sort(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_mems");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! Arrays.sort(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.effective_mems", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
- }
double oldValue = metrics.getCpuSetMemoryPressure();
double newValue = getDoubleValueFromFile(Controller.CPUSET, "cpuset.memory_pressure");
if (!CgroupMetricsTester.compareWithErrorMargin(oldValue, newValue)) {
fail(Controller.CPUSET, "cpuset.memory_pressure", oldValue, newValue);
--- 416,470 ----
}
}
public void testCpuSets() {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
! Integer[] oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetCpus());
! oldVal = CgroupMetricsTester.sortAllowNull(oldVal);
String cpusstr = getFileContents(Controller.CPUSET, "cpuset.cpus");
// Parse range string in the format 1,2-6,7
Integer[] newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! newVal = CgroupMetricsTester.sortAllowNull(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.cpus", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
int [] cpuSets = metrics.getEffectiveCpuSetCpus();
! oldVal = CgroupMetricsTester.boxedArrayOrNull(cpuSets);
! oldVal = CgroupMetricsTester.sortAllowNull(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_cpus");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! newVal = CgroupMetricsTester.sortAllowNull(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.effective_cpus", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
! oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetMems());
! oldVal = CgroupMetricsTester.sortAllowNull(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.mems");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! newVal = CgroupMetricsTester.sortAllowNull(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.mems", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
int [] cpuSetMems = metrics.getEffectiveCpuSetMems();
! oldVal = CgroupMetricsTester.boxedArrayOrNull(cpuSetMems);
! oldVal = CgroupMetricsTester.sortAllowNull(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.effective_mems");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
! newVal = CgroupMetricsTester.sortAllowNull(newVal);
if (Arrays.compare(oldVal, newVal) != 0) {
fail(Controller.CPUSET, "cpuset.effective_mems", Arrays.toString(oldVal),
Arrays.toString(newVal));
}
double oldValue = metrics.getCpuSetMemoryPressure();
double newValue = getDoubleValueFromFile(Controller.CPUSET, "cpuset.memory_pressure");
if (!CgroupMetricsTester.compareWithErrorMargin(oldValue, newValue)) {
fail(Controller.CPUSET, "cpuset.memory_pressure", oldValue, newValue);
*** 496,508 ****
// make system call
long newSysVal = metrics.getCpuSystemUsage();
long newUserVal = metrics.getCpuUserUsage();
long newUsage = metrics.getCpuUsage();
long[] newPerCpu = metrics.getPerCpuUsage();
- if (newPerCpu == null) {
- newPerCpu = new long[0];
- }
// system/user CPU usage counters may be slowly increasing.
// allow for equal values for a pass
if (newSysVal < startSysVal) {
fail(Controller.CPU, "getCpuSystemUsage", newSysVal, startSysVal);
--- 500,509 ----
*** 516,536 ****
if (newUsage <= startUsage) {
fail(Controller.CPU, "getCpuUsage", newUsage, startUsage);
}
boolean success = false;
for (int i = 0; i < startPerCpu.length; i++) {
if (newPerCpu[i] > startPerCpu[i]) {
success = true;
break;
}
}
!
! if(!success) fail(Controller.CPU, "getPerCpuUsage", Arrays.toString(newPerCpu),
Arrays.toString(startPerCpu));
}
public void testMemoryUsage() throws Exception {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
long memoryMaxUsage = metrics.getMemoryMaxUsage();
long memoryUsage = metrics.getMemoryUsage();
--- 517,543 ----
if (newUsage <= startUsage) {
fail(Controller.CPU, "getCpuUsage", newUsage, startUsage);
}
+ if (startPerCpu != null) {
boolean success = false;
for (int i = 0; i < startPerCpu.length; i++) {
if (newPerCpu[i] > startPerCpu[i]) {
success = true;
break;
}
}
! if (!success) {
! fail(Controller.CPU, "getPerCpuUsage", Arrays.toString(newPerCpu),
Arrays.toString(startPerCpu));
}
+ } else {
+ Asserts.assertNull(newPerCpu, Controller.CPU.value() + " getPerCpuUsage not both null");
+ }
+
+ }
public void testMemoryUsage() throws Exception {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
long memoryMaxUsage = metrics.getMemoryMaxUsage();
long memoryUsage = metrics.getMemoryUsage();
< prev index next >