author | mr |
Tue, 29 Oct 2019 08:26:55 -0700 | |
changeset 58842 | 6c255334120d |
parent 55348 | d109188f6480 |
child 58923 | 2938e0a4e954 |
permissions | -rw-r--r-- |
46207 | 1 |
/* |
54927 | 2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
46207 | 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 |
package jdk.test.lib.cds; |
|
24 |
||
25 |
import java.io.IOException; |
|
26 |
import java.io.File; |
|
27 |
import java.io.FileOutputStream; |
|
28 |
import java.io.PrintStream; |
|
47545
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
29 |
import java.text.SimpleDateFormat; |
46207 | 30 |
import java.util.ArrayList; |
47545
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
31 |
import java.util.Date; |
46207 | 32 |
import jdk.test.lib.Utils; |
33 |
import jdk.test.lib.process.OutputAnalyzer; |
|
34 |
import jdk.test.lib.process.ProcessTools; |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
35 |
import jtreg.SkippedException; |
46207 | 36 |
|
37 |
// This class contains common test utilities for testing CDS |
|
38 |
public class CDSTestUtils { |
|
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51411
diff
changeset
|
39 |
public static final String MSG_RANGE_NOT_WITHIN_HEAP = |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51411
diff
changeset
|
40 |
"UseSharedSpaces: Unable to allocate region, range is not within java heap."; |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51411
diff
changeset
|
41 |
public static final String MSG_RANGE_ALREADT_IN_USE = |
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51411
diff
changeset
|
42 |
"Unable to allocate region, java heap range is already in use."; |
51720
b7bfd64e43a6
8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents:
51507
diff
changeset
|
43 |
public static final String MSG_COMPRESSION_MUST_BE_USED = |
b7bfd64e43a6
8210523: runtime/appcds/cacheObject/DifferentHeapSizes.java crash
iklam
parents:
51507
diff
changeset
|
44 |
"Unable to use shared archive: UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."; |
51491
187c84a5efe1
8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents:
51411
diff
changeset
|
45 |
|
54927 | 46 |
public static final boolean DYNAMIC_DUMP = Boolean.getBoolean("test.dynamic.cds.archive"); |
47 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
48 |
public interface Checker { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
49 |
public void check(OutputAnalyzer output) throws Exception; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
50 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
51 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
52 |
/* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
53 |
* INTRODUCTION |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
54 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
55 |
* When testing various CDS functionalities, we need to launch JVM processes |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
56 |
* using a "launch method" (such as TestCommon.run), and analyze the results of these |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
57 |
* processes. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
58 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
59 |
* While typical jtreg tests would use OutputAnalyzer in such cases, due to the |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
60 |
* complexity of CDS failure modes, we have added the CDSTestUtils.Result class |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
61 |
* to make the analysis more convenient and less error prone. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
62 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
63 |
* A Java process can end in one of the following 4 states: |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
64 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
65 |
* 1: Unexpected error - such as JVM crashing. In this case, the "launch method" |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
66 |
* will throw a RuntimeException. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
67 |
* 2: Mapping Failure - this happens when the OS (intermittently) fails to map the |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
68 |
* CDS archive, normally caused by Address Space Layout Randomization. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
69 |
* We usually treat this as "pass". |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
70 |
* 3: Normal Exit - the JVM process has finished without crashing, and the exit code is 0. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
71 |
* 4: Abnormal Exit - the JVM process has finished without crashing, and the exit code is not 0. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
72 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
73 |
* In most test cases, we need to check the JVM process's output in cases 3 and 4. However, we need |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
74 |
* to make sure that our test code is not confused by case 2. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
75 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
76 |
* For example, a JVM process is expected to print the string "Hi" and exit with 0. With the old |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
77 |
* CDSTestUtils.runWithArchive API, the test may be written as this: |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
78 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
79 |
* OutputAnalyzer out = CDSTestUtils.runWithArchive(args); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
80 |
* out.shouldContain("Hi"); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
81 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
82 |
* However, if the JVM process fails with mapping failure, the string "Hi" will not be in the output, |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
83 |
* and your test case will fail intermittently. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
84 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
85 |
* Instead, the test case should be written as |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
86 |
* |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
87 |
* CDSTestUtils.run(args).assertNormalExit("Hi"); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
88 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
89 |
* EXAMPLES/HOWTO |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
90 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
91 |
* 1. For simple substring matching: |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
92 |
* |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
93 |
* CDSTestUtils.run(args).assertNormalExit("Hi"); |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
94 |
* CDSTestUtils.run(args).assertNormalExit("a", "b", "x"); |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
95 |
* CDSTestUtils.run(args).assertAbnormalExit("failure 1", "failure2"); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
96 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
97 |
* 2. For more complex output matching: using Lambda expressions |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
98 |
* |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
99 |
* CDSTestUtils.run(args) |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
100 |
* .assertNormalExit(output -> output.shouldNotContain("this should not be printed"); |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
101 |
* CDSTestUtils.run(args) |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
102 |
* .assertAbnormalExit(output -> { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
103 |
* output.shouldNotContain("this should not be printed"); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
104 |
* output.shouldHaveExitValue(123); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
105 |
* }); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
106 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
107 |
* 3. Chaining several checks: |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
108 |
* |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
109 |
* CDSTestUtils.run(args) |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
110 |
* .assertNormalExit(output -> output.shouldNotContain("this should not be printed") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
111 |
* .assertNormalExit("should have this", "should have that"); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
112 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
113 |
* 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally: |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
114 |
* |
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
115 |
* CDSTestUtils.run(args) |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
116 |
* .ifNormalExit("ths string is printed when exiting with 0") |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
117 |
* .ifAbNormalExit("ths string is printed when exiting with 1"); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
118 |
* |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
119 |
* NOTE: you usually don't want to write your test case like this -- it should always |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
120 |
* exit with the same exit code. (But I kept this API because some existing test cases |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
121 |
* behave this way -- need to revisit). |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
122 |
*/ |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
123 |
public static class Result { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
124 |
private final OutputAnalyzer output; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
125 |
private final CDSOptions options; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
126 |
private final boolean hasNormalExit; |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
127 |
private final String CDS_DISABLED = "warning: CDS is disabled when the"; |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
128 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
129 |
public Result(CDSOptions opts, OutputAnalyzer out) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
130 |
checkMappingFailure(out); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
131 |
this.options = opts; |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
132 |
this.output = out; |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
133 |
hasNormalExit = (output.getExitValue() == 0); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
134 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
135 |
if (hasNormalExit) { |
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
136 |
if ("on".equals(options.xShareMode) && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
137 |
output.getStderr().contains("java version") && |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
138 |
!output.getStderr().contains(CDS_DISABLED)) { |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
139 |
// "-showversion" is always passed in the command-line by the execXXX methods. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
140 |
// During normal exit, we require that the VM to show that sharing was enabled. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
141 |
output.shouldContain("sharing"); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
142 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
143 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
144 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
145 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
146 |
public Result assertNormalExit(Checker checker) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
147 |
checker.check(output); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
148 |
output.shouldHaveExitValue(0); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
149 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
150 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
151 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
152 |
public Result assertAbnormalExit(Checker checker) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
153 |
checker.check(output); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
154 |
output.shouldNotHaveExitValue(0); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
155 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
156 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
157 |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
158 |
// When {--limit-modules, --patch-module, and/or --upgrade-module-path} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
159 |
// are specified, CDS is silently disabled for both -Xshare:auto and -Xshare:on. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
160 |
public Result assertSilentlyDisabledCDS(Checker checker) throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
161 |
// this comes from a JVM warning message. |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
162 |
output.shouldContain(CDS_DISABLED); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
163 |
checker.check(output); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
164 |
return this; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
165 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
166 |
|
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
167 |
public Result assertSilentlyDisabledCDS(int exitCode, String... matches) throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
168 |
return assertSilentlyDisabledCDS((out) -> { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
169 |
out.shouldHaveExitValue(exitCode); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
170 |
checkMatches(out, matches); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
171 |
}); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
172 |
} |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
173 |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
174 |
public Result ifNormalExit(Checker checker) throws Exception { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
175 |
if (hasNormalExit) { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
176 |
checker.check(output); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
177 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
178 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
179 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
180 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
181 |
public Result ifAbnormalExit(Checker checker) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
182 |
if (!hasNormalExit) { |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
183 |
checker.check(output); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
184 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
185 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
186 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
187 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
188 |
public Result ifNoMappingFailure(Checker checker) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
189 |
checker.check(output); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
190 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
191 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
192 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
193 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
194 |
public Result assertNormalExit(String... matches) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
195 |
checkMatches(output, matches); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
196 |
output.shouldHaveExitValue(0); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
197 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
198 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
199 |
|
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
200 |
public Result assertAbnormalExit(String... matches) throws Exception { |
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
201 |
checkMatches(output, matches); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
202 |
output.shouldNotHaveExitValue(0); |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
203 |
return this; |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
204 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
205 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
206 |
|
51507
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
207 |
// A number to be included in the filename of the stdout and the stderr output file. |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
208 |
static int logCounter = 0; |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
209 |
|
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
210 |
private static int getNextLogCounter() { |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
211 |
return logCounter++; |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
212 |
} |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
213 |
|
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
214 |
// By default, stdout of child processes are logged in files such as |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
215 |
// <testname>-0000-exec.stdout. If you want to also include the stdout |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
216 |
// inside jtr files, you can override this in the jtreg command line like |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
217 |
// "jtreg -Dtest.cds.copy.child.stdout=true ...." |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
218 |
public static final boolean copyChildStdoutToMainStdout = |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
219 |
Boolean.getBoolean("test.cds.copy.child.stdout"); |
46207 | 220 |
|
221 |
// This property is passed to child test processes |
|
222 |
public static final String TestTimeoutFactor = System.getProperty("test.timeout.factor", "1.0"); |
|
223 |
||
224 |
public static final String UnableToMapMsg = |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
225 |
"Unable to map shared archive: test did not complete"; |
46207 | 226 |
|
227 |
// Create bootstrap CDS archive, |
|
228 |
// use extra JVM command line args as a prefix. |
|
229 |
// For CDS tests specifying prefix makes more sense than specifying suffix, since |
|
230 |
// normally there are no classes or arguments to classes, just "-version" |
|
231 |
// To specify suffix explicitly use CDSOptions.addSuffix() |
|
232 |
public static OutputAnalyzer createArchive(String... cliPrefix) |
|
233 |
throws Exception { |
|
234 |
return createArchive((new CDSOptions()).addPrefix(cliPrefix)); |
|
235 |
} |
|
236 |
||
237 |
// Create bootstrap CDS archive |
|
238 |
public static OutputAnalyzer createArchive(CDSOptions opts) |
|
239 |
throws Exception { |
|
240 |
||
47545
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
241 |
startNewArchiveName(); |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
242 |
|
46207 | 243 |
ArrayList<String> cmd = new ArrayList<String>(); |
244 |
||
245 |
for (String p : opts.prefix) cmd.add(p); |
|
246 |
||
247 |
cmd.add("-Xshare:dump"); |
|
46226
59ae25e5d4b9
8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents:
46220
diff
changeset
|
248 |
cmd.add("-Xlog:cds,cds+hashtables"); |
46207 | 249 |
if (opts.archiveName == null) |
250 |
opts.archiveName = getDefaultArchiveName(); |
|
54927 | 251 |
cmd.add("-XX:SharedArchiveFile=" + opts.archiveName); |
46207 | 252 |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
52319
diff
changeset
|
253 |
if (opts.classList != null) { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
52319
diff
changeset
|
254 |
File classListFile = makeClassList(opts.classList); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
52319
diff
changeset
|
255 |
cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath()); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
52319
diff
changeset
|
256 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
52319
diff
changeset
|
257 |
|
46207 | 258 |
for (String s : opts.suffix) cmd.add(s); |
259 |
||
260 |
String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
|
261 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
|
262 |
return executeAndLog(pb, "dump"); |
|
263 |
} |
|
264 |
||
54927 | 265 |
public static boolean isDynamicArchive() { |
266 |
return DYNAMIC_DUMP; |
|
267 |
} |
|
46207 | 268 |
|
269 |
// check result of 'dump-the-archive' operation, that is "-Xshare:dump" |
|
270 |
public static OutputAnalyzer checkDump(OutputAnalyzer output, String... extraMatches) |
|
271 |
throws Exception { |
|
272 |
||
54927 | 273 |
if (!DYNAMIC_DUMP) { |
274 |
output.shouldContain("Loading classes to share"); |
|
275 |
} else { |
|
276 |
output.shouldContain("Buffer-space to target-space delta") |
|
277 |
.shouldContain("Written dynamic archive 0x"); |
|
278 |
} |
|
46207 | 279 |
output.shouldHaveExitValue(0); |
280 |
||
281 |
for (String match : extraMatches) { |
|
282 |
output.shouldContain(match); |
|
283 |
} |
|
284 |
||
285 |
return output; |
|
286 |
} |
|
287 |
||
288 |
||
289 |
// A commonly used convenience methods to create an archive and check the results |
|
290 |
// Creates an archive and checks for errors |
|
291 |
public static OutputAnalyzer createArchiveAndCheck(CDSOptions opts) |
|
292 |
throws Exception { |
|
293 |
return checkDump(createArchive(opts)); |
|
294 |
} |
|
295 |
||
296 |
||
297 |
public static OutputAnalyzer createArchiveAndCheck(String... cliPrefix) |
|
298 |
throws Exception { |
|
299 |
return checkDump(createArchive(cliPrefix)); |
|
300 |
} |
|
301 |
||
302 |
||
303 |
// This method should be used to check the output of child VM for common exceptions. |
|
304 |
// Most of CDS tests deal with child VM processes for creating and using the archive. |
|
305 |
// However exceptions that occur in the child process do not automatically propagate |
|
306 |
// to the parent process. This mechanism aims to improve the propagation |
|
307 |
// of exceptions and common errors. |
|
308 |
// Exception e argument - an exception to be re-thrown if none of the common |
|
309 |
// exceptions match. Pass null if you wish not to re-throw any exception. |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
310 |
public static void checkCommonExecExceptions(OutputAnalyzer output, Exception e) |
46207 | 311 |
throws Exception { |
58842
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
55348
diff
changeset
|
312 |
if (output.getStdout().contains("https://bugreport.java.com/bugreport/crash.jsp")) { |
46207 | 313 |
throw new RuntimeException("Hotspot crashed"); |
314 |
} |
|
315 |
if (output.getStdout().contains("TEST FAILED")) { |
|
316 |
throw new RuntimeException("Test Failed"); |
|
317 |
} |
|
318 |
if (output.getOutput().contains("Unable to unmap shared space")) { |
|
319 |
throw new RuntimeException("Unable to unmap shared space"); |
|
320 |
} |
|
321 |
||
322 |
// Special case -- sometimes Xshare:on fails because it failed to map |
|
323 |
// at given address. This behavior is platform-specific, machine config-specific |
|
324 |
// and can be random (see ASLR). |
|
325 |
if (isUnableToMap(output)) { |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
326 |
throw new SkippedException(UnableToMapMsg); |
46207 | 327 |
} |
328 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
329 |
if (e != null) { |
46207 | 330 |
throw e; |
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
331 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
332 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
333 |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
334 |
public static void checkCommonExecExceptions(OutputAnalyzer output) throws Exception { |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
335 |
checkCommonExecExceptions(output, null); |
46207 | 336 |
} |
337 |
||
338 |
||
339 |
// Check the output for indication that mapping of the archive failed. |
|
340 |
// Performance note: this check seems to be rather costly - searching the entire |
|
341 |
// output stream of a child process for multiple strings. However, it is necessary |
|
342 |
// to detect this condition, a failure to map an archive, since this is not a real |
|
343 |
// failure of the test or VM operation, and results in a test being "skipped". |
|
344 |
// Suggestions to improve: |
|
345 |
// 1. VM can designate a special exit code for such condition. |
|
346 |
// 2. VM can print a single distinct string indicating failure to map an archive, |
|
347 |
// instead of utilizing multiple messages. |
|
348 |
// These are suggestions to improve testibility of the VM. However, implementing them |
|
349 |
// could also improve usability in the field. |
|
350 |
public static boolean isUnableToMap(OutputAnalyzer output) { |
|
351 |
String outStr = output.getOutput(); |
|
352 |
if ((output.getExitValue() == 1) && ( |
|
353 |
outStr.contains("Unable to reserve shared space at required address") || |
|
354 |
outStr.contains("Unable to map ReadOnly shared space at required address") || |
|
355 |
outStr.contains("Unable to map ReadWrite shared space at required address") || |
|
356 |
outStr.contains("Unable to map MiscData shared space at required address") || |
|
357 |
outStr.contains("Unable to map MiscCode shared space at required address") || |
|
48137
0afc5f9eafef
8191504: [TESTBUG] CDSTestUtils.isUnableToMap() should check OptionalData region mapping failure
jiangli
parents:
47545
diff
changeset
|
358 |
outStr.contains("Unable to map OptionalData shared space at required address") || |
46207 | 359 |
outStr.contains("Could not allocate metaspace at a compatible address") || |
55348
d109188f6480
8224710: [TESTBUG] dynamicArchive/ExcludedClasses.java test failed in tier6 testing on Windows
ccheung
parents:
54927
diff
changeset
|
360 |
outStr.contains("UseSharedSpaces: Unable to allocate region, range is not within java heap") || |
d109188f6480
8224710: [TESTBUG] dynamicArchive/ExcludedClasses.java test failed in tier6 testing on Windows
ccheung
parents:
54927
diff
changeset
|
361 |
outStr.contains("DynamicDumpSharedSpaces is unsupported when base CDS archive is not loaded") )) |
46207 | 362 |
{ |
363 |
return true; |
|
364 |
} |
|
365 |
||
366 |
return false; |
|
367 |
} |
|
368 |
||
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
369 |
public static void checkMappingFailure(OutputAnalyzer out) throws SkippedException { |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
370 |
if (isUnableToMap(out)) { |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
371 |
throw new SkippedException(UnableToMapMsg); |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
372 |
} |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
373 |
} |
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
374 |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
375 |
public static Result run(String... cliPrefix) throws Exception { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
376 |
CDSOptions opts = new CDSOptions(); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
377 |
opts.setArchiveName(getDefaultArchiveName()); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
378 |
opts.addPrefix(cliPrefix); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
379 |
return new Result(opts, runWithArchive(opts)); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
380 |
} |
46207 | 381 |
|
49894
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
382 |
public static Result run(CDSOptions opts) throws Exception { |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
383 |
return new Result(opts, runWithArchive(opts)); |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
384 |
} |
c830e94b5606
8197959: [TESTBUG] Some (App)CDS tests require modification due to the removal of the Java EE and CORBA modules
ccheung
parents:
49739
diff
changeset
|
385 |
|
46207 | 386 |
// Execute JVM with CDS archive, specify command line args suffix |
387 |
public static OutputAnalyzer runWithArchive(String... cliPrefix) |
|
388 |
throws Exception { |
|
389 |
||
390 |
return runWithArchive( (new CDSOptions()) |
|
391 |
.setArchiveName(getDefaultArchiveName()) |
|
392 |
.addPrefix(cliPrefix) ); |
|
393 |
} |
|
394 |
||
395 |
||
396 |
// Execute JVM with CDS archive, specify CDSOptions |
|
397 |
public static OutputAnalyzer runWithArchive(CDSOptions opts) |
|
398 |
throws Exception { |
|
399 |
||
400 |
ArrayList<String> cmd = new ArrayList<String>(); |
|
401 |
||
402 |
for (String p : opts.prefix) cmd.add(p); |
|
403 |
||
404 |
cmd.add("-Xshare:" + opts.xShareMode); |
|
405 |
cmd.add("-Dtest.timeout.factor=" + TestTimeoutFactor); |
|
406 |
||
52319
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
407 |
if (!opts.useSystemArchive) { |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
408 |
if (opts.archiveName == null) |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
409 |
opts.archiveName = getDefaultArchiveName(); |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
410 |
cmd.add("-XX:SharedArchiveFile=" + opts.archiveName); |
625f6c742392
8212200: assert when shared java.lang.Object is redefined by JVMTI agent
iklam
parents:
51720
diff
changeset
|
411 |
} |
46207 | 412 |
|
413 |
if (opts.useVersion) |
|
414 |
cmd.add("-version"); |
|
415 |
||
416 |
for (String s : opts.suffix) cmd.add(s); |
|
417 |
||
418 |
String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
|
419 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
|
420 |
return executeAndLog(pb, "exec"); |
|
421 |
} |
|
422 |
||
423 |
||
424 |
// A commonly used convenience methods to create an archive and check the results |
|
425 |
// Creates an archive and checks for errors |
|
426 |
public static OutputAnalyzer runWithArchiveAndCheck(CDSOptions opts) throws Exception { |
|
427 |
return checkExec(runWithArchive(opts)); |
|
428 |
} |
|
429 |
||
430 |
||
431 |
public static OutputAnalyzer runWithArchiveAndCheck(String... cliPrefix) throws Exception { |
|
432 |
return checkExec(runWithArchive(cliPrefix)); |
|
433 |
} |
|
434 |
||
435 |
||
436 |
public static OutputAnalyzer checkExec(OutputAnalyzer output, |
|
437 |
String... extraMatches) throws Exception { |
|
438 |
CDSOptions opts = new CDSOptions(); |
|
439 |
return checkExec(output, opts, extraMatches); |
|
440 |
} |
|
441 |
||
442 |
||
443 |
// check result of 'exec' operation, that is when JVM is run using the archive |
|
444 |
public static OutputAnalyzer checkExec(OutputAnalyzer output, CDSOptions opts, |
|
445 |
String... extraMatches) throws Exception { |
|
446 |
try { |
|
447 |
if ("on".equals(opts.xShareMode)) { |
|
448 |
output.shouldContain("sharing"); |
|
449 |
} |
|
450 |
output.shouldHaveExitValue(0); |
|
451 |
} catch (RuntimeException e) { |
|
452 |
checkCommonExecExceptions(output, e); |
|
453 |
return output; |
|
454 |
} |
|
455 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
456 |
checkMatches(output, extraMatches); |
46207 | 457 |
return output; |
458 |
} |
|
459 |
||
460 |
||
461 |
public static OutputAnalyzer checkExecExpectError(OutputAnalyzer output, |
|
462 |
int expectedExitValue, |
|
463 |
String... extraMatches) throws Exception { |
|
464 |
if (isUnableToMap(output)) { |
|
51411
4699147a4f91
8209164: [TESTBUG] Apply jtreg skipped status to cds tests
mseledtsov
parents:
49931
diff
changeset
|
465 |
throw new SkippedException(UnableToMapMsg); |
46207 | 466 |
} |
467 |
||
468 |
output.shouldHaveExitValue(expectedExitValue); |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
469 |
checkMatches(output, extraMatches); |
46207 | 470 |
return output; |
471 |
} |
|
472 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
473 |
public static OutputAnalyzer checkMatches(OutputAnalyzer output, |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
474 |
String... matches) throws Exception { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48137
diff
changeset
|
475 |
for (String match : matches) { |
46207 | 476 |
output.shouldContain(match); |
477 |
} |
|
478 |
return output; |
|
479 |
} |
|
480 |
||
481 |
||
482 |
// get the file object for the test artifact |
|
483 |
public static File getTestArtifact(String name, boolean checkExistence) { |
|
484 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
485 |
File file = new File(dir, name); |
|
486 |
||
487 |
if (checkExistence && !file.exists()) { |
|
488 |
throw new RuntimeException("Cannot find " + file.getPath()); |
|
489 |
} |
|
490 |
||
491 |
return file; |
|
492 |
} |
|
493 |
||
494 |
||
495 |
// create file containing the specified class list |
|
496 |
public static File makeClassList(String classes[]) |
|
497 |
throws Exception { |
|
498 |
return makeClassList(getTestName() + "-", classes); |
|
499 |
} |
|
500 |
||
501 |
// create file containing the specified class list |
|
502 |
public static File makeClassList(String testCaseName, String classes[]) |
|
503 |
throws Exception { |
|
504 |
||
505 |
File classList = getTestArtifact(testCaseName + "test.classlist", false); |
|
506 |
FileOutputStream fos = new FileOutputStream(classList); |
|
507 |
PrintStream ps = new PrintStream(fos); |
|
508 |
||
509 |
addToClassList(ps, classes); |
|
510 |
||
511 |
ps.close(); |
|
512 |
fos.close(); |
|
513 |
||
514 |
return classList; |
|
515 |
} |
|
516 |
||
517 |
||
518 |
public static void addToClassList(PrintStream ps, String classes[]) |
|
519 |
throws IOException |
|
520 |
{ |
|
521 |
if (classes != null) { |
|
522 |
for (String s : classes) { |
|
523 |
ps.println(s); |
|
524 |
} |
|
525 |
} |
|
526 |
} |
|
527 |
||
528 |
||
529 |
// Optimization for getting a test name. |
|
530 |
// Test name does not change during execution of the test, |
|
531 |
// but getTestName() uses stack walking hence it is expensive. |
|
532 |
// Therefore cache it and reuse it. |
|
533 |
private static String testName; |
|
534 |
public static String getTestName() { |
|
535 |
if (testName == null) { |
|
536 |
testName = Utils.getTestName(); |
|
537 |
} |
|
538 |
return testName; |
|
539 |
} |
|
540 |
||
47545
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
541 |
private static final SimpleDateFormat timeStampFormat = |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
542 |
new SimpleDateFormat("HH'h'mm'm'ss's'SSS"); |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
543 |
|
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
544 |
private static String defaultArchiveName; |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
545 |
|
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
546 |
// Call this method to start new archive with new unique name |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
547 |
public static void startNewArchiveName() { |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
548 |
defaultArchiveName = getTestName() + |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
549 |
timeStampFormat.format(new Date()) + ".jsa"; |
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
550 |
} |
46207 | 551 |
|
552 |
public static String getDefaultArchiveName() { |
|
47545
b741e818a8ac
8187124: [TESTBUG] TestInterpreterMethodEntries.java: Unable to create shared archive file
ccheung
parents:
46226
diff
changeset
|
553 |
return defaultArchiveName; |
46207 | 554 |
} |
555 |
||
556 |
||
557 |
// ===================== FILE ACCESS convenience methods |
|
558 |
public static File getOutputFile(String name) { |
|
559 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
560 |
return new File(dir, getTestName() + "-" + name); |
|
561 |
} |
|
562 |
||
563 |
||
564 |
public static File getOutputSourceFile(String name) { |
|
565 |
File dir = new File(System.getProperty("test.classes", ".")); |
|
566 |
return new File(dir, name); |
|
567 |
} |
|
568 |
||
569 |
||
570 |
public static File getSourceFile(String name) { |
|
571 |
File dir = new File(System.getProperty("test.src", ".")); |
|
572 |
return new File(dir, name); |
|
573 |
} |
|
574 |
||
575 |
||
576 |
// ============================= Logging |
|
577 |
public static OutputAnalyzer executeAndLog(ProcessBuilder pb, String logName) throws Exception { |
|
578 |
long started = System.currentTimeMillis(); |
|
579 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
|
51507
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
580 |
String outputFileNamePrefix = |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
581 |
getTestName() + "-" + String.format("%04d", getNextLogCounter()) + "-" + logName; |
46207 | 582 |
|
51507
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
583 |
writeFile(getOutputFile(outputFileNamePrefix + ".stdout"), output.getStdout()); |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
584 |
writeFile(getOutputFile(outputFileNamePrefix + ".stderr"), output.getStderr()); |
46207 | 585 |
System.out.println("[ELAPSED: " + (System.currentTimeMillis() - started) + " ms]"); |
51507
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
586 |
System.out.println("[logging stdout to " + outputFileNamePrefix + ".stdout]"); |
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
587 |
System.out.println("[logging stderr to " + outputFileNamePrefix + ".stderr]"); |
46207 | 588 |
System.out.println("[STDERR]\n" + output.getStderr()); |
589 |
||
51507
3e3764f8fe36
8207211: [TESTBUG] Remove excessive output from CDS/AppCDS tests
ccheung
parents:
51491
diff
changeset
|
590 |
if (copyChildStdoutToMainStdout) |
46207 | 591 |
System.out.println("[STDOUT]\n" + output.getStdout()); |
592 |
||
593 |
return output; |
|
594 |
} |
|
595 |
||
596 |
||
597 |
private static void writeFile(File file, String content) throws Exception { |
|
598 |
FileOutputStream fos = new FileOutputStream(file); |
|
599 |
PrintStream ps = new PrintStream(fos); |
|
600 |
ps.print(content); |
|
601 |
ps.close(); |
|
602 |
fos.close(); |
|
603 |
} |
|
604 |
} |