author | mseledtsov |
Thu, 16 Nov 2017 19:01:01 -0800 | |
changeset 47908 | d6d00f785f39 |
child 50545 | 292a4a87c321 |
permissions | -rw-r--r-- |
47908
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
1 |
/* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
4 |
* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
8 |
* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
14 |
* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
18 |
* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
23 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
24 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
25 |
/* |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
26 |
* @test |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
27 |
* @summary Test miscellanous functionality related to JVM running in docker container |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
28 |
* @requires docker.support |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
29 |
* @library /test/lib |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
31 |
* java.management |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
32 |
* jdk.jartool/sun.tools.jar |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
33 |
* @build Common CheckContainerized sun.hotspot.WhiteBox PrintContainerInfo |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
34 |
* @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
35 |
* @run driver TestMisc |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
36 |
*/ |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
37 |
import jdk.test.lib.containers.docker.DockerRunOptions; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
38 |
import jdk.test.lib.containers.docker.DockerTestUtils; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
39 |
import jdk.test.lib.process.OutputAnalyzer; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
40 |
import jdk.test.lib.process.ProcessTools; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
41 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
42 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
43 |
public class TestMisc { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
44 |
private static final String imageName = Common.imageName("misc"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
45 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
46 |
public static void main(String[] args) throws Exception { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
47 |
if (!DockerTestUtils.canTestDocker()) { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
48 |
return; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
49 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
50 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
51 |
Common.prepareWhiteBox(); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
52 |
DockerTestUtils.buildJdkDockerImage(imageName, "Dockerfile-BasicTest", "jdk-docker"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
53 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
54 |
try { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
55 |
testMinusContainerSupport(); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
56 |
testIsContainerized(); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
57 |
testPrintContainerInfo(); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
58 |
} finally { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
59 |
DockerTestUtils.removeDockerImage(imageName); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
60 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
61 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
62 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
63 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
64 |
private static void testMinusContainerSupport() throws Exception { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
65 |
Common.logNewTestCase("Test related flags: '-UseContainerSupport'"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
66 |
DockerRunOptions opts = new DockerRunOptions(imageName, "/jdk/bin/java", "-version"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
67 |
opts.addJavaOpts("-XX:-UseContainerSupport", "-Xlog:os+container=trace"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
68 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
69 |
Common.run(opts) |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
70 |
.shouldContain("Container Support not enabled"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
71 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
72 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
73 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
74 |
private static void testIsContainerized() throws Exception { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
75 |
Common.logNewTestCase("Test is_containerized() inside a docker container"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
76 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
77 |
DockerRunOptions opts = Common.newOpts(imageName, "CheckContainerized"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
78 |
Common.addWhiteBoxOpts(opts); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
79 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
80 |
Common.run(opts) |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
81 |
.shouldContain(CheckContainerized.INSIDE_A_CONTAINER); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
82 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
83 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
84 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
85 |
private static void testPrintContainerInfo() throws Exception { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
86 |
Common.logNewTestCase("Test print_container_info()"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
87 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
88 |
DockerRunOptions opts = Common.newOpts(imageName, "PrintContainerInfo"); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
89 |
Common.addWhiteBoxOpts(opts); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
90 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
91 |
checkContainerInfo(Common.run(opts)); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
92 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
93 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
94 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
95 |
private static void checkContainerInfo(OutputAnalyzer out) throws Exception { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
96 |
String[] expectedToContain = new String[] { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
97 |
"cpuset.cpus", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
98 |
"cpuset.mems", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
99 |
"CPU Shares", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
100 |
"CPU Quota", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
101 |
"CPU Period", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
102 |
"OSContainer::active_processor_count", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
103 |
"Memory Limit", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
104 |
"Memory Soft Limit", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
105 |
"Memory Usage", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
106 |
"Maximum Memory Usage", |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
107 |
"memory_max_usage_in_bytes" |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
108 |
}; |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
109 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
110 |
for (String s : expectedToContain) { |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
111 |
out.shouldContain(s); |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
112 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
113 |
} |
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
114 |
|
d6d00f785f39
8189762: [TESTBUG] Create tests for JDK-8146115 container awareness and resource configuration
mseledtsov
parents:
diff
changeset
|
115 |
} |