author | dtitov |
Mon, 08 Apr 2019 17:09:02 +0000 | |
changeset 54460 | 6733a9176cce |
parent 53707 | 67537bbafd7f |
child 55386 | 2f4e214781a1 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
1 |
/* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
4 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
8 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
13 |
* accompanied this code). |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
14 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
18 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
21 |
* questions. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
22 |
*/ |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
23 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
24 |
import jdk.internal.module.ModuleInfoWriter; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
25 |
import jdk.test.lib.JDKToolFinder; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
26 |
import jdk.test.lib.process.ProcessTools; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
27 |
import jdk.test.lib.util.JarUtils; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
28 |
import sun.tools.common.ProcessHelper; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
29 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
30 |
import java.io.File; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
31 |
import java.io.IOException; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
32 |
import java.io.OutputStream; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
33 |
import java.lang.module.ModuleDescriptor; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
34 |
import java.nio.file.FileSystems; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
36 |
import java.nio.file.Path; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
38 |
import java.util.LinkedList; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
39 |
import java.util.List; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
40 |
import java.util.jar.Attributes; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
41 |
import java.util.jar.JarEntry; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
42 |
import java.util.jar.JarOutputStream; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
43 |
import java.util.jar.Manifest; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
44 |
import java.util.stream.Collectors; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
45 |
import java.util.stream.Stream; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
46 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
47 |
/* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
48 |
* @test |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
49 |
* @bug 8205654 |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
50 |
* @summary Unit test for sun.tools.ProcessHelper class. The test launches Java processes with different Java options |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
51 |
* and checks that sun.tools.ProcessHelper.getMainClass(pid) method returns a correct main class. return a . |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
52 |
* |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
53 |
* @requires os.family == "linux" |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
54 |
* @library /test/lib |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
55 |
* @modules jdk.jcmd/sun.tools.common |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
56 |
* java.base/jdk.internal.module |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
57 |
* @build test.TestProcess |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
58 |
* @run main/othervm TestProcessHelper |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
59 |
*/ |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
60 |
public class TestProcessHelper { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
61 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
62 |
private ProcessHelper PROCESS_HELPER = ProcessHelper.platformProcessHelper(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
63 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
64 |
private static final String TEST_PROCESS_MAIN_CLASS_NAME = "TestProcess"; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
65 |
private static final String TEST_PROCESS_MAIN_CLASS_PACKAGE = "test"; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
66 |
private static final String TEST_PROCESS_MAIN_CLASS = TEST_PROCESS_MAIN_CLASS_PACKAGE + "." |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
67 |
+ TEST_PROCESS_MAIN_CLASS_NAME; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
68 |
private static final Path TEST_CLASSES = FileSystems.getDefault().getPath(System.getProperty("test.classes")); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
69 |
private static final Path USER_DIR = FileSystems.getDefault().getPath(System.getProperty("user.dir", ".")); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
70 |
private static final Path TEST_MODULES = USER_DIR.resolve("testmodules"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
71 |
private static final String JAVA_PATH = JDKToolFinder.getJDKTool("java"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
72 |
private static final Path TEST_CLASS = TEST_CLASSES.resolve(TEST_PROCESS_MAIN_CLASS_PACKAGE) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
73 |
.resolve(TEST_PROCESS_MAIN_CLASS_NAME + ".class"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
74 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
75 |
private static final String[] CP_OPTIONS = {"-cp", "-classpath", "--class-path"}; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
76 |
private static final String[][] VM_ARGS = {{}, {"-Dtest1=aaa"}, {"-Dtest1=aaa", "-Dtest2=bbb"}}; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
77 |
private static final String[][] ARGS = {{}, {"param1"}, {"param1", "param2"}}; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
78 |
private static final String[] MP_OPTIONS = {"-p", "--module-path"}; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
79 |
private static final String[] MODULE_OPTIONS = {"-m", "--module"}; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
80 |
private static final String JAR_OPTION = "-jar"; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
81 |
private static final String MODULE_NAME = "module1"; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
82 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
83 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
84 |
public static void main(String[] args) throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
85 |
new TestProcessHelper().runTests(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
86 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
87 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
88 |
public void runTests() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
89 |
testClassPath(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
90 |
testJar(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
91 |
testModule(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
92 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
93 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
94 |
// Test Java processes that are started with -classpath, -cp, or --class-path options |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
95 |
// and with different combinations of VM and program args. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
96 |
private void testClassPath() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
97 |
for (String cp : CP_OPTIONS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
98 |
for (String[] vma : VM_ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
99 |
for (String[] arg : ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
100 |
List<String> cmd = new LinkedList<>(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
101 |
cmd.add(JAVA_PATH); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
102 |
cmd.add(cp); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
103 |
cmd.add(TEST_CLASSES.toAbsolutePath().toString()); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
104 |
for (String v : vma) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
105 |
cmd.add(v); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
106 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
107 |
cmd.add(TEST_PROCESS_MAIN_CLASS); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
108 |
for (String a : arg) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
109 |
cmd.add(a); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
110 |
} |
54460 | 111 |
testProcessHelper(cmd, TEST_PROCESS_MAIN_CLASS); |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
112 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
113 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
114 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
115 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
116 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
117 |
// Test Java processes that are started with -jar option |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
118 |
// and with different combinations of VM and program args. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
119 |
private void testJar() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
120 |
File jarFile = prepareJar(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
121 |
for (String[] vma : VM_ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
122 |
for (String[] arg : ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
123 |
List<String> cmd = new LinkedList<>(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
124 |
cmd.add(JAVA_PATH); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
125 |
for (String v : vma) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
126 |
cmd.add(v); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
127 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
128 |
cmd.add(JAR_OPTION); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
129 |
cmd.add(jarFile.getAbsolutePath()); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
130 |
for (String a : arg) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
131 |
cmd.add(a); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
132 |
} |
54460 | 133 |
testProcessHelper(cmd, jarFile.getAbsolutePath()); |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
134 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
135 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
136 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
137 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
138 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
139 |
// Test Java processes that are started with -m or --module options |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
140 |
// and with different combination of VM and program args. |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
141 |
private void testModule() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
142 |
prepareModule(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
143 |
for (String mp : MP_OPTIONS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
144 |
for (String m : MODULE_OPTIONS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
145 |
for (String[] vma : VM_ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
146 |
for (String[] arg : ARGS) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
147 |
List<String> cmd = new LinkedList<>(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
148 |
cmd.add(JAVA_PATH); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
149 |
cmd.add(mp); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
150 |
cmd.add(TEST_MODULES.toAbsolutePath().toString()); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
151 |
for (String v : vma) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
152 |
cmd.add(v); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
153 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
154 |
cmd.add(m); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
155 |
cmd.add(MODULE_NAME + "/" + TEST_PROCESS_MAIN_CLASS); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
156 |
for (String a : arg) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
157 |
cmd.add(a); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
158 |
} |
54460 | 159 |
testProcessHelper(cmd, MODULE_NAME + "/" + TEST_PROCESS_MAIN_CLASS); |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
160 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
161 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
162 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
163 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
164 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
165 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
166 |
private void checkMainClass(Process p, String expectedMainClass) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
167 |
String mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
168 |
p.destroyForcibly(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
169 |
if (!expectedMainClass.equals(mainClass)) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
170 |
throw new RuntimeException("Main class is wrong: " + mainClass); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
171 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
172 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
173 |
|
54460 | 174 |
private void testProcessHelper(List<String> args, String expectedValue) throws Exception { |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
175 |
ProcessBuilder pb = new ProcessBuilder(args); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
176 |
String cmd = pb.command().stream().collect(Collectors.joining(" ")); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
177 |
System.out.println("Starting the process:" + cmd); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
178 |
Process p = ProcessTools.startProcess("test", pb); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
179 |
if (!p.isAlive()) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
180 |
throw new RuntimeException("Cannot start the process: " + cmd); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
181 |
} |
54460 | 182 |
checkMainClass(p, expectedValue); |
53707
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
183 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
184 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
185 |
private File prepareJar() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
186 |
Path jarFile = USER_DIR.resolve("testprocess.jar"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
187 |
Manifest manifest = createManifest(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
188 |
JarUtils.createJarFile(jarFile, manifest, TEST_CLASSES, TEST_CLASS); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
189 |
return jarFile.toFile(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
190 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
191 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
192 |
private void prepareModule() throws Exception { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
193 |
TEST_MODULES.toFile().mkdirs(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
194 |
Path moduleJar = TEST_MODULES.resolve("mod1.jar"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
195 |
ModuleDescriptor md = createModuleDescriptor(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
196 |
createModuleJarFile(moduleJar, md, TEST_CLASSES, TEST_CLASS); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
197 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
198 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
199 |
private Manifest createManifest() { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
200 |
Manifest manifest = new Manifest(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
201 |
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
202 |
manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, TEST_PROCESS_MAIN_CLASS); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
203 |
return manifest; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
204 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
205 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
206 |
private ModuleDescriptor createModuleDescriptor() { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
207 |
ModuleDescriptor.Builder builder |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
208 |
= ModuleDescriptor.newModule(MODULE_NAME).requires("java.base"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
209 |
return builder.build(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
210 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
211 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
212 |
private static void createModuleJarFile(Path jarfile, ModuleDescriptor md, Path dir, Path... files) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
213 |
throws IOException { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
214 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
215 |
Path parent = jarfile.getParent(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
216 |
if (parent != null) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
217 |
Files.createDirectories(parent); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
218 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
219 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
220 |
List<Path> entries = findAllRegularFiles(dir, files); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
221 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
222 |
try (OutputStream out = Files.newOutputStream(jarfile); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
223 |
JarOutputStream jos = new JarOutputStream(out)) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
224 |
if (md != null) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
225 |
JarEntry je = new JarEntry("module-info.class"); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
226 |
jos.putNextEntry(je); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
227 |
ModuleInfoWriter.write(md, jos); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
228 |
jos.closeEntry(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
229 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
230 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
231 |
for (Path entry : entries) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
232 |
String name = toJarEntryName(entry); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
233 |
jos.putNextEntry(new JarEntry(name)); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
234 |
Files.copy(dir.resolve(entry), jos); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
235 |
jos.closeEntry(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
236 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
237 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
238 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
239 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
240 |
private static String toJarEntryName(Path file) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
241 |
Path normalized = file.normalize(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
242 |
return normalized.subpath(0, normalized.getNameCount()) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
243 |
.toString() |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
244 |
.replace(File.separatorChar, '/'); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
245 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
246 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
247 |
private static List<Path> findAllRegularFiles(Path dir, Path[] files) throws IOException { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
248 |
List<Path> entries = new ArrayList<>(); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
249 |
for (Path file : files) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
250 |
try (Stream<Path> stream = Files.find(dir.resolve(file), Integer.MAX_VALUE, |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
251 |
(p, attrs) -> attrs.isRegularFile())) { |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
252 |
stream.map(dir::relativize) |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
253 |
.forEach(entries::add); |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
254 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
255 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
256 |
return entries; |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
257 |
} |
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
258 |
|
67537bbafd7f
8205654: serviceability/dcmd/framework/HelpTest.java timed out
dtitov
parents:
diff
changeset
|
259 |
} |