< prev index next >

test/hotspot/jtreg/containers/docker/TestCPUAwareness.java

Print this page
@  rev 56576 : 8230305: Cgroups v2: Container awareness
|  Summary: Implement Cgroups v2 container awareness in hotspot
~  Reviewed-by: bobv

@@ -31,14 +31,16 @@
  *          java.management
  *          jdk.jartool/sun.tools.jar
  * @run driver TestCPUAwareness
  */
 import java.util.List;
+import java.util.Optional;
 import jdk.test.lib.containers.docker.Common;
 import jdk.test.lib.containers.docker.DockerRunOptions;
 import jdk.test.lib.containers.docker.DockerTestUtils;
 import jdk.test.lib.containers.cgroup.CPUSetsReader;
+import jdk.test.lib.process.OutputAnalyzer;
 
 public class TestCPUAwareness {
     private static final String imageName = Common.imageName("cpu");
     private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
 

@@ -200,10 +202,30 @@
 
         expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
 
         DockerRunOptions opts = Common.newOpts(imageName)
             .addDockerOpts("--cpu-shares=" + shares);
-        Common.run(opts)
-            .shouldMatch("CPU Shares is.*" + shares)
-            .shouldMatch("active_processor_count.*" + expectedAPC);
+        OutputAnalyzer out = Common.run(opts);
+        String cgroupVer = getDetectedCgroupVersion(out);
+        if (cgroupVer != null ) {
+            if ("cgroupv1".equals(cgroupVer)) {
+                out.shouldMatch("CPU Shares is.*" + shares);
+            } else if ("cgroupsv2".equals(cgroupVer)) {
+                out.shouldMatch("Scaled CPU Shares value is:.*");
+            }
+        }
+        out.shouldMatch("active_processor_count.*" + expectedAPC);
+    }
+
+    private static String getDetectedCgroupVersion(OutputAnalyzer out) throws Exception {
+        Optional<String> cgroupVersString = out.asLines()
+                                                .stream()
+                                                .filter( l -> l.startsWith("Detected CGroups version is:") )
+                                                .findFirst();
+        if (cgroupVersString.isPresent()) { // only non-product builds have this
+            return cgroupVersString.get().split(": ")[1].trim();
+        } else {
+            return null;
     }
+    }
+
 }
< prev index next >