test/testlibrary_tests/OutputAnalyzerReportingTest.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 5782
5b1191bf0b4b
child 6876
710a3c8b516e
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

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

mercurial