< prev index next >

test/jdk/jdk/internal/platform/docker/TestDockerMemoryMetrics.java

Print this page
o  rev 57733 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv, mchung
~
o  rev 56862 : 8231111: Cgroups v2: Rework Metrics in java.base so as to recognize unified hierarchy
|  Reviewed-by: bobv
~

@@ -19,10 +19,11 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
+import jdk.internal.platform.Metrics;
 import jdk.test.lib.Utils;
 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.process.OutputAnalyzer;

@@ -56,24 +57,37 @@
             testMemoryLimit("1g");
 
             testMemoryAndSwapLimit("200m", "1g");
             testMemoryAndSwapLimit("100m", "200m");
 
+            Metrics m = Metrics.systemMetrics();
+            // kernel memory, '--kernel-memory' switch, and OOM killer,
+            // '--oom-kill-disable' switch, tests not supported by cgroupv2
+            // runtimes
+            if (m != null) {
+                if ("cgroupv1".equals(m.getProvider())) {
             testKernelMemoryLimit("100m");
             testKernelMemoryLimit("1g");
 
             testOomKillFlag("100m", false);
+                } else {
+                    System.out.println("kernel memory tests and OOM Kill flag tests not " +
+                                       "possible with cgroupv2.");
+                }
+            }
             testOomKillFlag("100m", true);
 
             testMemoryFailCount("64m");
 
             testMemorySoftLimit("500m","200m");
 
         } finally {
+            if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {
             DockerTestUtils.removeDockerImage(imageName);
         }
     }
+    }
 
     private static void testMemoryLimit(String value) throws Exception {
         Common.logNewTestCase("testMemoryLimit, value = " + value);
         DockerRunOptions opts =
                 new DockerRunOptions(imageName, "/jdk/bin/java", "MetricsMemoryTester");

@@ -145,11 +159,12 @@
             opts.addDockerOpts("--oom-kill-disable");
         }
         opts.addJavaOpts("-cp", "/test-classes/")
                 .addJavaOpts("--add-exports", "java.base/jdk.internal.platform=ALL-UNNAMED")
                 .addClassOptions("memory", value, oomKillFlag + "");
-        DockerTestUtils.dockerRunJava(opts).shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
+        OutputAnalyzer oa = DockerTestUtils.dockerRunJava(opts);
+        oa.shouldHaveExitValue(0).shouldContain("TEST PASSED!!!");
     }
 
     private static void testMemorySoftLimit(String mem, String softLimit) throws Exception {
         Common.logNewTestCase("testMemorySoftLimit, memory = " + mem + ", soft limit = " + softLimit);
         DockerRunOptions opts =
< prev index next >