author | lkorinth |
Mon, 28 Jan 2019 15:53:56 +0100 | |
changeset 53523 | 4c5184c56dc2 |
parent 47216 | 71c04702a3d5 |
child 55308 | 871bc449ce06 |
child 58678 | 9cf78a70fa4f |
permissions | -rw-r--r-- |
17389 | 1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
41705
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
4 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
7 |
* published by the Free Software Foundation. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
8 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
13 |
* accompanied this code). |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
14 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
18 |
* |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
21 |
* questions. |
332239c052cc
8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents:
40631
diff
changeset
|
22 |
*/ |
17389 | 23 |
|
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
24 |
package gc.arguments; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
47216
diff
changeset
|
25 |
|
17389 | 26 |
import java.util.regex.Matcher; |
27 |
import java.util.regex.Pattern; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.Arrays; |
|
30 |
||
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39993
diff
changeset
|
31 |
import jdk.test.lib.process.ProcessTools; |
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
39993
diff
changeset
|
32 |
import jdk.test.lib.process.OutputAnalyzer; |
17389 | 33 |
import sun.hotspot.WhiteBox; |
34 |
||
35 |
class ErgoArgsPrinter { |
|
36 |
public static void main(String[] args) throws Exception { |
|
37 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
|
38 |
wb.printHeapSizes(); |
|
39 |
} |
|
40 |
} |
|
41 |
||
42 |
final class MinInitialMaxValues { |
|
43 |
public long minHeapSize; |
|
44 |
public long initialHeapSize; |
|
45 |
public long maxHeapSize; |
|
46 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
47 |
public long spaceAlignment; |
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
48 |
public long heapAlignment; |
17389 | 49 |
} |
50 |
||
51 |
class TestMaxHeapSizeTools { |
|
52 |
||
53 |
public static void checkMinInitialMaxHeapFlags(String gcflag) throws Exception { |
|
54 |
checkInvalidMinInitialHeapCombinations(gcflag); |
|
55 |
checkValidMinInitialHeapCombinations(gcflag); |
|
56 |
checkInvalidInitialMaxHeapCombinations(gcflag); |
|
57 |
checkValidInitialMaxHeapCombinations(gcflag); |
|
58 |
} |
|
59 |
||
60 |
public static void checkMinInitialErgonomics(String gcflag) throws Exception { |
|
61 |
// heap sizing ergonomics use the value NewSize + OldSize as default values |
|
62 |
// for ergonomics calculation. Retrieve these values. |
|
63 |
long[] values = new long[2]; |
|
64 |
getNewOldSize(gcflag, values); |
|
65 |
||
66 |
// we check cases with values smaller and larger than this default value. |
|
67 |
long newPlusOldSize = values[0] + values[1]; |
|
68 |
long smallValue = newPlusOldSize / 2; |
|
69 |
long largeValue = newPlusOldSize * 2; |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
70 |
long maxHeapSize = largeValue + (2 * 1024 * 1024); |
17389 | 71 |
|
72 |
// -Xms is not set |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
73 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
74 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
75 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
76 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1); |
17389 | 77 |
|
78 |
// -Xms is set to zero |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
79 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
80 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
81 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
82 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1); |
17389 | 83 |
|
84 |
// -Xms is set to small value |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
85 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
86 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
87 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
88 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1); |
17389 | 89 |
|
90 |
// -Xms is set to large value |
|
21561
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
91 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue); |
c619b1cb4554
8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
17389
diff
changeset
|
92 |
checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1); |
17389 | 93 |
} |
94 |
||
95 |
private static long align_up(long value, long alignment) { |
|
96 |
long alignmentMinusOne = alignment - 1; |
|
97 |
return (value + alignmentMinusOne) & ~alignmentMinusOne; |
|
98 |
} |
|
99 |
||
100 |
private static void getNewOldSize(String gcflag, long[] values) throws Exception { |
|
101 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(gcflag, |
|
102 |
"-XX:+PrintFlagsFinal", "-version"); |
|
103 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
104 |
output.shouldHaveExitValue(0); |
|
105 |
||
106 |
String stdout = output.getStdout(); |
|
107 |
values[0] = getFlagValue(" NewSize", stdout); |
|
108 |
values[1] = getFlagValue(" OldSize", stdout); |
|
109 |
} |
|
110 |
||
111 |
public static void checkGenMaxHeapErgo(String gcflag) throws Exception { |
|
112 |
TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4); |
|
113 |
TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5); |
|
114 |
} |
|
115 |
||
116 |
private static void checkInvalidMinInitialHeapCombinations(String gcflag) throws Exception { |
|
37088 | 117 |
expectError(new String[] { gcflag, "-XX:InitialHeapSize=1023K", "-version" }); |
28497
a7aecf0ffb6b
8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents:
22765
diff
changeset
|
118 |
expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" }); |
17389 | 119 |
} |
120 |
||
121 |
private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception { |
|
37088 | 122 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" }); |
17389 | 123 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" }); |
124 |
expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" }); |
|
125 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" }); |
|
126 |
// the following is not an error as -Xms sets both minimal and initial heap size |
|
127 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" }); |
|
128 |
} |
|
129 |
||
130 |
private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception { |
|
37088 | 131 |
expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" }); |
17389 | 132 |
expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" }); |
133 |
expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" }); |
|
134 |
} |
|
135 |
||
136 |
private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception { |
|
137 |
expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" }); |
|
138 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" }); |
|
139 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" }); |
|
140 |
// a value of "0" for initial heap size means auto-detect |
|
141 |
expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" }); |
|
142 |
} |
|
143 |
||
144 |
private static long valueAfter(String source, String match) { |
|
145 |
int start = source.indexOf(match) + match.length(); |
|
146 |
String tail = source.substring(start).split(" ")[0]; |
|
147 |
return Long.parseLong(tail); |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* Executes a new VM process with the given class and parameters. |
|
152 |
* @param vmargs Arguments to the VM to run |
|
153 |
* @param classname Name of the class to run |
|
154 |
* @param arguments Arguments to the class |
|
155 |
* @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string |
|
156 |
* @return The OutputAnalyzer with the results for the invocation. |
|
157 |
*/ |
|
158 |
public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception { |
|
159 |
ArrayList<String> finalargs = new ArrayList<String>(); |
|
160 |
||
161 |
String[] whiteboxOpts = new String[] { |
|
162 |
"-Xbootclasspath/a:.", |
|
163 |
"-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
164 |
"-cp", System.getProperty("java.class.path"), |
|
165 |
}; |
|
166 |
||
167 |
if (useTestDotJavaDotOpts) { |
|
168 |
// System.getProperty("test.java.opts") is '' if no options is set, |
|
169 |
// we need to skip such a result |
|
170 |
String[] externalVMOpts = new String[0]; |
|
171 |
if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) { |
|
172 |
externalVMOpts = System.getProperty("test.java.opts").split(" "); |
|
173 |
} |
|
174 |
finalargs.addAll(Arrays.asList(externalVMOpts)); |
|
175 |
} |
|
176 |
||
177 |
finalargs.addAll(Arrays.asList(vmargs)); |
|
178 |
finalargs.addAll(Arrays.asList(whiteboxOpts)); |
|
179 |
finalargs.add(classname); |
|
180 |
finalargs.addAll(Arrays.asList(arguments)); |
|
181 |
||
182 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0])); |
|
183 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
184 |
output.shouldHaveExitValue(0); |
|
185 |
||
186 |
return output; |
|
187 |
} |
|
188 |
||
189 |
private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception { |
|
190 |
OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false); |
|
191 |
||
192 |
// the output we watch for has the following format: |
|
193 |
// |
|
194 |
// "Minimum heap X Initial heap Y Maximum heap Z Min alignment A Max Alignment B" |
|
195 |
// |
|
196 |
// where A, B, X, Y and Z are sizes in bytes. |
|
197 |
// Unfortunately there is no other way to retrieve the minimum heap size and |
|
198 |
// the alignments. |
|
199 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
200 |
Matcher m = Pattern.compile("Minimum heap \\d+ Initial heap \\d+ Maximum heap \\d+ Space alignment \\d+ Heap alignment \\d+"). |
17389 | 201 |
matcher(output.getStdout()); |
202 |
if (!m.find()) { |
|
203 |
throw new RuntimeException("Could not find heap size string."); |
|
204 |
} |
|
205 |
||
206 |
String match = m.group(); |
|
207 |
||
208 |
// actual values |
|
209 |
val.minHeapSize = valueAfter(match, "Minimum heap "); |
|
210 |
val.initialHeapSize = valueAfter(match, "Initial heap "); |
|
211 |
val.maxHeapSize = valueAfter(match, "Maximum heap "); |
|
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
212 |
val.spaceAlignment = valueAfter(match, "Space alignment "); |
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
213 |
val.heapAlignment = valueAfter(match, "Heap alignment "); |
17389 | 214 |
} |
215 |
||
216 |
/** |
|
217 |
* Verify whether the VM automatically synchronizes minimum and initial heap size if only |
|
218 |
* one is given for the GC specified. |
|
219 |
*/ |
|
220 |
public static void checkErgonomics(String[] args, long[] newoldsize, |
|
221 |
long expectedMin, long expectedInitial) throws Exception { |
|
222 |
||
223 |
MinInitialMaxValues v = new MinInitialMaxValues(); |
|
224 |
getMinInitialMaxHeap(args, v); |
|
225 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
226 |
if ((expectedMin != -1) && (align_up(expectedMin, v.heapAlignment) != v.minHeapSize)) { |
17389 | 227 |
throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize + |
228 |
" differs from expected minimum heap size of " + expectedMin); |
|
229 |
} |
|
230 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
231 |
if ((expectedInitial != -1) && (align_up(expectedInitial, v.heapAlignment) != v.initialHeapSize)) { |
17389 | 232 |
throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize + |
233 |
" differs from expected initial heap size of " + expectedInitial); |
|
234 |
} |
|
235 |
||
236 |
// always check the invariant min <= initial <= max heap size |
|
237 |
if (!(v.minHeapSize <= v.initialHeapSize && v.initialHeapSize <= v.maxHeapSize)) { |
|
238 |
throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " + |
|
239 |
v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize); |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
/** |
|
244 |
* Verify whether the VM respects the given maximum heap size in MB for the |
|
245 |
* GC specified. |
|
246 |
* @param gcflag The garbage collector to test as command line flag. E.g. -XX:+UseG1GC |
|
247 |
* @param maxHeapSize the maximum heap size to verify, in MB. |
|
248 |
*/ |
|
249 |
public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception { |
|
250 |
final long K = 1024; |
|
251 |
||
252 |
MinInitialMaxValues v = new MinInitialMaxValues(); |
|
253 |
getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v); |
|
254 |
||
22765
cae8833b9e29
8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents:
21561
diff
changeset
|
255 |
long expectedHeapSize = align_up(maxHeapsize * K * K, v.heapAlignment); |
17389 | 256 |
long actualHeapSize = v.maxHeapSize; |
257 |
||
258 |
if (actualHeapSize > expectedHeapSize) { |
|
259 |
throw new RuntimeException("Heap has " + actualHeapSize + |
|
260 |
" bytes, expected to be less than " + expectedHeapSize); |
|
261 |
} |
|
262 |
} |
|
263 |
||
264 |
private static long getFlagValue(String flag, String where) { |
|
265 |
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where); |
|
266 |
if (!m.find()) { |
|
267 |
throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
|
268 |
} |
|
269 |
String match = m.group(); |
|
270 |
return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length())); |
|
271 |
} |
|
272 |
||
273 |
private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception { |
|
274 |
if (contains) { |
|
275 |
output.shouldContain(message); |
|
276 |
} else { |
|
277 |
output.shouldNotContain(message); |
|
278 |
} |
|
279 |
} |
|
280 |
||
281 |
private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { |
|
282 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); |
|
283 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
284 |
shouldContainOrNot(output, hasWarning, "Warning"); |
|
285 |
shouldContainOrNot(output, hasError, "Error"); |
|
286 |
output.shouldHaveExitValue(errorcode); |
|
287 |
} |
|
288 |
||
289 |
private static void expectError(String[] flags) throws Exception { |
|
290 |
expect(flags, false, true, 1); |
|
291 |
} |
|
292 |
||
293 |
private static void expectValid(String[] flags) throws Exception { |
|
294 |
expect(flags, false, false, 0); |
|
295 |
} |
|
296 |
} |
|
297 |