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

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

mercurial