Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240189: [TESTBUG] Some cgroup tests are failing after JDK-8231111
Reviewed-by: mbaesken, bobv
  • Loading branch information
jerboaa committed Feb 24, 2020
1 parent 14c0986 commit c92adf41587767e9c5c8e116cfaeb375d36928aa
@@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import jdk.internal.platform.Metrics;

public class MetricsCpuTester {
@@ -96,7 +97,7 @@ private static void testCpuSets(String cpuset) {
}

// Check to see if this metric is supported on this platform
if (effectiveCpus.length != 0) {
if (effectiveCpus != null) {
if (!Arrays.equals(ipCpuSet, effectiveCpus)) {
throw new RuntimeException("Effective Cpusets not equal, expected : "
+ Arrays.toString(ipCpuSet) + ", got : "
@@ -131,7 +132,7 @@ private static void testCpuSetMemNodes(String cpusetMems) {
}

// Check to see if this metric is supported on this platform
if (effectiveMems.length != 0) {
if (effectiveMems != null) {
if (!Arrays.equals(ipCpuSet, effectiveMems)) {
throw new RuntimeException("Effective mem nodes not equal, expected : "
+ Arrays.toString(ipCpuSet) + ", got : "
@@ -23,10 +23,13 @@

import java.util.Arrays;

import jdk.internal.platform.Metrics;
import jdk.internal.platform.CgroupV1Metrics;
import jdk.internal.platform.Metrics;

public class MetricsMemoryTester {

public static final long UNLIMITED = -1;

public static void main(String[] args) {
System.out.println(Arrays.toString(args));
switch (args[0]) {
@@ -115,13 +118,13 @@ private static void testKernelMemoryLimit(String value) {
System.out.println("TEST PASSED!!!");
long limit = getMemoryValue(value);
long kmemlimit = mCgroupV1.getKernelMemoryLimit();
if (kmemlimit != 0 && limit != kmemlimit) {
if (kmemlimit != UNLIMITED && limit != kmemlimit) {
throw new RuntimeException("Kernel Memory limit not equal, expected : ["
+ limit + "]" + ", got : ["
+ kmemlimit + "]");
}
} else {
throw new RuntimeException("oomKillFlag test not supported for cgroups v2");
throw new RuntimeException("kernel memory limit test not supported for cgroups v2");
}
}

@@ -25,6 +25,7 @@

import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

@@ -41,9 +42,9 @@ interface CgroupMetricsTester {
public void testMemoryUsage() throws Exception;
public void testMisc();

public static long convertStringToLong(String strval, long overflowRetval) {
long retval = 0;
if (strval == null) return 0L;
public static long convertStringToLong(String strval, long initialVal, long overflowRetval) {
long retval = initialVal;
if (strval == null) return retval;

try {
retval = Long.parseLong(strval);
@@ -93,7 +94,7 @@ public static void warn(String controller, String metric, long oldVal, long test

public static Integer[] convertCpuSetsToArray(String cpusstr) {
if (cpusstr == null || EMPTY_STR.equals(cpusstr)) {
return new Integer[0];
return null;
}
// Parse range string in the format 1,2-6,7
Integer[] cpuSets = Stream.of(cpusstr.split(",")).flatMap(a -> {
@@ -108,4 +109,19 @@ public static Integer[] convertCpuSetsToArray(String cpusstr) {
return cpuSets;
}

public static Integer[] boxedArrayOrNull(int[] primitiveArray) {
if (primitiveArray == null) {
return null;
}
return Arrays.stream(primitiveArray).boxed().toArray(Integer[]::new);
}

public static Integer[] sortAllowNull(Integer[] array) {
if (array == null) {
return null;
}
Arrays.sort(array);
return array;
}

}
@@ -38,11 +38,15 @@
import java.util.stream.LongStream;
import java.util.stream.Stream;

import jdk.internal.platform.Metrics;
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;
@@ -127,9 +131,6 @@ public void setup() {
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"));
@@ -159,11 +160,11 @@ private static String getFileContents(Controller subSystem, String fileName) {

private static long getLongValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
return (data == null || data.isEmpty()) ? 0L : convertStringToLong(data);
return (data == null || data.isEmpty()) ? RETVAL_UNAVAILABLE : convertStringToLong(data);
}

private static long convertStringToLong(String strval) {
return CgroupMetricsTester.convertStringToLong(strval, Long.MAX_VALUE);
return CgroupMetricsTester.convertStringToLong(strval, RETVAL_UNAVAILABLE, Long.MAX_VALUE);
}

private static long getLongValueFromFile(Controller subSystem, String metric, String subMetric) {
@@ -175,12 +176,12 @@ private static long getLongValueFromFile(Controller subSystem, String metric, St
return convertStringToLong(strval);
}
}
return 0L;
return RETVAL_UNAVAILABLE;
}

private static double getDoubleValueFromFile(Controller subSystem, String fileName) {
String data = getFileContents(subSystem, fileName);
return data.isEmpty() ? 0.0 : Double.parseDouble(data);
return data == null || data.isEmpty() ? RETVAL_UNAVAILABLE : Double.parseDouble(data);
}

private static void fail(Controller system, String metric, long oldVal, long testVal) {
@@ -203,6 +204,13 @@ private static void warn(Controller system, String metric, long oldVal, long tes
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();

@@ -215,7 +223,7 @@ public void testMemorySubsystem() {

oldVal = metrics.getMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.limit_in_bytes");
newVal = newVal > unlimited_minimum ? -1L : newVal;
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.limit_in_bytes", oldVal, newVal);
}
@@ -241,7 +249,7 @@ public void testMemorySubsystem() {

oldVal = metrics.getKernelMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.limit_in_bytes");
newVal = newVal > unlimited_minimum ? -1L : newVal;
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.kmem.limit_in_bytes", oldVal, newVal);
}
@@ -267,7 +275,7 @@ public void testMemorySubsystem() {

oldVal = metrics.getTcpMemoryLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.kmem.tcp.limit_in_bytes");
newVal = newVal > unlimited_minimum ? -1L : newVal;
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);
}
@@ -293,7 +301,7 @@ public void testMemorySubsystem() {

oldVal = metrics.getMemoryAndSwapLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.memsw.limit_in_bytes");
newVal = newVal > unlimited_minimum ? -1L : newVal;
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.memsw.limit_in_bytes", oldVal, newVal);
}
@@ -312,7 +320,7 @@ public void testMemorySubsystem() {

oldVal = metrics.getMemorySoftLimit();
newVal = getLongValueFromFile(Controller.MEMORY, "memory.soft_limit_in_bytes");
newVal = newVal > unlimited_minimum ? -1L : newVal;
newVal = newVal > unlimited_minimum ? CgroupSubsystem.LONG_RETVAL_UNLIMITED : newVal;
if (!CgroupMetricsTester.compareWithErrorMargin(oldVal, newVal)) {
fail(Controller.MEMORY, "memory.soft_limit_in_bytes", oldVal, newVal);
}
@@ -337,20 +345,22 @@ public void testCpuAccounting() {
}

String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu");
Long[] newVals = new Long[0];
Long[] newVals = null;
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]);
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();
@@ -408,56 +418,50 @@ public void testCpuSchedulingMetrics() {

public void testCpuSets() {
CgroupV1Metrics metrics = (CgroupV1Metrics)Metrics.systemMetrics();
Integer[] oldVal = Arrays.stream(metrics.getCpuSetCpus()).boxed().toArray(Integer[]::new);
Arrays.sort(oldVal);
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);
Arrays.sort(newVal);
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();

// 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 = 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 = Arrays.stream(metrics.getCpuSetMems()).boxed().toArray(Integer[]::new);
Arrays.sort(oldVal);
oldVal = CgroupMetricsTester.boxedArrayOrNull(metrics.getCpuSetMems());
oldVal = CgroupMetricsTester.sortAllowNull(oldVal);
cpusstr = getFileContents(Controller.CPUSET, "cpuset.mems");
newVal = CgroupMetricsTester.convertCpuSetsToArray(cpusstr);
Arrays.sort(newVal);
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();

// 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));
}
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();
@@ -498,9 +502,6 @@ public void testCpuConsumption() throws IOException, InterruptedException {
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
@@ -518,16 +519,22 @@ public void testCpuConsumption() throws IOException, InterruptedException {
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 (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");
}

if(!success) fail(Controller.CPU, "getPerCpuUsage", Arrays.toString(newPerCpu),
Arrays.toString(startPerCpu));
}

public void testMemoryUsage() throws Exception {

0 comments on commit c92adf4

Please sign in to comment.