author | sangheki |
Mon, 08 Apr 2019 12:15:40 -0700 | |
changeset 54467 | 0c5d713cf43f |
parent 51675 | b487c1e914d0 |
permissions | -rw-r--r-- |
21662
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
1 |
/* |
51675 | 2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
21662
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
4 |
* |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
8 |
* |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
13 |
* accompanied this code). |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
14 |
* |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
18 |
* |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
21 |
* questions. |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
22 |
*/ |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
23 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
24 |
/* |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
25 |
* @test |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
26 |
* @summary Test the OutputAnalyzer reporting functionality, |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
27 |
* such as printing additional diagnostic info |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
28 |
* (exit code, stdout, stderr, command line, etc.) |
30820 | 29 |
* @modules java.management |
51675 | 30 |
* @library /test/lib |
31 |
* @run main OutputAnalyzerReportingTest |
|
21662
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
32 |
*/ |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
33 |
|
51675 | 34 |
import jdk.test.lib.process.OutputAnalyzer; |
35 |
||
21662
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
36 |
import java.io.ByteArrayOutputStream; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
37 |
import java.io.PrintStream; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
38 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
39 |
public class OutputAnalyzerReportingTest { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
40 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
41 |
public static void main(String[] args) throws Exception { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
42 |
// Create the output analyzer under test |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
43 |
String stdout = "aaaaaa"; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
44 |
String stderr = "bbbbbb"; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
45 |
OutputAnalyzer output = new OutputAnalyzer(stdout, stderr); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
46 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
47 |
// Expected summary values should be the same for all cases, |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
48 |
// since the outputAnalyzer object is the same |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
49 |
String expectedExitValue = "-1"; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
50 |
String expectedSummary = |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
51 |
" stdout: [" + stdout + "];\n" + |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
52 |
" stderr: [" + stderr + "]\n" + |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
53 |
" exitValue = " + expectedExitValue + "\n"; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
54 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
55 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
56 |
DiagnosticSummaryTestRunner testRunner = |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
57 |
new DiagnosticSummaryTestRunner(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
58 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
59 |
// should have exit value |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
60 |
testRunner.init(expectedSummary); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
61 |
int unexpectedExitValue = 2; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
62 |
try { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
63 |
output.shouldHaveExitValue(unexpectedExitValue); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
64 |
} catch (RuntimeException e) { } |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
65 |
testRunner.closeAndCheckResults(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
66 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
67 |
// should not contain |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
68 |
testRunner.init(expectedSummary); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
69 |
try { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
70 |
output.shouldNotContain(stdout); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
71 |
} catch (RuntimeException e) { } |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
72 |
testRunner.closeAndCheckResults(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
73 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
74 |
// should contain |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
75 |
testRunner.init(expectedSummary); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
76 |
try { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
77 |
output.shouldContain("unexpected-stuff"); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
78 |
} catch (RuntimeException e) { } |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
79 |
testRunner.closeAndCheckResults(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
80 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
81 |
// should not match |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
82 |
testRunner.init(expectedSummary); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
83 |
try { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
84 |
output.shouldNotMatch("[a]"); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
85 |
} catch (RuntimeException e) { } |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
86 |
testRunner.closeAndCheckResults(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
87 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
88 |
// should match |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
89 |
testRunner.init(expectedSummary); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
90 |
try { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
91 |
output.shouldMatch("[qwerty]"); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
92 |
} catch (RuntimeException e) { } |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
93 |
testRunner.closeAndCheckResults(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
94 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
95 |
} |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
96 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
97 |
private static class DiagnosticSummaryTestRunner { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
98 |
private ByteArrayOutputStream byteStream = |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
99 |
new ByteArrayOutputStream(10000); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
100 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
101 |
private String expectedSummary = ""; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
102 |
private PrintStream errStream; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
103 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
104 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
105 |
public void init(String expectedSummary) { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
106 |
this.expectedSummary = expectedSummary; |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
107 |
byteStream.reset(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
108 |
errStream = new PrintStream(byteStream); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
109 |
System.setErr(errStream); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
110 |
} |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
111 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
112 |
public void closeAndCheckResults() { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
113 |
// check results |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
114 |
errStream.close(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
115 |
String stdErrStr = byteStream.toString(); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
116 |
if (!stdErrStr.contains(expectedSummary)) { |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
117 |
throw new RuntimeException("The output does not contain " |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
118 |
+ "the diagnostic message, or the message is incorrect"); |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
119 |
} |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
120 |
} |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
121 |
} |
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
122 |
|
b37eb0c9db8d
8015497: Take new fixes from hotspot/test/testlibrary to jdk/test/lib/testlibrary
ykantser
parents:
diff
changeset
|
123 |
} |