1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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 */
42 * The jps output should contain processes' names
43 * (except when jps is started in quite mode).
44 * The expected name of the test process is prepared here.
45 */
46 static {
47 URL url = JpsBase.class.getResource("JpsBase.class");
48 boolean isJar = url.getProtocol().equals("jar");
49
50 if (isJar) {
51 shortProcessName = JpsBase.class.getSimpleName() + ".jar";
52 String urlPath = url.getPath();
53 File jar = new File(urlPath.substring(urlPath.indexOf("file:") + 5, urlPath.indexOf("jar!") + 3));
54 fullProcessName = jar.getAbsolutePath();
55 } else {
56 shortProcessName = JpsBase.class.getSimpleName();
57 fullProcessName = JpsBase.class.getName();
58 }
59 }
60
61 public static void main(String[] args) throws Exception {
62 int pid = ProcessTools.getProcessId();
63
64 List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
65 for (List<JpsHelper.JpsArg> combination : combinations) {
66 OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
67 output.shouldHaveExitValue(0);
68
69 boolean isQuiet = false;
70 boolean isFull = false;
71 String pattern;
72 for (JpsHelper.JpsArg jpsArg : combination) {
73 switch (jpsArg) {
74 case q:
75 // If '-q' is specified output should contain only a list of local VM identifiers:
76 // 30673
77 isQuiet = true;
78 JpsHelper.verifyJpsOutput(output, "^\\d+$");
79 output.shouldContain(Integer.toString(pid));
80 break;
81 case l:
82 // If '-l' is specified output should contain the full package name for the application's main class
83 // or the full path name to the application's JAR file:
84 // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
85 isFull = true;
86 pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
87 output.shouldMatch(pattern);
88 break;
89 case m:
90 // If '-m' is specified output should contain the arguments passed to the main method:
91 // 30673 JpsBase monkey ...
92 for (String arg : args) {
93 pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
94 output.shouldMatch(pattern);
95 }
96 break;
97 case v:
98 // If '-v' is specified output should contain VM arguments:
99 // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
|
1 /*
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
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 */
42 * The jps output should contain processes' names
43 * (except when jps is started in quite mode).
44 * The expected name of the test process is prepared here.
45 */
46 static {
47 URL url = JpsBase.class.getResource("JpsBase.class");
48 boolean isJar = url.getProtocol().equals("jar");
49
50 if (isJar) {
51 shortProcessName = JpsBase.class.getSimpleName() + ".jar";
52 String urlPath = url.getPath();
53 File jar = new File(urlPath.substring(urlPath.indexOf("file:") + 5, urlPath.indexOf("jar!") + 3));
54 fullProcessName = jar.getAbsolutePath();
55 } else {
56 shortProcessName = JpsBase.class.getSimpleName();
57 fullProcessName = JpsBase.class.getName();
58 }
59 }
60
61 public static void main(String[] args) throws Exception {
62 long pid = ProcessTools.getProcessId();
63
64 List<List<JpsHelper.JpsArg>> combinations = JpsHelper.JpsArg.generateCombinations();
65 for (List<JpsHelper.JpsArg> combination : combinations) {
66 OutputAnalyzer output = JpsHelper.jps(JpsHelper.JpsArg.asCmdArray(combination));
67 output.shouldHaveExitValue(0);
68
69 boolean isQuiet = false;
70 boolean isFull = false;
71 String pattern;
72 for (JpsHelper.JpsArg jpsArg : combination) {
73 switch (jpsArg) {
74 case q:
75 // If '-q' is specified output should contain only a list of local VM identifiers:
76 // 30673
77 isQuiet = true;
78 JpsHelper.verifyJpsOutput(output, "^\\d+$");
79 output.shouldContain(Long.toString(pid));
80 break;
81 case l:
82 // If '-l' is specified output should contain the full package name for the application's main class
83 // or the full path name to the application's JAR file:
84 // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
85 isFull = true;
86 pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
87 output.shouldMatch(pattern);
88 break;
89 case m:
90 // If '-m' is specified output should contain the arguments passed to the main method:
91 // 30673 JpsBase monkey ...
92 for (String arg : args) {
93 pattern = "^" + pid + ".*" + replaceSpecialChars(arg) + ".*";
94 output.shouldMatch(pattern);
95 }
96 break;
97 case v:
98 // If '-v' is specified output should contain VM arguments:
99 // 30673 JpsBase -Xmx512m -XX:+UseParallelGC -XX:Flags=/tmp/jtreg/jtreg-workdir/scratch/vmflags ...
|