49653
|
1 |
/*
|
|
2 |
* Copyright (c) 2018, 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 |
*/
|
|
23 |
|
|
24 |
|
|
25 |
/*
|
|
26 |
* @test
|
|
27 |
* @bug 8191101
|
|
28 |
* @summary Show Registers on assert/guarantee
|
|
29 |
* @library /test/lib
|
|
30 |
* @requires (vm.debug == true) & (os.family == "linux")
|
|
31 |
* @author Thomas Stuefe (SAP)
|
|
32 |
* @modules java.base/jdk.internal.misc
|
|
33 |
* java.management
|
|
34 |
*/
|
|
35 |
|
|
36 |
// Note: this test can only run on debug since it relies on VMError::controlled_crash() which
|
|
37 |
// only exists in debug builds.
|
|
38 |
import java.io.BufferedReader;
|
|
39 |
import java.io.File;
|
|
40 |
import java.io.FileInputStream;
|
|
41 |
import java.io.InputStreamReader;
|
|
42 |
import java.util.regex.Pattern;
|
|
43 |
|
|
44 |
import jdk.test.lib.process.OutputAnalyzer;
|
|
45 |
import jdk.test.lib.Platform;
|
|
46 |
import jdk.test.lib.process.ProcessTools;
|
|
47 |
|
|
48 |
public class ShowRegistersOnAssertTest {
|
|
49 |
|
|
50 |
private static void do_test(boolean do_assert, // true - assert, false - guarantee
|
|
51 |
boolean suppress_assert,
|
|
52 |
boolean show_registers_on_assert) throws Exception
|
|
53 |
{
|
|
54 |
System.out.println("Testing " + (suppress_assert ? "suppressed" : "normal") + " " + (do_assert ? "assert" : "guarantee") +
|
|
55 |
" with " + (show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert") + "...");
|
|
56 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
|
|
57 |
"-XX:+UnlockDiagnosticVMOptions", "-Xmx100M", "-XX:-CreateCoredumpOnCrash",
|
|
58 |
"-XX:ErrorHandlerTest=" + (do_assert ? "1" : "3"),
|
|
59 |
(suppress_assert ? "-XX:SuppressErrorAt=/vmError.cpp" : ""),
|
|
60 |
(show_registers_on_assert ? "-XX:+ShowRegistersOnAssert" : "-XX:-ShowRegistersOnAssert"),
|
|
61 |
"-version");
|
|
62 |
|
|
63 |
OutputAnalyzer output_detail = new OutputAnalyzer(pb.start());
|
|
64 |
|
|
65 |
if (suppress_assert) {
|
|
66 |
// we should have not have crashed. See VMError::controlled_crash().
|
|
67 |
output_detail.shouldMatch(".*survived intentional crash.*");
|
|
68 |
} else {
|
|
69 |
// we should have crashed with an internal error. We should definitly NOT have crashed with a segfault
|
|
70 |
// (which would be a sign that the assert poison page mechanism does not work).
|
|
71 |
output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*");
|
|
72 |
output_detail.shouldMatch("# +Internal Error.*");
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
public static void main(String[] args) throws Exception {
|
|
77 |
// Note: for now, this is only a regression test testing that the addition of ShowRegistersOnAssert does
|
|
78 |
// not break normal assert/guarantee handling. The feature is not implemented on all platforms and really testing
|
|
79 |
// it requires more effort.
|
|
80 |
do_test(false, false, false);
|
|
81 |
do_test(false, false, true);
|
|
82 |
do_test(false, true, false);
|
|
83 |
do_test(false, true, true);
|
|
84 |
do_test(true, false, false);
|
|
85 |
do_test(true, false, true);
|
|
86 |
do_test(true, true, false);
|
|
87 |
do_test(true, true, true);
|
|
88 |
}
|
|
89 |
|
|
90 |
}
|
|
91 |
|