8222299: [TESTBUG] move hotspot container tests to hotspot/containers
Summary: Moved the tests, updated relevant files
Reviewed-by: dholmes, iignatyev
--- a/doc/testing.html Fri Apr 12 09:55:30 2019 -0400
+++ b/doc/testing.html Fri Apr 12 12:26:29 2019 -0700
@@ -191,8 +191,8 @@
<h2 id="notes-for-specific-tests">Notes for Specific Tests</h2>
<h3 id="docker-tests">Docker Tests</h3>
<p>Docker tests with default parameters may fail on systems with glibc versions not compatible with the one used in the default docker image (e.g., Oracle Linux 7.6 for x86). For example, they pass on Ubuntu 16.04 but fail on Ubuntu 18.04 if run like this on x86:</p>
-<pre><code>$ make test TEST="jtreg:test/hotspot/jtreg/runtime/containers/docker"</code></pre>
+<pre><code>$ make test TEST="jtreg:test/hotspot/jtreg/containers/docker"</code></pre>
<p>To run these tests correctly, additional parameters for the correct docker image are required on Ubuntu 18.04 by using <code>JAVA_OPTIONS</code>.</p>
-<pre><code>$ make test TEST="jtreg:test/hotspot/jtreg/runtime/containers/docker" JTREG="JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest"</code></pre>
+<pre><code>$ make test TEST="jtreg:test/hotspot/jtreg/containers/docker" JTREG="JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest"</code></pre>
</body>
</html>
--- a/doc/testing.md Fri Apr 12 09:55:30 2019 -0400
+++ b/doc/testing.md Fri Apr 12 12:26:29 2019 -0700
@@ -381,12 +381,12 @@
compatible with the one used in the default docker image (e.g., Oracle Linux 7.6 for x86).
For example, they pass on Ubuntu 16.04 but fail on Ubuntu 18.04 if run like this on x86:
- $ make test TEST="jtreg:test/hotspot/jtreg/runtime/containers/docker"
+ $ make test TEST="jtreg:test/hotspot/jtreg/containers/docker"
To run these tests correctly, additional parameters for the correct docker image are
required on Ubuntu 18.04 by using `JAVA_OPTIONS`.
- $ make test TEST="jtreg:test/hotspot/jtreg/runtime/containers/docker" JTREG="JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest"
+ $ make test TEST="jtreg:test/hotspot/jtreg/containers/docker" JTREG="JAVA_OPTIONS=-Djdk.test.docker.image.name=ubuntu -Djdk.test.docker.image.version=latest"
---
# Override some definitions in the global css file that are not optimal for
--- a/test/hotspot/jtreg/ProblemList.txt Fri Apr 12 09:55:30 2019 -0400
+++ b/test/hotspot/jtreg/ProblemList.txt Fri Apr 12 12:26:29 2019 -0700
@@ -79,7 +79,7 @@
# :hotspot_runtime
runtime/SharedArchiveFile/SASymbolTableTest.java 8193639 solaris-all
-runtime/containers/docker/TestCPUSets.java 8220672 generic-all
+containers/docker/TestCPUSets.java 8220672 generic-all
runtime/jni/terminatedThread/TestTerminatedThread.java 8219652 aix-ppc64
#############################################################################
--- a/test/hotspot/jtreg/TEST.groups Fri Apr 12 09:55:30 2019 -0400
+++ b/test/hotspot/jtreg/TEST.groups Fri Apr 12 12:26:29 2019 -0700
@@ -43,6 +43,7 @@
gc \
-gc/nvdimm
+# By design this group should include ALL tests under runtime sub-directory
hotspot_runtime = \
runtime
@@ -65,6 +66,9 @@
hotspot_native_sanity = \
native_sanity
+hotspot_containers = \
+ containers
+
tier1_common = \
sanity/BasicVMTest.java \
gtest/GTestWrapper.java
@@ -296,7 +300,6 @@
-runtime/Thread/CancellableThreadTest.java \
-runtime/Thread/TestThreadDumpMonitorContention.java \
-runtime/Unsafe/RangeCheck.java \
- -runtime/containers/ \
sanity/ \
testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java \
-:tier1_runtime_appcds_exclude \
@@ -365,7 +368,6 @@
-runtime/CommandLine/OptionsValidation/TestOptionsWithRanges.java \
-runtime/CompressedOops/UseCompressedOops.java \
-runtime/Thread/TestThreadDumpMonitorContention.java \
- -runtime/containers/ \
-:tier1_runtime \
-:tier1_serviceability \
-:hotspot_tier2_runtime_platform_agnostic \
@@ -379,7 +381,6 @@
hotspot_tier3_runtime = \
runtime/ \
serviceability/ \
- -runtime/containers/ \
-:tier1_runtime \
-:tier1_serviceability \
-:hotspot_tier2_runtime_platform_agnostic \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/cgroup/PlainRead.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+/*
+ * @test PlainRead
+ * @requires os.family == "linux"
+ * @library /testlibrary /test/lib
+ * @build sun.hotspot.WhiteBox
+ * @run driver ClassFileInstaller sun.hotspot.WhiteBox
+ * sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PlainRead
+ */
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.Platform;
+import sun.hotspot.WhiteBox;
+
+public class PlainRead {
+
+ static public void match(OutputAnalyzer oa, String what, String value) {
+ oa.shouldMatch("^.*" + what + " *" + value + ".*$");
+ }
+
+ static public void noMatch(OutputAnalyzer oa, String what, String value) {
+ oa.shouldNotMatch("^.*" + what + " *" + value + ".*$");
+ }
+
+ static final String good_value = "(\\d+|-1|Unlimited)";
+ static final String bad_value = "(failed)";
+
+ static final String[] variables = {"Memory Limit is:", "CPU Shares is:", "CPU Quota is:", "CPU Period is:", "active_processor_count:"};
+
+ static public void isContainer(OutputAnalyzer oa) {
+ for (String v: variables) {
+ match(oa, v, good_value);
+ }
+ for (String v: variables) {
+ noMatch(oa, v, bad_value);
+ }
+ }
+
+ static public void isNotContainer(OutputAnalyzer oa) {
+ oa.shouldMatch("^.*Can't open /proc/self/mountinfo.*$");
+ }
+
+ public static void main(String[] args) throws Exception {
+ WhiteBox wb = WhiteBox.getWhiteBox();
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:os+container=trace", "-version");
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+ if (wb.isContainerized()) {
+ System.out.println("Inside a cgroup, testing...");
+ isContainer(output);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/AttemptOOM.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+public class AttemptOOM {
+ private static MyObj[] data;
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Entering AttemptOOM main");
+
+ // each MyObj will allocate 1024 byte array
+ int sizeInMb = Integer.parseInt(args[0]);
+ data = new MyObj[sizeInMb*1024];
+
+ System.out.println("data.length = " + data.length);
+
+ for (int i=0; i < data.length; i++) {
+ data[i] = new MyObj(1024);
+ }
+
+ System.out.println("AttemptOOM allocation successful");
+ }
+
+ private static class MyObj {
+ private byte[] myData;
+ MyObj(int size) {
+ myData = new byte[size];
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/CheckContainerized.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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 sun.hotspot.WhiteBox;
+
+public class CheckContainerized {
+ public static String OUTSIDE_OF_CONTAINER =
+ "CheckContainerized: Running outside of a container";
+ public static String INSIDE_A_CONTAINER =
+ "CheckContainerized: Running inside a container";
+
+ public static void main(String[] args) {
+ System.out.println("CheckContainerized: Entering");
+ WhiteBox wb = WhiteBox.getWhiteBox();
+
+ if (wb.isContainerized()) {
+ System.out.println(INSIDE_A_CONTAINER);
+
+ } else {
+ System.out.println(OUTSIDE_OF_CONTAINER);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/DockerBasicTest.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,84 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Basic (sanity) test for JDK-under-test inside a docker image.
+ * @requires docker.support
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @build HelloDocker
+ * @run driver DockerBasicTest
+ */
+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.Platform;
+import jdk.test.lib.Utils;
+
+
+public class DockerBasicTest {
+ private static final String imageNameAndTag = Common.imageName("basic");
+
+ public static void main(String[] args) throws Exception {
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ testJavaVersion();
+ testHelloDocker();
+ } finally {
+ if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {
+ DockerTestUtils.removeDockerImage(imageNameAndTag);
+ }
+ }
+ }
+
+
+ private static void testJavaVersion() throws Exception {
+ DockerRunOptions opts =
+ new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "-version");
+
+ DockerTestUtils.dockerRunJava(opts)
+ .shouldHaveExitValue(0)
+ .shouldContain(Platform.vmName);
+ }
+
+
+ private static void testHelloDocker() throws Exception {
+ DockerRunOptions opts =
+ new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "HelloDocker")
+ .addJavaOpts("-cp", "/test-classes/")
+ .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
+
+ DockerTestUtils.dockerRunJava(opts)
+ .shouldHaveExitValue(0)
+ .shouldContain("Hello Docker");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/HelloDocker.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+public class HelloDocker {
+ public static void main(String args[]) {
+ System.out.println("Hello Docker");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/JfrReporter.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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 java.nio.file.Paths;
+import jdk.jfr.Recording;
+import jdk.jfr.consumer.RecordedEvent;
+import jdk.jfr.consumer.RecordingFile;
+
+
+// This class is intended to run inside a container
+public class JfrReporter {
+ public static final String TEST_REPORTED_CORES="TEST_REPORTED_CORES";
+ public static final String TEST_REPORTED_MEMORY="TEST_REPORTED_MEMORY";
+ public static final String TEST_REPORTED_PID="TEST_REPORTED_PID";
+ public static final String TESTCASE_CPU="cpu";
+ public static final String TESTCASE_MEMORY="memory";
+ public static final String TESTCASE_PROCESS="process";
+
+ public static void main(String[] args) throws Exception {
+ String testCase = args[0];
+ System.out.println("Testcase: " + testCase);
+ switch (testCase) {
+ case TESTCASE_CPU:
+ RecordedEvent event = testEvent("jdk.CPUInformation", "cpu.jfr");
+ System.out.println(TEST_REPORTED_CORES + "=" + event.getInt("cores"));
+ break;
+ case TESTCASE_MEMORY:
+ event = testEvent("jdk.PhysicalMemory", "memory.jfr");
+ System.out.println(TEST_REPORTED_MEMORY + "=" + event.getLong("totalSize"));
+ break;
+ case TESTCASE_PROCESS:
+ event = testEvent("jdk.SystemProcess", "process.jfr");
+ System.out.println(TEST_REPORTED_PID + "=" + event.getString("pid"));
+ break;
+ default:
+ throw new IllegalArgumentException("Invalid test case");
+ }
+ }
+
+ private static RecordedEvent testEvent(String event, String recordingPath) throws Exception {
+ System.out.println("========= Testing event: " + event);
+ Recording r = new Recording();
+ r.enable(event);
+ r.setDestination(Paths.get("tmp", recordingPath));
+ r.start();
+ r.stop();
+
+ RecordedEvent recordedEvent = RecordingFile.readAllEvents(r.getDestination()).get(0);
+ System.out.println("RecordedEvent: " + recordedEvent);
+ return recordedEvent;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/PrintContainerInfo.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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 sun.hotspot.WhiteBox;
+
+public class PrintContainerInfo {
+
+ public static void main(String[] args) {
+ System.out.println("PrintContainerInfo: Entering");
+ WhiteBox wb = WhiteBox.getWhiteBox();
+
+ wb.printOsInfo();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TEST.properties Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,1 @@
+exclusiveAccess.dirs=.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TestCPUAwareness.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,209 @@
+/*
+ * 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Test JVM's CPU resource awareness when running inside docker container
+ * @requires docker.support
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @run driver TestCPUAwareness
+ */
+import java.util.List;
+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;
+
+public class TestCPUAwareness {
+ private static final String imageName = Common.imageName("cpu");
+ private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
+
+ public static void main(String[] args) throws Exception {
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
+ DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ // cpuset, period, shares, expected Active Processor Count
+ testComboWithCpuSets();
+
+ // cpu shares - it should be safe to use CPU shares exceeding available CPUs
+ testCpuShares(256, 1);
+ testCpuShares(2048, 2);
+ testCpuShares(4096, 4);
+
+ // leave one CPU for system and tools, otherwise this test may be unstable
+ int maxNrOfAvailableCpus = availableCPUs - 1;
+ for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) {
+ testCpus(i, i);
+ }
+
+ // If ActiveProcessorCount is set, the VM should use it, regardless of other
+ // container settings, host settings or available CPUs on the host.
+ testActiveProcessorCount(1, 1);
+ testActiveProcessorCount(2, 2);
+
+ // cpu quota and period
+ testCpuQuotaAndPeriod(50*1000, 100*1000);
+ testCpuQuotaAndPeriod(100*1000, 100*1000);
+ testCpuQuotaAndPeriod(150*1000, 100*1000);
+ testCpuQuotaAndPeriod(400*1000, 100*1000);
+
+ } finally {
+ DockerTestUtils.removeDockerImage(imageName);
+ }
+ }
+
+
+ private static void testComboWithCpuSets() throws Exception {
+ String cpuSetStr = CPUSetsReader.readFromProcStatus("Cpus_allowed_list");
+ System.out.println("cpuSetStr = " + cpuSetStr);
+
+ if (cpuSetStr == null) {
+ System.out.printf("The cpuset test cases are skipped");
+ } else {
+ List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
+
+ // Test subset of cpuset with one element
+ if (cpuSet.size() >= 1) {
+ String testCpuSet = CPUSetsReader.listToString(cpuSet, 1);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 1);
+ }
+
+ // Test subset of cpuset with two elements
+ if (cpuSet.size() >= 2) {
+ String testCpuSet = CPUSetsReader.listToString(cpuSet, 2);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 2);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, true, 2);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, false, 1);
+ }
+
+ // Test subset of cpuset with three elements
+ if (cpuSet.size() >= 3) {
+ String testCpuSet = CPUSetsReader.listToString(cpuSet, 3);
+ testAPCCombo(testCpuSet, 100*1000, 100*1000, 2*1024, true, 1);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, true, 2);
+ testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, false, 1);
+ }
+ }
+ }
+
+
+ private static void testActiveProcessorCount(int valueToSet, int expectedValue) throws Exception {
+ Common.logNewTestCase("Test ActiveProcessorCount: valueToSet = " + valueToSet);
+
+ DockerRunOptions opts = Common.newOpts(imageName)
+ .addJavaOpts("-XX:ActiveProcessorCount=" + valueToSet, "-Xlog:os=trace");
+ Common.run(opts)
+ .shouldMatch("active processor count set by user.*" + expectedValue);
+ }
+
+
+ private static void testCpus(int valueToSet, int expectedTraceValue) throws Exception {
+ Common.logNewTestCase("test cpus: " + valueToSet);
+ DockerRunOptions opts = Common.newOpts(imageName)
+ .addDockerOpts("--cpu-period=" + 10000)
+ .addDockerOpts("--cpu-quota=" + valueToSet * 10000);
+ Common.run(opts)
+ .shouldMatch("active_processor_count.*" + expectedTraceValue);
+ }
+
+
+ // Expected active processor count can not exceed available CPU count
+ private static int adjustExpectedAPCForAvailableCPUs(int expectedAPC) {
+ if (expectedAPC > availableCPUs) {
+ expectedAPC = availableCPUs;
+ System.out.println("Adjusted expectedAPC = " + expectedAPC);
+ }
+ return expectedAPC;
+ }
+
+
+ private static void testCpuQuotaAndPeriod(int quota, int period)
+ throws Exception {
+ Common.logNewTestCase("test cpu quota and period: ");
+ System.out.println("quota = " + quota);
+ System.out.println("period = " + period);
+
+ int expectedAPC = (int) Math.ceil((float) quota / (float) period);
+ System.out.println("expectedAPC = " + expectedAPC);
+ expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
+
+ DockerRunOptions opts = Common.newOpts(imageName)
+ .addDockerOpts("--cpu-period=" + period)
+ .addDockerOpts("--cpu-quota=" + quota);
+
+ Common.run(opts)
+ .shouldMatch("CPU Period is.*" + period)
+ .shouldMatch("CPU Quota is.*" + quota)
+ .shouldMatch("active_processor_count.*" + expectedAPC);
+ }
+
+
+ // Test correctess of automatically selected active processor cound
+ private static void testAPCCombo(String cpuset, int quota, int period, int shares,
+ boolean usePreferContainerQuotaForCPUCount,
+ int expectedAPC) throws Exception {
+ Common.logNewTestCase("test APC Combo");
+ System.out.println("cpuset = " + cpuset);
+ System.out.println("quota = " + quota);
+ System.out.println("period = " + period);
+ System.out.println("shares = " + shares);
+ System.out.println("usePreferContainerQuotaForCPUCount = " + usePreferContainerQuotaForCPUCount);
+ System.out.println("expectedAPC = " + expectedAPC);
+
+ expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
+
+ DockerRunOptions opts = Common.newOpts(imageName)
+ .addDockerOpts("--cpuset-cpus", "" + cpuset)
+ .addDockerOpts("--cpu-period=" + period)
+ .addDockerOpts("--cpu-quota=" + quota)
+ .addDockerOpts("--cpu-shares=" + shares);
+
+ if (!usePreferContainerQuotaForCPUCount) opts.addJavaOpts("-XX:-PreferContainerQuotaForCPUCount");
+
+ Common.run(opts)
+ .shouldMatch("active_processor_count.*" + expectedAPC);
+ }
+
+
+ private static void testCpuShares(int shares, int expectedAPC) throws Exception {
+ Common.logNewTestCase("test cpu shares, shares = " + shares);
+ System.out.println("expectedAPC = " + expectedAPC);
+
+ 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);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TestCPUSets.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2017, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Test JVM's awareness of cpu sets (cpus and mems)
+ * @requires docker.support
+ * @requires (os.arch != "s390x")
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo
+ * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver TestCPUSets
+ */
+import java.util.List;
+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.Asserts;
+import jdk.test.lib.Platform;
+import jdk.test.lib.Utils;
+import jdk.test.lib.process.OutputAnalyzer;
+
+
+public class TestCPUSets {
+ private static final String imageName = Common.imageName("cpusets");
+
+ public static void main(String[] args) throws Exception {
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ Common.prepareWhiteBox();
+ DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ // Sanity test the cpu sets reader and parser
+ CPUSetsReader.test();
+ testTheSet("Cpus_allowed_list");
+ testTheSet("Mems_allowed_list");
+ } finally {
+ DockerTestUtils.removeDockerImage(imageName);
+ }
+ }
+
+
+ private static void testTheSet(String setType) throws Exception {
+ String cpuSetStr = CPUSetsReader.readFromProcStatus(setType);
+
+ if (cpuSetStr == null) {
+ System.out.printf("The %s test is skipped %n", setType);
+ } else {
+ List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
+
+ // Test subset of one, full subset, and half of the subset
+ testCpuSet(CPUSetsReader.listToString(cpuSet, 1));
+ if (cpuSet.size() > 1) {
+ testCpuSet(CPUSetsReader.listToString(cpuSet));
+ }
+ if (cpuSet.size() > 2) {
+ testCpuSet(CPUSetsReader.listToString(cpuSet, cpuSet.size()/2 ));
+ }
+ }
+ }
+
+
+ private static DockerRunOptions commonOpts() {
+ DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",
+ "PrintContainerInfo");
+ opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
+ opts.addJavaOpts("-Xlog:os+container=trace", "-cp", "/test-classes/");
+ Common.addWhiteBoxOpts(opts);
+ return opts;
+ }
+
+
+ private static void checkResult(List<String> lines, String lineMarker, String value) {
+ boolean lineMarkerFound = false;
+
+ for (String line : lines) {
+ if (line.contains(lineMarker)) {
+ lineMarkerFound = true;
+ String[] parts = line.split(":");
+ System.out.println("DEBUG: line = " + line);
+ System.out.println("DEBUG: parts.length = " + parts.length);
+
+ Asserts.assertEquals(parts.length, 2);
+ String set = parts[1].replaceAll("\\s","");
+ String actual = CPUSetsReader.listToString(CPUSetsReader.parseCpuSet(set));
+ Asserts.assertEquals(actual, value);
+ break;
+ }
+ }
+ Asserts.assertTrue(lineMarkerFound);
+ }
+
+
+ private static void testCpuSet(String value) throws Exception {
+ Common.logNewTestCase("cpusets.cpus, value = " + value);
+
+ DockerRunOptions opts = commonOpts();
+ opts.addDockerOpts("--cpuset-cpus=" + value);
+
+ List<String> lines = Common.run(opts).asLines();
+ checkResult(lines, "cpuset.cpus is:", value);
+ }
+
+ private static void testMemSet(String value) throws Exception {
+ Common.logNewTestCase("cpusets.mems, value = " + value);
+
+ DockerRunOptions opts = commonOpts();
+ opts.addDockerOpts("--cpuset-mems=" + value);
+
+ List<String> lines = Common.run(opts).asLines();
+ checkResult(lines, "cpuset.mems is:", value);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TestJFREvents.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Ensure that certain JFR events return correct results for resource values
+ * when run inside Docker container, such as available CPU and memory.
+ * Also make sure that PIDs are based on value provided by container,
+ * not by the host system.
+ * @requires (docker.support & os.maxMemory >= 2g)
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @build JfrReporter
+ * @run driver TestJFREvents
+ */
+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.Utils;
+
+
+public class TestJFREvents {
+ private static final String imageName = Common.imageName("jfr-events");
+ private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ // leave one CPU for system and tools, otherwise this test may be unstable
+ int maxNrOfAvailableCpus = availableCPUs - 1;
+ for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) {
+ testCPUInfo(i, i);
+ }
+
+ long MB = 1024*1024;
+ testMemory("200m", "" + 200*MB);
+ testMemory("500m", "" + 500*MB);
+ testMemory("1g", "" + 1024*MB);
+
+ testProcessInfo();
+
+ } finally {
+ DockerTestUtils.removeDockerImage(imageName);
+ }
+ }
+
+
+ private static void testCPUInfo(int valueToSet, int expectedValue) throws Exception {
+ Common.logNewTestCase("CPUInfo: --cpus = " + valueToSet);
+ DockerTestUtils.dockerRunJava(
+ commonDockerOpts()
+ .addDockerOpts("--cpus=" + valueToSet)
+ .addClassOptions(JfrReporter.TESTCASE_CPU))
+ .shouldHaveExitValue(0)
+ .shouldContain(JfrReporter.TEST_REPORTED_CORES);
+
+ // The following assertion is currently disabled due to JFR reporting incorrect values.
+ // JFR reports values for the host system as opposed to values for the container.
+ // @ignore 8219999
+ // .shouldContain(JfrReporter.TEST_REPORTED_CORES + "=" + expectedValue);
+ }
+
+
+ private static void testMemory(String valueToSet, String expectedValue) throws Exception {
+ Common.logNewTestCase("Memory: --memory = " + valueToSet);
+ DockerTestUtils.dockerRunJava(
+ commonDockerOpts()
+ .addDockerOpts("--memory=" + valueToSet)
+ .addClassOptions(JfrReporter.TESTCASE_MEMORY))
+ .shouldHaveExitValue(0)
+ .shouldContain(JfrReporter.TEST_REPORTED_MEMORY + "=" + expectedValue);
+ }
+
+
+ private static void testProcessInfo() throws Exception {
+ Common.logNewTestCase("ProcessInfo");
+ DockerTestUtils.dockerRunJava(
+ commonDockerOpts()
+ .addClassOptions(JfrReporter.TESTCASE_PROCESS))
+ .shouldHaveExitValue(0)
+ .shouldContain(JfrReporter.TEST_REPORTED_PID + "=1");
+
+ }
+
+
+ private static DockerRunOptions commonDockerOpts() {
+ return new DockerRunOptions(imageName, "/jdk/bin/java", "JfrReporter")
+ .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
+ .addJavaOpts("-cp", "/test-classes/");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TestMemoryAwareness.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Test JVM's memory resource awareness when running inside docker container
+ * @requires docker.support
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo
+ * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver TestMemoryAwareness
+ */
+import jdk.test.lib.containers.docker.Common;
+import jdk.test.lib.containers.docker.DockerRunOptions;
+import jdk.test.lib.containers.docker.DockerTestUtils;
+
+
+public class TestMemoryAwareness {
+ private static final String imageName = Common.imageName("memory");
+
+ public static void main(String[] args) throws Exception {
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ Common.prepareWhiteBox();
+ DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ testMemoryLimit("100m", "104857600");
+ testMemoryLimit("500m", "524288000");
+ testMemoryLimit("1g", "1073741824");
+ testMemoryLimit("4g", "4294967296");
+
+ testMemorySoftLimit("500m", "524288000");
+ testMemorySoftLimit("1g", "1073741824");
+
+ // Add extra 10 Mb to allocator limit, to be sure to cause OOM
+ testOOM("256m", 256 + 10);
+
+ } finally {
+ DockerTestUtils.removeDockerImage(imageName);
+ }
+ }
+
+
+ private static void testMemoryLimit(String valueToSet, String expectedTraceValue)
+ throws Exception {
+
+ Common.logNewTestCase("memory limit: " + valueToSet);
+
+ DockerRunOptions opts = Common.newOpts(imageName)
+ .addDockerOpts("--memory", valueToSet);
+
+ Common.run(opts)
+ .shouldMatch("Memory Limit is:.*" + expectedTraceValue);
+ }
+
+
+ private static void testMemorySoftLimit(String valueToSet, String expectedTraceValue)
+ throws Exception {
+ Common.logNewTestCase("memory soft limit: " + valueToSet);
+
+ DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
+ Common.addWhiteBoxOpts(opts);
+ opts.addDockerOpts("--memory-reservation=" + valueToSet);
+
+ Common.run(opts)
+ .shouldMatch("Memory Soft Limit.*" + expectedTraceValue);
+ }
+
+
+ // provoke OOM inside the container, see how VM reacts
+ private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
+ Common.logNewTestCase("OOM");
+
+ DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
+ .addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit);
+ opts.classParams.add("" + sizeToAllocInMb);
+
+ DockerTestUtils.dockerRunJava(opts)
+ .shouldHaveExitValue(1)
+ .shouldContain("Entering AttemptOOM main")
+ .shouldNotContain("AttemptOOM allocation successful")
+ .shouldContain("java.lang.OutOfMemoryError");
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/containers/docker/TestMisc.java Fri Apr 12 12:26:29 2019 -0700
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2017, 2018, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * 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.
+ */
+
+
+/*
+ * @test
+ * @summary Test miscellanous functionality related to JVM running in docker container
+ * @requires docker.support
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ * java.management
+ * jdk.jartool/sun.tools.jar
+ * @build CheckContainerized sun.hotspot.WhiteBox PrintContainerInfo
+ * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
+ * @run driver TestMisc
+ */
+import jdk.test.lib.containers.docker.Common;
+import jdk.test.lib.containers.docker.DockerTestUtils;
+import jdk.test.lib.containers.docker.DockerRunOptions;
+import jdk.test.lib.process.OutputAnalyzer;
+import jdk.test.lib.process.ProcessTools;
+
+
+public class TestMisc {
+ private static final String imageName = Common.imageName("misc");
+
+ public static void main(String[] args) throws Exception {
+ if (!DockerTestUtils.canTestDocker()) {
+ return;
+ }
+
+ Common.prepareWhiteBox();
+ DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
+
+ try {
+ testMinusContainerSupport();
+ testIsContainerized();
+ testPrintContainerInfo();
+ } finally {
+ DockerTestUtils.removeDockerImage(imageName);
+ }
+ }
+
+
+ private static void testMinusContainerSupport() throws Exception {
+ Common.logNewTestCase("Test related flags: '-UseContainerSupport'");
+ DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "-version");
+ opts.addJavaOpts("-XX:-UseContainerSupport", "-Xlog:os+container=trace");
+
+ Common.run(opts)
+ .shouldContain("Container Support not enabled");
+ }
+
+
+ private static void testIsContainerized() throws Exception {
+ Common.logNewTestCase("Test is_containerized() inside a docker container");
+
+ DockerRunOptions opts = Common.newOpts(imageName, "CheckContainerized");
+ Common.addWhiteBoxOpts(opts);
+
+ Common.run(opts)
+ .shouldContain(CheckContainerized.INSIDE_A_CONTAINER);
+ }
+
+
+ private static void testPrintContainerInfo() throws Exception {
+ Common.logNewTestCase("Test print_container_info()");
+
+ DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
+ Common.addWhiteBoxOpts(opts);
+
+ checkContainerInfo(Common.run(opts));
+ }
+
+
+ private static void checkContainerInfo(OutputAnalyzer out) throws Exception {
+ String[] expectedToContain = new String[] {
+ "cpuset.cpus",
+ "cpuset.mems",
+ "CPU Shares",
+ "CPU Quota",
+ "CPU Period",
+ "OSContainer::active_processor_count",
+ "Memory Limit",
+ "Memory Soft Limit",
+ "Memory Usage",
+ "Maximum Memory Usage",
+ "memory_max_usage_in_bytes"
+ };
+
+ for (String s : expectedToContain) {
+ out.shouldContain(s);
+ }
+ }
+
+}
--- a/test/hotspot/jtreg/runtime/containers/cgroup/PlainRead.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-/*
- * Copyright (c) 2017, 2018, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-/*
- * @test PlainRead
- * @requires os.family == "linux"
- * @library /testlibrary /test/lib
- * @build sun.hotspot.WhiteBox
- * @run driver ClassFileInstaller sun.hotspot.WhiteBox
- * sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI PlainRead
- */
-
-import jdk.test.lib.process.ProcessTools;
-import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.Platform;
-import sun.hotspot.WhiteBox;
-
-public class PlainRead {
-
- static public void match(OutputAnalyzer oa, String what, String value) {
- oa.shouldMatch("^.*" + what + " *" + value + ".*$");
- }
-
- static public void noMatch(OutputAnalyzer oa, String what, String value) {
- oa.shouldNotMatch("^.*" + what + " *" + value + ".*$");
- }
-
- static final String good_value = "(\\d+|-1|Unlimited)";
- static final String bad_value = "(failed)";
-
- static final String[] variables = {"Memory Limit is:", "CPU Shares is:", "CPU Quota is:", "CPU Period is:", "active_processor_count:"};
-
- static public void isContainer(OutputAnalyzer oa) {
- for (String v: variables) {
- match(oa, v, good_value);
- }
- for (String v: variables) {
- noMatch(oa, v, bad_value);
- }
- }
-
- static public void isNotContainer(OutputAnalyzer oa) {
- oa.shouldMatch("^.*Can't open /proc/self/mountinfo.*$");
- }
-
- public static void main(String[] args) throws Exception {
- WhiteBox wb = WhiteBox.getWhiteBox();
- ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:os+container=trace", "-version");
- OutputAnalyzer output = new OutputAnalyzer(pb.start());
-
- if (wb.isContainerized()) {
- System.out.println("Inside a cgroup, testing...");
- isContainer(output);
- }
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/AttemptOOM.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-public class AttemptOOM {
- private static MyObj[] data;
-
- public static void main(String[] args) throws Exception {
- System.out.println("Entering AttemptOOM main");
-
- // each MyObj will allocate 1024 byte array
- int sizeInMb = Integer.parseInt(args[0]);
- data = new MyObj[sizeInMb*1024];
-
- System.out.println("data.length = " + data.length);
-
- for (int i=0; i < data.length; i++) {
- data[i] = new MyObj(1024);
- }
-
- System.out.println("AttemptOOM allocation successful");
- }
-
- private static class MyObj {
- private byte[] myData;
- MyObj(int size) {
- myData = new byte[size];
- }
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/CheckContainerized.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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 sun.hotspot.WhiteBox;
-
-public class CheckContainerized {
- public static String OUTSIDE_OF_CONTAINER =
- "CheckContainerized: Running outside of a container";
- public static String INSIDE_A_CONTAINER =
- "CheckContainerized: Running inside a container";
-
- public static void main(String[] args) {
- System.out.println("CheckContainerized: Entering");
- WhiteBox wb = WhiteBox.getWhiteBox();
-
- if (wb.isContainerized()) {
- System.out.println(INSIDE_A_CONTAINER);
-
- } else {
- System.out.println(OUTSIDE_OF_CONTAINER);
- }
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/DockerBasicTest.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Basic (sanity) test for JDK-under-test inside a docker image.
- * @requires docker.support
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @build HelloDocker
- * @run driver DockerBasicTest
- */
-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.Platform;
-import jdk.test.lib.Utils;
-
-
-public class DockerBasicTest {
- private static final String imageNameAndTag = Common.imageName("basic");
-
- public static void main(String[] args) throws Exception {
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- DockerTestUtils.buildJdkDockerImage(imageNameAndTag, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- testJavaVersion();
- testHelloDocker();
- } finally {
- if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {
- DockerTestUtils.removeDockerImage(imageNameAndTag);
- }
- }
- }
-
-
- private static void testJavaVersion() throws Exception {
- DockerRunOptions opts =
- new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "-version");
-
- DockerTestUtils.dockerRunJava(opts)
- .shouldHaveExitValue(0)
- .shouldContain(Platform.vmName);
- }
-
-
- private static void testHelloDocker() throws Exception {
- DockerRunOptions opts =
- new DockerRunOptions(imageNameAndTag, "/jdk/bin/java", "HelloDocker")
- .addJavaOpts("-cp", "/test-classes/")
- .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
-
- DockerTestUtils.dockerRunJava(opts)
- .shouldHaveExitValue(0)
- .shouldContain("Hello Docker");
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/HelloDocker.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-public class HelloDocker {
- public static void main(String args[]) {
- System.out.println("Hello Docker");
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/JfrReporter.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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 java.nio.file.Paths;
-import jdk.jfr.Recording;
-import jdk.jfr.consumer.RecordedEvent;
-import jdk.jfr.consumer.RecordingFile;
-
-
-// This class is intended to run inside a container
-public class JfrReporter {
- public static final String TEST_REPORTED_CORES="TEST_REPORTED_CORES";
- public static final String TEST_REPORTED_MEMORY="TEST_REPORTED_MEMORY";
- public static final String TEST_REPORTED_PID="TEST_REPORTED_PID";
- public static final String TESTCASE_CPU="cpu";
- public static final String TESTCASE_MEMORY="memory";
- public static final String TESTCASE_PROCESS="process";
-
- public static void main(String[] args) throws Exception {
- String testCase = args[0];
- System.out.println("Testcase: " + testCase);
- switch (testCase) {
- case TESTCASE_CPU:
- RecordedEvent event = testEvent("jdk.CPUInformation", "cpu.jfr");
- System.out.println(TEST_REPORTED_CORES + "=" + event.getInt("cores"));
- break;
- case TESTCASE_MEMORY:
- event = testEvent("jdk.PhysicalMemory", "memory.jfr");
- System.out.println(TEST_REPORTED_MEMORY + "=" + event.getLong("totalSize"));
- break;
- case TESTCASE_PROCESS:
- event = testEvent("jdk.SystemProcess", "process.jfr");
- System.out.println(TEST_REPORTED_PID + "=" + event.getString("pid"));
- break;
- default:
- throw new IllegalArgumentException("Invalid test case");
- }
- }
-
- private static RecordedEvent testEvent(String event, String recordingPath) throws Exception {
- System.out.println("========= Testing event: " + event);
- Recording r = new Recording();
- r.enable(event);
- r.setDestination(Paths.get("tmp", recordingPath));
- r.start();
- r.stop();
-
- RecordedEvent recordedEvent = RecordingFile.readAllEvents(r.getDestination()).get(0);
- System.out.println("RecordedEvent: " + recordedEvent);
- return recordedEvent;
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/PrintContainerInfo.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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 sun.hotspot.WhiteBox;
-
-public class PrintContainerInfo {
-
- public static void main(String[] args) {
- System.out.println("PrintContainerInfo: Entering");
- WhiteBox wb = WhiteBox.getWhiteBox();
-
- wb.printOsInfo();
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/TEST.properties Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-exclusiveAccess.dirs=.
--- a/test/hotspot/jtreg/runtime/containers/docker/TestCPUAwareness.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,209 +0,0 @@
-/*
- * 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Test JVM's CPU resource awareness when running inside docker container
- * @requires docker.support
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @run driver TestCPUAwareness
- */
-import java.util.List;
-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;
-
-public class TestCPUAwareness {
- private static final String imageName = Common.imageName("cpu");
- private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
-
- public static void main(String[] args) throws Exception {
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
- DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- // cpuset, period, shares, expected Active Processor Count
- testComboWithCpuSets();
-
- // cpu shares - it should be safe to use CPU shares exceeding available CPUs
- testCpuShares(256, 1);
- testCpuShares(2048, 2);
- testCpuShares(4096, 4);
-
- // leave one CPU for system and tools, otherwise this test may be unstable
- int maxNrOfAvailableCpus = availableCPUs - 1;
- for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) {
- testCpus(i, i);
- }
-
- // If ActiveProcessorCount is set, the VM should use it, regardless of other
- // container settings, host settings or available CPUs on the host.
- testActiveProcessorCount(1, 1);
- testActiveProcessorCount(2, 2);
-
- // cpu quota and period
- testCpuQuotaAndPeriod(50*1000, 100*1000);
- testCpuQuotaAndPeriod(100*1000, 100*1000);
- testCpuQuotaAndPeriod(150*1000, 100*1000);
- testCpuQuotaAndPeriod(400*1000, 100*1000);
-
- } finally {
- DockerTestUtils.removeDockerImage(imageName);
- }
- }
-
-
- private static void testComboWithCpuSets() throws Exception {
- String cpuSetStr = CPUSetsReader.readFromProcStatus("Cpus_allowed_list");
- System.out.println("cpuSetStr = " + cpuSetStr);
-
- if (cpuSetStr == null) {
- System.out.printf("The cpuset test cases are skipped");
- } else {
- List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
-
- // Test subset of cpuset with one element
- if (cpuSet.size() >= 1) {
- String testCpuSet = CPUSetsReader.listToString(cpuSet, 1);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 1);
- }
-
- // Test subset of cpuset with two elements
- if (cpuSet.size() >= 2) {
- String testCpuSet = CPUSetsReader.listToString(cpuSet, 2);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 4*1024, true, 2);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, true, 2);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, false, 1);
- }
-
- // Test subset of cpuset with three elements
- if (cpuSet.size() >= 3) {
- String testCpuSet = CPUSetsReader.listToString(cpuSet, 3);
- testAPCCombo(testCpuSet, 100*1000, 100*1000, 2*1024, true, 1);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, true, 2);
- testAPCCombo(testCpuSet, 200*1000, 100*1000, 1023, false, 1);
- }
- }
- }
-
-
- private static void testActiveProcessorCount(int valueToSet, int expectedValue) throws Exception {
- Common.logNewTestCase("Test ActiveProcessorCount: valueToSet = " + valueToSet);
-
- DockerRunOptions opts = Common.newOpts(imageName)
- .addJavaOpts("-XX:ActiveProcessorCount=" + valueToSet, "-Xlog:os=trace");
- Common.run(opts)
- .shouldMatch("active processor count set by user.*" + expectedValue);
- }
-
-
- private static void testCpus(int valueToSet, int expectedTraceValue) throws Exception {
- Common.logNewTestCase("test cpus: " + valueToSet);
- DockerRunOptions opts = Common.newOpts(imageName)
- .addDockerOpts("--cpu-period=" + 10000)
- .addDockerOpts("--cpu-quota=" + valueToSet * 10000);
- Common.run(opts)
- .shouldMatch("active_processor_count.*" + expectedTraceValue);
- }
-
-
- // Expected active processor count can not exceed available CPU count
- private static int adjustExpectedAPCForAvailableCPUs(int expectedAPC) {
- if (expectedAPC > availableCPUs) {
- expectedAPC = availableCPUs;
- System.out.println("Adjusted expectedAPC = " + expectedAPC);
- }
- return expectedAPC;
- }
-
-
- private static void testCpuQuotaAndPeriod(int quota, int period)
- throws Exception {
- Common.logNewTestCase("test cpu quota and period: ");
- System.out.println("quota = " + quota);
- System.out.println("period = " + period);
-
- int expectedAPC = (int) Math.ceil((float) quota / (float) period);
- System.out.println("expectedAPC = " + expectedAPC);
- expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
-
- DockerRunOptions opts = Common.newOpts(imageName)
- .addDockerOpts("--cpu-period=" + period)
- .addDockerOpts("--cpu-quota=" + quota);
-
- Common.run(opts)
- .shouldMatch("CPU Period is.*" + period)
- .shouldMatch("CPU Quota is.*" + quota)
- .shouldMatch("active_processor_count.*" + expectedAPC);
- }
-
-
- // Test correctess of automatically selected active processor cound
- private static void testAPCCombo(String cpuset, int quota, int period, int shares,
- boolean usePreferContainerQuotaForCPUCount,
- int expectedAPC) throws Exception {
- Common.logNewTestCase("test APC Combo");
- System.out.println("cpuset = " + cpuset);
- System.out.println("quota = " + quota);
- System.out.println("period = " + period);
- System.out.println("shares = " + shares);
- System.out.println("usePreferContainerQuotaForCPUCount = " + usePreferContainerQuotaForCPUCount);
- System.out.println("expectedAPC = " + expectedAPC);
-
- expectedAPC = adjustExpectedAPCForAvailableCPUs(expectedAPC);
-
- DockerRunOptions opts = Common.newOpts(imageName)
- .addDockerOpts("--cpuset-cpus", "" + cpuset)
- .addDockerOpts("--cpu-period=" + period)
- .addDockerOpts("--cpu-quota=" + quota)
- .addDockerOpts("--cpu-shares=" + shares);
-
- if (!usePreferContainerQuotaForCPUCount) opts.addJavaOpts("-XX:-PreferContainerQuotaForCPUCount");
-
- Common.run(opts)
- .shouldMatch("active_processor_count.*" + expectedAPC);
- }
-
-
- private static void testCpuShares(int shares, int expectedAPC) throws Exception {
- Common.logNewTestCase("test cpu shares, shares = " + shares);
- System.out.println("expectedAPC = " + expectedAPC);
-
- 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);
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/TestCPUSets.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,142 +0,0 @@
-/*
- * Copyright (c) 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Test JVM's awareness of cpu sets (cpus and mems)
- * @requires docker.support
- * @requires (os.arch != "s390x")
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo
- * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run driver TestCPUSets
- */
-import java.util.List;
-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.Asserts;
-import jdk.test.lib.Platform;
-import jdk.test.lib.Utils;
-import jdk.test.lib.process.OutputAnalyzer;
-
-
-public class TestCPUSets {
- private static final String imageName = Common.imageName("cpusets");
-
- public static void main(String[] args) throws Exception {
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- Common.prepareWhiteBox();
- DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- // Sanity test the cpu sets reader and parser
- CPUSetsReader.test();
- testTheSet("Cpus_allowed_list");
- testTheSet("Mems_allowed_list");
- } finally {
- DockerTestUtils.removeDockerImage(imageName);
- }
- }
-
-
- private static void testTheSet(String setType) throws Exception {
- String cpuSetStr = CPUSetsReader.readFromProcStatus(setType);
-
- if (cpuSetStr == null) {
- System.out.printf("The %s test is skipped %n", setType);
- } else {
- List<Integer> cpuSet = CPUSetsReader.parseCpuSet(cpuSetStr);
-
- // Test subset of one, full subset, and half of the subset
- testCpuSet(CPUSetsReader.listToString(cpuSet, 1));
- if (cpuSet.size() > 1) {
- testCpuSet(CPUSetsReader.listToString(cpuSet));
- }
- if (cpuSet.size() > 2) {
- testCpuSet(CPUSetsReader.listToString(cpuSet, cpuSet.size()/2 ));
- }
- }
- }
-
-
- private static DockerRunOptions commonOpts() {
- DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java",
- "PrintContainerInfo");
- opts.addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/");
- opts.addJavaOpts("-Xlog:os+container=trace", "-cp", "/test-classes/");
- Common.addWhiteBoxOpts(opts);
- return opts;
- }
-
-
- private static void checkResult(List<String> lines, String lineMarker, String value) {
- boolean lineMarkerFound = false;
-
- for (String line : lines) {
- if (line.contains(lineMarker)) {
- lineMarkerFound = true;
- String[] parts = line.split(":");
- System.out.println("DEBUG: line = " + line);
- System.out.println("DEBUG: parts.length = " + parts.length);
-
- Asserts.assertEquals(parts.length, 2);
- String set = parts[1].replaceAll("\\s","");
- String actual = CPUSetsReader.listToString(CPUSetsReader.parseCpuSet(set));
- Asserts.assertEquals(actual, value);
- break;
- }
- }
- Asserts.assertTrue(lineMarkerFound);
- }
-
-
- private static void testCpuSet(String value) throws Exception {
- Common.logNewTestCase("cpusets.cpus, value = " + value);
-
- DockerRunOptions opts = commonOpts();
- opts.addDockerOpts("--cpuset-cpus=" + value);
-
- List<String> lines = Common.run(opts).asLines();
- checkResult(lines, "cpuset.cpus is:", value);
- }
-
- private static void testMemSet(String value) throws Exception {
- Common.logNewTestCase("cpusets.mems, value = " + value);
-
- DockerRunOptions opts = commonOpts();
- opts.addDockerOpts("--cpuset-mems=" + value);
-
- List<String> lines = Common.run(opts).asLines();
- checkResult(lines, "cpuset.mems is:", value);
- }
-
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/TestJFREvents.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Ensure that certain JFR events return correct results for resource values
- * when run inside Docker container, such as available CPU and memory.
- * Also make sure that PIDs are based on value provided by container,
- * not by the host system.
- * @requires (docker.support & os.maxMemory >= 2g)
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @build JfrReporter
- * @run driver TestJFREvents
- */
-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.Utils;
-
-
-public class TestJFREvents {
- private static final String imageName = Common.imageName("jfr-events");
- private static final int availableCPUs = Runtime.getRuntime().availableProcessors();
-
- public static void main(String[] args) throws Exception {
- System.out.println("Test Environment: detected availableCPUs = " + availableCPUs);
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- // leave one CPU for system and tools, otherwise this test may be unstable
- int maxNrOfAvailableCpus = availableCPUs - 1;
- for (int i=1; i < maxNrOfAvailableCpus; i = i * 2) {
- testCPUInfo(i, i);
- }
-
- long MB = 1024*1024;
- testMemory("200m", "" + 200*MB);
- testMemory("500m", "" + 500*MB);
- testMemory("1g", "" + 1024*MB);
-
- testProcessInfo();
-
- } finally {
- DockerTestUtils.removeDockerImage(imageName);
- }
- }
-
-
- private static void testCPUInfo(int valueToSet, int expectedValue) throws Exception {
- Common.logNewTestCase("CPUInfo: --cpus = " + valueToSet);
- DockerTestUtils.dockerRunJava(
- commonDockerOpts()
- .addDockerOpts("--cpus=" + valueToSet)
- .addClassOptions(JfrReporter.TESTCASE_CPU))
- .shouldHaveExitValue(0)
- .shouldContain(JfrReporter.TEST_REPORTED_CORES);
-
- // The following assertion is currently disabled due to JFR reporting incorrect values.
- // JFR reports values for the host system as opposed to values for the container.
- // @ignore 8219999
- // .shouldContain(JfrReporter.TEST_REPORTED_CORES + "=" + expectedValue);
- }
-
-
- private static void testMemory(String valueToSet, String expectedValue) throws Exception {
- Common.logNewTestCase("Memory: --memory = " + valueToSet);
- DockerTestUtils.dockerRunJava(
- commonDockerOpts()
- .addDockerOpts("--memory=" + valueToSet)
- .addClassOptions(JfrReporter.TESTCASE_MEMORY))
- .shouldHaveExitValue(0)
- .shouldContain(JfrReporter.TEST_REPORTED_MEMORY + "=" + expectedValue);
- }
-
-
- private static void testProcessInfo() throws Exception {
- Common.logNewTestCase("ProcessInfo");
- DockerTestUtils.dockerRunJava(
- commonDockerOpts()
- .addClassOptions(JfrReporter.TESTCASE_PROCESS))
- .shouldHaveExitValue(0)
- .shouldContain(JfrReporter.TEST_REPORTED_PID + "=1");
-
- }
-
-
- private static DockerRunOptions commonDockerOpts() {
- return new DockerRunOptions(imageName, "/jdk/bin/java", "JfrReporter")
- .addDockerOpts("--volume", Utils.TEST_CLASSES + ":/test-classes/")
- .addJavaOpts("-cp", "/test-classes/");
- }
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/TestMemoryAwareness.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- * Copyright (c) 2017, 2018, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Test JVM's memory resource awareness when running inside docker container
- * @requires docker.support
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @build AttemptOOM sun.hotspot.WhiteBox PrintContainerInfo
- * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run driver TestMemoryAwareness
- */
-import jdk.test.lib.containers.docker.Common;
-import jdk.test.lib.containers.docker.DockerRunOptions;
-import jdk.test.lib.containers.docker.DockerTestUtils;
-
-
-public class TestMemoryAwareness {
- private static final String imageName = Common.imageName("memory");
-
- public static void main(String[] args) throws Exception {
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- Common.prepareWhiteBox();
- DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- testMemoryLimit("100m", "104857600");
- testMemoryLimit("500m", "524288000");
- testMemoryLimit("1g", "1073741824");
- testMemoryLimit("4g", "4294967296");
-
- testMemorySoftLimit("500m", "524288000");
- testMemorySoftLimit("1g", "1073741824");
-
- // Add extra 10 Mb to allocator limit, to be sure to cause OOM
- testOOM("256m", 256 + 10);
-
- } finally {
- DockerTestUtils.removeDockerImage(imageName);
- }
- }
-
-
- private static void testMemoryLimit(String valueToSet, String expectedTraceValue)
- throws Exception {
-
- Common.logNewTestCase("memory limit: " + valueToSet);
-
- DockerRunOptions opts = Common.newOpts(imageName)
- .addDockerOpts("--memory", valueToSet);
-
- Common.run(opts)
- .shouldMatch("Memory Limit is:.*" + expectedTraceValue);
- }
-
-
- private static void testMemorySoftLimit(String valueToSet, String expectedTraceValue)
- throws Exception {
- Common.logNewTestCase("memory soft limit: " + valueToSet);
-
- DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
- Common.addWhiteBoxOpts(opts);
- opts.addDockerOpts("--memory-reservation=" + valueToSet);
-
- Common.run(opts)
- .shouldMatch("Memory Soft Limit.*" + expectedTraceValue);
- }
-
-
- // provoke OOM inside the container, see how VM reacts
- private static void testOOM(String dockerMemLimit, int sizeToAllocInMb) throws Exception {
- Common.logNewTestCase("OOM");
-
- DockerRunOptions opts = Common.newOpts(imageName, "AttemptOOM")
- .addDockerOpts("--memory", dockerMemLimit, "--memory-swap", dockerMemLimit);
- opts.classParams.add("" + sizeToAllocInMb);
-
- DockerTestUtils.dockerRunJava(opts)
- .shouldHaveExitValue(1)
- .shouldContain("Entering AttemptOOM main")
- .shouldNotContain("AttemptOOM allocation successful")
- .shouldContain("java.lang.OutOfMemoryError");
- }
-
-}
--- a/test/hotspot/jtreg/runtime/containers/docker/TestMisc.java Fri Apr 12 09:55:30 2019 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2017, 2018, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * 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.
- */
-
-
-/*
- * @test
- * @summary Test miscellanous functionality related to JVM running in docker container
- * @requires docker.support
- * @library /test/lib
- * @modules java.base/jdk.internal.misc
- * java.management
- * jdk.jartool/sun.tools.jar
- * @build CheckContainerized sun.hotspot.WhiteBox PrintContainerInfo
- * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run driver TestMisc
- */
-import jdk.test.lib.containers.docker.Common;
-import jdk.test.lib.containers.docker.DockerTestUtils;
-import jdk.test.lib.containers.docker.DockerRunOptions;
-import jdk.test.lib.process.OutputAnalyzer;
-import jdk.test.lib.process.ProcessTools;
-
-
-public class TestMisc {
- private static final String imageName = Common.imageName("misc");
-
- public static void main(String[] args) throws Exception {
- if (!DockerTestUtils.canTestDocker()) {
- return;
- }
-
- Common.prepareWhiteBox();
- DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker");
-
- try {
- testMinusContainerSupport();
- testIsContainerized();
- testPrintContainerInfo();
- } finally {
- DockerTestUtils.removeDockerImage(imageName);
- }
- }
-
-
- private static void testMinusContainerSupport() throws Exception {
- Common.logNewTestCase("Test related flags: '-UseContainerSupport'");
- DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "-version");
- opts.addJavaOpts("-XX:-UseContainerSupport", "-Xlog:os+container=trace");
-
- Common.run(opts)
- .shouldContain("Container Support not enabled");
- }
-
-
- private static void testIsContainerized() throws Exception {
- Common.logNewTestCase("Test is_containerized() inside a docker container");
-
- DockerRunOptions opts = Common.newOpts(imageName, "CheckContainerized");
- Common.addWhiteBoxOpts(opts);
-
- Common.run(opts)
- .shouldContain(CheckContainerized.INSIDE_A_CONTAINER);
- }
-
-
- private static void testPrintContainerInfo() throws Exception {
- Common.logNewTestCase("Test print_container_info()");
-
- DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo");
- Common.addWhiteBoxOpts(opts);
-
- checkContainerInfo(Common.run(opts));
- }
-
-
- private static void checkContainerInfo(OutputAnalyzer out) throws Exception {
- String[] expectedToContain = new String[] {
- "cpuset.cpus",
- "cpuset.mems",
- "CPU Shares",
- "CPU Quota",
- "CPU Period",
- "OSContainer::active_processor_count",
- "Memory Limit",
- "Memory Soft Limit",
- "Memory Usage",
- "Maximum Memory Usage",
- "memory_max_usage_in_bytes"
- };
-
- for (String s : expectedToContain) {
- out.shouldContain(s);
- }
- }
-
-}
--- a/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java Fri Apr 12 09:55:30 2019 -0400
+++ b/test/lib/jdk/test/lib/containers/docker/DockerTestUtils.java Fri Apr 12 12:26:29 2019 -0700
@@ -169,11 +169,17 @@
generateDockerFile(buildDir.resolve("Dockerfile"),
DockerfileConfig.getBaseImageName(),
DockerfileConfig.getBaseImageVersion());
-
- // Build the docker
- execute(DOCKER_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
- .shouldHaveExitValue(0)
- .shouldContain("Successfully built");
+ try {
+ // Build the docker
+ execute(DOCKER_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
+ .shouldHaveExitValue(0)
+ .shouldContain("Successfully built");
+ } catch (Exception e) {
+ // If docker image building fails there is a good chance it happens due to environment and/or
+ // configuration other than product failure. Throw jtreg skipped exception in such case
+ // instead of failing the test.
+ throw new SkippedException("Building docker image failed. Details: \n" + e.getMessage());
+ }
}