changeset 10891:48a018a40f07

8250984: Memory Docker tests fail on some Linux kernels w/o cgroupv1 swap limit capabilities Reviewed-by: bobv, sgehwolf, phh
author hseigel
date Fri, 25 Sep 2020 17:16:38 +0000
parents 21cf022ac550
children 6d9f5328694b
files test/runtime/containers/docker/TestMemoryAwareness.java
diffstat 1 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/test/runtime/containers/docker/TestMemoryAwareness.java	Fri Aug 30 11:11:33 2019 +0200
+++ b/test/runtime/containers/docker/TestMemoryAwareness.java	Fri Sep 25 17:16:38 2020 +0000
@@ -34,6 +34,7 @@
 import com.oracle.java.testlibrary.Common;
 import com.oracle.java.testlibrary.DockerRunOptions;
 import com.oracle.java.testlibrary.DockerTestUtils;
+import com.oracle.java.testlibrary.OutputAnalyzer;
 
 
 public class TestMemoryAwareness {
@@ -128,14 +129,26 @@
                 "--memory-swap", swapAllocation
             );
 
-        DockerTestUtils.dockerRunJava(opts)
-            .shouldHaveExitValue(0)
-            .shouldContain("Checking OperatingSystemMXBean")
-            .shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory)
-            .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+")
-            .shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap)
-            .shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+")
-            ;
+        OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
+            out.shouldHaveExitValue(0)
+               .shouldContain("Checking OperatingSystemMXBean")
+               .shouldContain("OperatingSystemMXBean.getTotalPhysicalMemorySize: " + expectedMemory)
+               .shouldMatch("OperatingSystemMXBean\\.getFreePhysicalMemorySize: [1-9][0-9]+");
+        // in case of warnings like : "Your kernel does not support swap limit capabilities
+        // or the cgroup is not mounted. Memory limited without swap."
+        // the getTotalSwapSpaceSize and getFreeSwapSpaceSize return the system
+        // values as the container setup isn't supported in that case.
+        try {
+            out.shouldContain("OperatingSystemMXBean.getTotalSwapSpaceSize: " + expectedSwap);
+        } catch(RuntimeException ex) {
+            out.shouldMatch("OperatingSystemMXBean.getTotalSwapSpaceSize: [0-9]+");
+        }
+
+        try {
+            out.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: [1-9][0-9]+");
+        } catch(RuntimeException ex) {
+            out.shouldMatch("OperatingSystemMXBean\\.getFreeSwapSpaceSize: 0");
+        }
     }
 
 }