author | iignatyev |
Fri, 21 Sep 2018 14:50:06 -0700 | |
changeset 51840 | dc15e45122b2 |
parent 51675 | b487c1e914d0 |
permissions | -rw-r--r-- |
25987 | 1 |
/* |
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. |
25987 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
51840 | 24 |
import jdk.test.lib.Asserts; |
51675 | 25 |
import jdk.test.lib.process.OutputAnalyzer; |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
26 |
import jdk.test.lib.apps.LingeredApp; |
25987 | 27 |
|
28 |
/* |
|
29 |
* @test |
|
30 |
* @summary This test verifies jps usage and checks that appropriate error message is shown |
|
31 |
* when running jps with illegal arguments. |
|
51840 | 32 |
* @library /test/lib |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
25987
diff
changeset
|
33 |
* @modules jdk.jartool/sun.tools.jar |
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
25987
diff
changeset
|
34 |
* java.management |
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
35 |
* java.base/jdk.internal.misc |
51840 | 36 |
* @build jdk.test.lib.apps.* JpsHelper |
25987 | 37 |
* @run driver TestJpsSanity |
38 |
*/ |
|
39 |
public class TestJpsSanity { |
|
40 |
||
41 |
public static void main(String[] args) throws Throwable { |
|
42 |
testJpsUsage(); |
|
43 |
testJpsVersion(); |
|
44 |
testJpsUnknownHost(); |
|
38956
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
45 |
testJpsShort(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
46 |
testJpsLong(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
47 |
testJpsShortPkg(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
48 |
testJpsLongPkg(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
49 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
50 |
|
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
51 |
private static void testJpsShort() throws Exception { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
52 |
OutputAnalyzer output = JpsHelper.jps(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
53 |
output.shouldMatch("^[0-9]+ Jps$"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
54 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
55 |
|
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
56 |
private static void testJpsLong() throws Exception { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
57 |
OutputAnalyzer output = JpsHelper.jps("-l"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
58 |
output.shouldMatch("^[0-9]+ jdk\\.jcmd/sun\\.tools\\.jps\\.Jps$"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
59 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
60 |
|
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
61 |
private static void testJpsShortPkg() throws Exception { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
62 |
LingeredApp app = null; |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
63 |
try { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
64 |
app = LingeredApp.startApp(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
65 |
OutputAnalyzer output = JpsHelper.jps(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
66 |
output.shouldMatch("^[0-9]+ LingeredApp$"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
67 |
} finally { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
68 |
LingeredApp.stopApp(app); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
69 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
70 |
} |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
71 |
|
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
72 |
private static void testJpsLongPkg() throws Exception { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
73 |
LingeredApp app = null; |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
74 |
try { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
75 |
app = LingeredApp.startApp(); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
76 |
OutputAnalyzer output = JpsHelper.jps("-l"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
77 |
output.shouldMatch("^[0-9]+ jdk\\.test\\.lib\\.apps\\.LingeredApp$"); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
78 |
} finally { |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
79 |
LingeredApp.stopApp(app); |
cf2c4bfba78a
8156537: Tools using MonitoredVmUtil do not parse module in cmdline correctly
rehn
parents:
34715
diff
changeset
|
80 |
} |
25987 | 81 |
} |
82 |
||
83 |
private static void testJpsUsage() throws Exception { |
|
84 |
OutputAnalyzer output = JpsHelper.jps("-?"); |
|
85 |
JpsHelper.verifyOutputAgainstFile(output); |
|
86 |
||
48543
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
87 |
output = JpsHelper.jps("-h"); |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
88 |
JpsHelper.verifyOutputAgainstFile(output); |
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
89 |
|
7067fe4e054e
8189102: All tools should support -?, -h and --help
goetz
parents:
47216
diff
changeset
|
90 |
output = JpsHelper.jps("--help"); |
25987 | 91 |
JpsHelper.verifyOutputAgainstFile(output); |
92 |
} |
|
93 |
||
94 |
private static void testJpsVersion() throws Exception { |
|
95 |
OutputAnalyzer output = JpsHelper.jps("-version"); |
|
96 |
Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0"); |
|
97 |
Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty"); |
|
98 |
output.shouldContain("illegal argument: -version"); |
|
99 |
} |
|
100 |
||
101 |
private static void testJpsUnknownHost() throws Exception { |
|
42101
e75889484926
8165500: TestJpsJar shouldn't jar all test.classpath directories
dsamersoff
parents:
40686
diff
changeset
|
102 |
String invalidHostName = "Oja781nh2ev7vcvbajdg-Sda1-C.invalid"; |
25987 | 103 |
OutputAnalyzer output = JpsHelper.jps(invalidHostName); |
104 |
Asserts.assertNotEquals(output.getExitValue(), 0, "Exit code shouldn't be 0"); |
|
105 |
Asserts.assertFalse(output.getStderr().isEmpty(), "Error output should not be empty"); |
|
34715
efac989a60dd
8145417: JInfoSanityTest failed with Error attaching to remote server: java.rmi.ConnectException: Connection refused
jbachorik
parents:
30376
diff
changeset
|
106 |
output.shouldMatch(".*(RMI Registry not available at|Unknown host\\:) " + invalidHostName + ".*"); |
25987 | 107 |
} |
108 |
||
109 |
} |