8229182: runtime/containers/docker/TestMemoryAwareness.java test fails on SLES12
authormbaesken
Tue, 03 Sep 2019 17:52:36 +0200
changeset 58001 0437b0f20312
parent 58000 62926eb5e40e
child 58002 01d31583f25c
8229182: runtime/containers/docker/TestMemoryAwareness.java test fails on SLES12 Reviewed-by: clanger, mseledtsov
test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java
test/lib/jdk/test/lib/containers/docker/DockerRunOptions.java
test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java
--- a/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java	Tue Sep 03 16:52:55 2019 +0200
+++ b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java	Tue Sep 03 17:52:36 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
 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;
 
 public class TestMemoryAwareness {
     private static final String imageName = Common.imageName("memory");
@@ -98,15 +98,26 @@
     private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
         Common.logNewTestCase("OOM");
 
+        // add "--memory-swappiness 0" so as to disable anonymous page swapping.
         DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
-            .addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit);
+            .addDockerOpts("--memory", dockerMemLimit, "--memory-swappiness", "0", "--memory-swap", dockerMemLimit);
         opts.classParams.add("" + sizeToAllocInMb);
 
-        DockerTestUtils.dockerRunJava(opts)
-            .shouldHaveExitValue(1)
-            .shouldContain("Entering AttemptOOM main")
-            .shouldNotContain("AttemptOOM allocation successful")
-            .shouldContain("java.lang.OutOfMemoryError");
+        // make sure we avoid inherited Xmx settings from the jtreg vmoptions
+        // set Xmx ourselves instead
+        System.out.println("sizeToAllocInMb is:" + sizeToAllocInMb + " sizeToAllocInMb/2 is:" + sizeToAllocInMb/2);
+        String javaHeapSize = sizeToAllocInMb/2 + "m";
+        opts.addJavaOptsAppended("-Xmx" + javaHeapSize);
+
+        OutputAnalyzer out = DockerTestUtils.dockerRunJava(opts);
+
+        if (out.getExitValue() == 0) {
+            throw new RuntimeException("We exited successfully, but we wanted to provoke an OOM inside the container");
+        }
+
+        out.shouldContain("Entering AttemptOOM main")
+           .shouldNotContain("AttemptOOM allocation successful")
+           .shouldContain("java.lang.OutOfMemoryError");
     }
 
 }
--- a/test/lib/jdk/test/lib/containers/docker/DockerRunOptions.java	Tue Sep 03 16:52:55 2019 +0200
+++ b/test/lib/jdk/test/lib/containers/docker/DockerRunOptions.java	Tue Sep 03 17:52:36 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -31,11 +31,13 @@
 // in test environment.
 public class DockerRunOptions {
     public String imageNameAndTag;
-    public ArrayList<String> dockerOpts = new ArrayList<String>();
+    public ArrayList<String> dockerOpts = new ArrayList<>();
     public String command;    // normally a full path to java
-    public ArrayList<String> javaOpts = new ArrayList<String>();
+    public ArrayList<String> javaOpts = new ArrayList<>();
+    // more java options, but to be set AFTER the test Java options
+    public ArrayList<String> javaOptsAppended = new ArrayList<>();
     public String classToRun;  // class or "-version"
-    public ArrayList<String> classParams = new ArrayList<String>();
+    public ArrayList<String> classParams = new ArrayList<>();
 
     public boolean tty = true;
     public boolean removeContainerAfterUse = true;
@@ -70,6 +72,11 @@
         return this;
     }
 
+    public DockerRunOptions addJavaOptsAppended(String... opts) {
+        Collections.addAll(javaOptsAppended, opts);
+        return this;
+    }
+
     public DockerRunOptions addClassOptions(String... opts) {
         Collections.addAll(classParams,opts);
         return this;
--- a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java	Tue Sep 03 16:52:55 2019 +0200
+++ b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java	Tue Sep 03 17:52:36 2019 +0200
@@ -40,12 +40,10 @@
 import jdk.test.lib.Container;
 import jdk.test.lib.Utils;
 import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
 import jtreg.SkippedException;
 
 
 public class DockerTestUtils {
-    private static final String FS = File.separator;
     private static boolean isDockerEngineAvailable = false;
     private static boolean wasDockerEngineChecked = false;
 
@@ -212,6 +210,7 @@
         if (opts.appendTestJavaOptions) {
             Collections.addAll(cmd, Utils.getTestJavaOpts());
         }
+        cmd.addAll(opts.javaOptsAppended);
 
         cmd.add(opts.classToRun);
         cmd.addAll(opts.classParams);