author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58001 | 0437b0f20312 |
permissions | -rw-r--r-- |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
1 |
/* |
54293
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
4 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
8 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
14 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
18 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
50545 | 23 |
|
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
24 |
package jdk.test.lib.containers.docker; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
25 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
26 |
import java.io.File; |
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
27 |
import java.io.FileWriter; |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
28 |
import java.io.IOException; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
29 |
import java.nio.file.Files; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
30 |
import java.nio.file.FileVisitResult; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
31 |
import java.nio.file.Path; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
32 |
import java.nio.file.Paths; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
33 |
import java.nio.file.SimpleFileVisitor; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
34 |
import java.nio.file.StandardCopyOption; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
35 |
import java.nio.file.attribute.BasicFileAttributes; |
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
36 |
import java.util.Arrays; |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
38 |
import java.util.Collections; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
39 |
import java.util.List; |
55757
07e998f8f816
8228434: jdk/net/Sockets/Test.java fails after JDK-8227642
sgehwolf
parents:
55746
diff
changeset
|
40 |
import jdk.test.lib.Container; |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
41 |
import jdk.test.lib.Utils; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
42 |
import jdk.test.lib.process.OutputAnalyzer; |
54424
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
43 |
import jtreg.SkippedException; |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
44 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
45 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
46 |
public class DockerTestUtils { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
47 |
private static boolean isDockerEngineAvailable = false; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
48 |
private static boolean wasDockerEngineChecked = false; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
49 |
|
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
50 |
// Specifies how many lines to copy from child STDOUT to main test output. |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
51 |
// Having too many lines in the main test output will result |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
52 |
// in JT harness trimming the output, and can lead to loss of useful |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
53 |
// diagnostic information. |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
54 |
private static final int MAX_LINES_TO_COPY_FOR_CHILD_STDOUT = 100; |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
55 |
|
54424
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
56 |
// Set this property to true to retain image after test. By default |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
57 |
// images are removed after test execution completes. |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
58 |
// Retaining the image can be useful for diagnostics and image inspection. |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
59 |
// E.g.: start image interactively: docker run -it <IMAGE_NAME>. |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
60 |
public static final boolean RETAIN_IMAGE_AFTER_TEST = |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
61 |
Boolean.getBoolean("jdk.test.docker.retain.image"); |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
62 |
|
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
63 |
// Path to a JDK under test. |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
64 |
// This may be useful when developing tests on non-Linux platforms. |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
65 |
public static final String JDK_UNDER_TEST = |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
66 |
System.getProperty("jdk.test.docker.jdk", Utils.TEST_JDK); |
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
67 |
|
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
68 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
69 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
70 |
* Optimized check of whether the docker engine is available in a given |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
71 |
* environment. Checks only once, then remembers the result in a singleton. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
72 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
73 |
* @return true if docker engine is available |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
74 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
75 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
76 |
public static boolean isDockerEngineAvailable() throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
77 |
if (wasDockerEngineChecked) |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
78 |
return isDockerEngineAvailable; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
79 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
80 |
isDockerEngineAvailable = isDockerEngineAvailableCheck(); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
81 |
wasDockerEngineChecked = true; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
82 |
return isDockerEngineAvailable; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
83 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
84 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
85 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
86 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
87 |
* Convenience method, will check if docker engine is available and usable; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
88 |
* will print the appropriate message when not available. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
89 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
90 |
* @return true if docker engine is available |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
91 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
92 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
93 |
public static boolean canTestDocker() throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
94 |
if (isDockerEngineAvailable()) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
95 |
return true; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
96 |
} else { |
54424
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
97 |
throw new SkippedException("Docker engine is not available on this system"); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
98 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
99 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
100 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
101 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
102 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
103 |
* Simple check - is docker engine available, accessible and usable. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
104 |
* Run basic docker command: 'docker ps' - list docker instances. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
105 |
* If docker engine is available and accesible then true is returned |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
106 |
* and we can proceed with testing docker. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
107 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
108 |
* @return true if docker engine is available and usable |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
109 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
110 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
111 |
private static boolean isDockerEngineAvailableCheck() throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
112 |
try { |
55757
07e998f8f816
8228434: jdk/net/Sockets/Test.java fails after JDK-8227642
sgehwolf
parents:
55746
diff
changeset
|
113 |
execute(Container.ENGINE_COMMAND, "ps") |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
114 |
.shouldHaveExitValue(0) |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
115 |
.shouldContain("CONTAINER") |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
116 |
.shouldContain("IMAGE"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
117 |
} catch (Exception e) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
118 |
return false; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
119 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
120 |
return true; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
121 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
122 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
123 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
124 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
125 |
* Build a docker image that contains JDK under test. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
126 |
* The jdk will be placed under the "/jdk/" folder inside the docker file system. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
127 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
128 |
* @param imageName name of the image to be created, including version tag |
48880
ee49ac008730
8196062: Enable docker container related tests for linux ppc64le
mbaesken
parents:
47615
diff
changeset
|
129 |
* @param dockerfile name of the dockerfile residing in the test source; |
ee49ac008730
8196062: Enable docker container related tests for linux ppc64le
mbaesken
parents:
47615
diff
changeset
|
130 |
* we check for a platform specific dockerfile as well |
ee49ac008730
8196062: Enable docker container related tests for linux ppc64le
mbaesken
parents:
47615
diff
changeset
|
131 |
* and use this one in case it exists |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
132 |
* @param buildDirName name of the docker build/staging directory, which will |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
133 |
* be created in the jtreg's scratch folder |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
134 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
135 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
136 |
public static void |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
137 |
buildJdkDockerImage(String imageName, String dockerfile, String buildDirName) |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
138 |
throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
139 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
140 |
Path buildDir = Paths.get(".", buildDirName); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
141 |
if (Files.exists(buildDir)) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
142 |
throw new RuntimeException("The docker build directory already exists: " + buildDir); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
143 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
144 |
|
54424
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
145 |
Path jdkSrcDir = Paths.get(JDK_UNDER_TEST); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
146 |
Path jdkDstDir = buildDir.resolve("jdk"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
147 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
148 |
Files.createDirectories(jdkDstDir); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
149 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
150 |
// Copy JDK-under-test tree to the docker build directory. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
151 |
// This step is required for building a docker image. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
152 |
Files.walkFileTree(jdkSrcDir, new CopyFileVisitor(jdkSrcDir, jdkDstDir)); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
153 |
buildDockerImage(imageName, Paths.get(Utils.TEST_SRC, dockerfile), buildDir); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
154 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
155 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
156 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
157 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
158 |
* Build a docker image based on given docker file and docker build directory. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
159 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
160 |
* @param imageName name of the image to be created, including version tag |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
161 |
* @param dockerfile path to the Dockerfile to be used for building the docker |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
162 |
* image. The specified dockerfile will be copied to the docker build |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
163 |
* directory as 'Dockerfile' |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
164 |
* @param buildDir build directory; it should already contain all the content |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
165 |
* needed to build the docker image. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
166 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
167 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
168 |
public static void |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
169 |
buildDockerImage(String imageName, Path dockerfile, Path buildDir) throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
170 |
|
54293
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
171 |
generateDockerFile(buildDir.resolve("Dockerfile"), |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
172 |
DockerfileConfig.getBaseImageName(), |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
173 |
DockerfileConfig.getBaseImageVersion()); |
54525
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
174 |
try { |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
175 |
// Build the docker |
55757
07e998f8f816
8228434: jdk/net/Sockets/Test.java fails after JDK-8227642
sgehwolf
parents:
55746
diff
changeset
|
176 |
execute(Container.ENGINE_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString()) |
55746
709913d8ace9
8227642: [TESTBUG] Make docker tests podman compatible
sgehwolf
parents:
55012
diff
changeset
|
177 |
.shouldHaveExitValue(0); |
54525
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
178 |
} catch (Exception e) { |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
179 |
// If docker image building fails there is a good chance it happens due to environment and/or |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
180 |
// configuration other than product failure. Throw jtreg skipped exception in such case |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
181 |
// instead of failing the test. |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
182 |
throw new SkippedException("Building docker image failed. Details: \n" + e.getMessage()); |
5ae4d3f46537
8222299: [TESTBUG] move hotspot container tests to hotspot/containers
mseledtsov
parents:
54424
diff
changeset
|
183 |
} |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
184 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
185 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
186 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
187 |
/** |
54625
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
188 |
* Build the docker command to run java inside a container |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
189 |
* |
57502
650335128b9d
8227122: [TESTBUG] Create Docker sidecar test cases
mseledtsov
parents:
55757
diff
changeset
|
190 |
* @param DockerRunOptions options for running docker |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
191 |
* |
54625
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
192 |
* @return command |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
193 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
194 |
*/ |
54625
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
195 |
public static List<String> buildJavaCommand(DockerRunOptions opts) throws Exception { |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
196 |
List<String> cmd = new ArrayList<>(); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
197 |
|
55757
07e998f8f816
8228434: jdk/net/Sockets/Test.java fails after JDK-8227642
sgehwolf
parents:
55746
diff
changeset
|
198 |
cmd.add(Container.ENGINE_COMMAND); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
199 |
cmd.add("run"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
200 |
if (opts.tty) |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
201 |
cmd.add("--tty=true"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
202 |
if (opts.removeContainerAfterUse) |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
203 |
cmd.add("--rm"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
204 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
205 |
cmd.addAll(opts.dockerOpts); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
206 |
cmd.add(opts.imageNameAndTag); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
207 |
cmd.add(opts.command); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
208 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
209 |
cmd.addAll(opts.javaOpts); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
210 |
if (opts.appendTestJavaOptions) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
211 |
Collections.addAll(cmd, Utils.getTestJavaOpts()); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
212 |
} |
58001
0437b0f20312
8229182: runtime/containers/docker/TestMemoryAwareness.java test fails on SLES12
mbaesken
parents:
57502
diff
changeset
|
213 |
cmd.addAll(opts.javaOptsAppended); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
214 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
215 |
cmd.add(opts.classToRun); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
216 |
cmd.addAll(opts.classParams); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
217 |
|
54625
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
218 |
return cmd; |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
219 |
} |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
220 |
|
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
221 |
/** |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
222 |
* Run Java inside the docker image with specified parameters and options. |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
223 |
* |
57502
650335128b9d
8227122: [TESTBUG] Create Docker sidecar test cases
mseledtsov
parents:
55757
diff
changeset
|
224 |
* @param DockerRunOptions options for running docker |
54625
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
225 |
* |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
226 |
* @return output of the run command |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
227 |
* @throws Exception |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
228 |
*/ |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
229 |
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception { |
7f30741331ad
8222888: [TESTBUG] docker/TestJFREvents.java fails due to "RuntimeException: JAVA_MAIN_CLASS_ is not defined"
mseledtsov
parents:
54525
diff
changeset
|
230 |
return execute(buildJavaCommand(opts)); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
231 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
232 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
233 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
234 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
235 |
* Remove docker image |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
236 |
* |
57502
650335128b9d
8227122: [TESTBUG] Create Docker sidecar test cases
mseledtsov
parents:
55757
diff
changeset
|
237 |
* @param DockerRunOptions options for running docker |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
238 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
239 |
*/ |
54424
b354ffb03ae4
8221710: [TESTBUG] more configurable parameters for docker testing
mseledtsov
parents:
54293
diff
changeset
|
240 |
public static void removeDockerImage(String imageNameAndTag) throws Exception { |
55757
07e998f8f816
8228434: jdk/net/Sockets/Test.java fails after JDK-8227642
sgehwolf
parents:
55746
diff
changeset
|
241 |
execute(Container.ENGINE_COMMAND, "rmi", "--force", imageNameAndTag); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
242 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
243 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
244 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
245 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
246 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
247 |
* Convenience method - express command as sequence of strings |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
248 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
249 |
* @param command to execute |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
250 |
* @return The output from the process |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
251 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
252 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
253 |
public static OutputAnalyzer execute(List<String> command) throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
254 |
return execute(command.toArray(new String[command.size()])); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
255 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
256 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
257 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
258 |
/** |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
259 |
* Execute a specified command in a process, report diagnostic info. |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
260 |
* |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
261 |
* @param command to be executed |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
262 |
* @return The output from the process |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
263 |
* @throws Exception |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
264 |
*/ |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
265 |
public static OutputAnalyzer execute(String... command) throws Exception { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
266 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
267 |
ProcessBuilder pb = new ProcessBuilder(command); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
268 |
System.out.println("[COMMAND]\n" + Utils.getCommandLine(pb)); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
269 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
270 |
long started = System.currentTimeMillis(); |
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
271 |
Process p = pb.start(); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
272 |
long pid = p.pid(); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
273 |
OutputAnalyzer output = new OutputAnalyzer(p); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
274 |
|
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
275 |
String stdoutLogFile = String.format("docker-stdout-%d.log", pid); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
276 |
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]"); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
277 |
System.out.println("[STDERR]\n" + output.getStderr()); |
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
278 |
System.out.println("[STDOUT]\n" + |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
279 |
trimLines(output.getStdout(),MAX_LINES_TO_COPY_FOR_CHILD_STDOUT)); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
280 |
System.out.printf("Child process STDOUT is trimmed to %d lines \n", |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
281 |
MAX_LINES_TO_COPY_FOR_CHILD_STDOUT); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
282 |
writeOutputToFile(output.getStdout(), stdoutLogFile); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
283 |
System.out.println("Full child process STDOUT was saved to " + stdoutLogFile); |
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
284 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
285 |
return output; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
286 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
287 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
288 |
|
55012
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
289 |
private static void writeOutputToFile(String output, String fileName) throws Exception { |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
290 |
try (FileWriter fw = new FileWriter(fileName)) { |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
291 |
fw.write(output, 0, output.length()); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
292 |
} |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
293 |
} |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
294 |
|
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
295 |
|
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
296 |
private static String trimLines(String buffer, int nrOfLines) { |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
297 |
List<String> l = Arrays.asList(buffer.split("\\R")); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
298 |
if (l.size() < nrOfLines) { |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
299 |
return buffer; |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
300 |
} |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
301 |
|
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
302 |
return String.join("\n", l.subList(0, nrOfLines)); |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
303 |
} |
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
304 |
|
fb0cfce19262
8224165: [TESTBUG] Docker tests produce excessive output
mseledtsov
parents:
54625
diff
changeset
|
305 |
|
54293
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
306 |
private static void generateDockerFile(Path dockerfile, String baseImage, |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
307 |
String baseImageVersion) throws Exception { |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
308 |
String template = |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
309 |
"FROM %s:%s\n" + |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
310 |
"COPY /jdk /jdk\n" + |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
311 |
"ENV JAVA_HOME=/jdk\n" + |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
312 |
"CMD [\"/bin/bash\"]\n"; |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
313 |
String dockerFileStr = String.format(template, baseImage, baseImageVersion); |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
314 |
Files.writeString(dockerfile, dockerFileStr); |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
315 |
} |
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
316 |
|
dae71635cc3a
8221342: [TESTBUG] Generate Dockerfile for docker testing
mseledtsov
parents:
50545
diff
changeset
|
317 |
|
47615
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
318 |
private static class CopyFileVisitor extends SimpleFileVisitor<Path> { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
319 |
private final Path src; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
320 |
private final Path dst; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
321 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
322 |
public CopyFileVisitor(Path src, Path dst) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
323 |
this.src = src; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
324 |
this.dst = dst; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
325 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
326 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
327 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
328 |
@Override |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
329 |
public FileVisitResult preVisitDirectory(Path file, |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
330 |
BasicFileAttributes attrs) throws IOException { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
331 |
Path dstDir = dst.resolve(src.relativize(file)); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
332 |
if (!dstDir.toFile().exists()) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
333 |
Files.createDirectories(dstDir); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
334 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
335 |
return FileVisitResult.CONTINUE; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
336 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
337 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
338 |
|
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
339 |
@Override |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
340 |
public FileVisitResult visitFile(Path file, |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
341 |
BasicFileAttributes attrs) throws IOException { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
342 |
if (!file.toFile().isFile()) { |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
343 |
return FileVisitResult.CONTINUE; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
344 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
345 |
Path dstFile = dst.resolve(src.relativize(file)); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
346 |
Files.copy(file, dstFile, StandardCopyOption.COPY_ATTRIBUTES); |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
347 |
return FileVisitResult.CONTINUE; |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
348 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
349 |
} |
6210a27c3704
8181592: [TESTBUG] Docker test utils and docker jdk basic test
mseledtsov
parents:
diff
changeset
|
350 |
} |