1 /* |
1 /* |
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
41 * @author Thomas Stuefe (SAP) |
41 * @author Thomas Stuefe (SAP) |
42 */ |
42 */ |
43 |
43 |
44 public class TimeoutInErrorHandlingTest { |
44 public class TimeoutInErrorHandlingTest { |
45 |
45 |
|
46 public static final boolean verbose = System.getProperty("verbose") != null; |
|
47 // 16 seconds for hs_err generation timeout = 4 seconds per step timeout |
|
48 public static final int ERROR_LOG_TIMEOUT = 16; |
46 |
49 |
47 public static void main(String[] args) throws Exception { |
50 public static void main(String[] args) throws Exception { |
|
51 |
|
52 int error_log_timeout = ERROR_LOG_TIMEOUT; |
|
53 if ("SunOS".equals(System.getProperty("os.name"))) { |
|
54 // Give Solaris machines 3X as much time: |
|
55 error_log_timeout *= 3; |
|
56 } |
48 |
57 |
49 /* Start the VM and let it crash. Specify TestUnresponsiveErrorHandler which will |
58 /* Start the VM and let it crash. Specify TestUnresponsiveErrorHandler which will |
50 * let five subsequent error reporting steps hang. The Timeout handling triggered |
59 * let five subsequent error reporting steps hang. The Timeout handling triggered |
51 * by the WatcherThread should kick in and interrupt those steps. In theory, the |
60 * by the WatcherThread should kick in and interrupt those steps. In theory, the |
52 * text "timeout occurred during error reporting in step .." (the little timeouts) |
61 * text "timeout occurred during error reporting in step .." (the little timeouts) |
70 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
79 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
71 "-XX:+UnlockDiagnosticVMOptions", |
80 "-XX:+UnlockDiagnosticVMOptions", |
72 "-Xmx100M", |
81 "-Xmx100M", |
73 "-XX:ErrorHandlerTest=14", |
82 "-XX:ErrorHandlerTest=14", |
74 "-XX:+TestUnresponsiveErrorHandler", |
83 "-XX:+TestUnresponsiveErrorHandler", |
75 "-XX:ErrorLogTimeout=16", // 16 seconds big timeout = 4 seconds per little timeout |
84 "-XX:ErrorLogTimeout=" + error_log_timeout, |
76 "-XX:-CreateCoredumpOnCrash", |
85 "-XX:-CreateCoredumpOnCrash", |
77 "-version"); |
86 "-version"); |
78 |
87 |
79 OutputAnalyzer output_detail = new OutputAnalyzer(pb.start()); |
88 OutputAnalyzer output_detail = new OutputAnalyzer(pb.start()); |
80 |
89 |
|
90 if (verbose) { |
|
91 System.err.println("<begin cmd output>"); |
|
92 System.err.println(output_detail.getOutput()); |
|
93 System.err.println("<end cmd output>"); |
|
94 } |
|
95 |
81 // we should have crashed with a SIGSEGV |
96 // we should have crashed with a SIGSEGV |
82 output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*"); |
97 output_detail.shouldMatch("# A fatal error has been detected by the Java Runtime Environment:.*"); |
83 output_detail.shouldMatch("# +(?:SIGSEGV|EXCEPTION_ACCESS_VIOLATION).*"); |
98 output_detail.shouldMatch("# +(?:SIGSEGV|SIGBUS|EXCEPTION_ACCESS_VIOLATION).*"); |
84 |
99 |
85 // VM should have been aborted by WatcherThread |
100 // VM should have been aborted by WatcherThread |
86 output_detail.shouldMatch(".*timer expired, abort.*"); |
101 output_detail.shouldMatch(".*timer expired, abort.*"); |
87 |
102 |
88 // extract hs-err file |
103 // extract hs-err file |
89 String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1); |
104 String hs_err_file = output_detail.firstMatch("# *(\\S*hs_err_pid\\d+\\.log)", 1); |
90 if (hs_err_file == null) { |
105 if (hs_err_file == null) { |
|
106 if (!verbose) { |
|
107 System.err.println("<begin cmd output>"); |
|
108 System.err.println(output_detail.getOutput()); |
|
109 System.err.println("<end cmd output>"); |
|
110 } |
91 throw new RuntimeException("Did not find hs-err file in output.\n"); |
111 throw new RuntimeException("Did not find hs-err file in output.\n"); |
92 } |
112 } |
93 |
113 |
94 File f = new File(hs_err_file); |
114 File f = new File(hs_err_file); |
95 if (!f.exists()) { |
115 if (!f.exists()) { |
|
116 if (!verbose) { |
|
117 System.err.println("<begin cmd output>"); |
|
118 System.err.println(output_detail.getOutput()); |
|
119 System.err.println("<end cmd output>"); |
|
120 } |
96 throw new RuntimeException("hs-err file missing at " |
121 throw new RuntimeException("hs-err file missing at " |
97 + f.getAbsolutePath() + ".\n"); |
122 + f.getAbsolutePath() + ".\n"); |
98 } |
123 } |
99 |
124 |
100 System.out.println("Found hs_err file. Scanning..."); |
125 System.out.println("Found hs_err file. Scanning..."); |
102 FileInputStream fis = new FileInputStream(f); |
127 FileInputStream fis = new FileInputStream(f); |
103 BufferedReader br = new BufferedReader(new InputStreamReader(fis)); |
128 BufferedReader br = new BufferedReader(new InputStreamReader(fis)); |
104 String line = null; |
129 String line = null; |
105 |
130 |
106 |
131 |
107 |
|
108 Pattern [] pattern = new Pattern[] { |
132 Pattern [] pattern = new Pattern[] { |
109 Pattern.compile(".*timeout occurred during error reporting in step.*"), |
133 Pattern.compile(".*timeout occurred during error reporting in step.*"), |
110 Pattern.compile(".*timeout occurred during error reporting in step.*") |
134 Pattern.compile(".*timeout occurred during error reporting in step.*") |
111 }; |
135 }; |
112 int currentPattern = 0; |
136 int currentPattern = 0; |
113 |
137 |
114 String lastLine = null; |
138 String lastLine = null; |
|
139 StringBuilder saved_hs_err = new StringBuilder(); |
115 while ((line = br.readLine()) != null) { |
140 while ((line = br.readLine()) != null) { |
|
141 saved_hs_err.append(line + System.lineSeparator()); |
116 if (currentPattern < pattern.length) { |
142 if (currentPattern < pattern.length) { |
117 if (pattern[currentPattern].matcher(line).matches()) { |
143 if (pattern[currentPattern].matcher(line).matches()) { |
118 System.out.println("Found: " + line + "."); |
144 System.out.println("Found: " + line + "."); |
119 currentPattern ++; |
145 currentPattern ++; |
120 } |
146 } |
121 } |
147 } |
122 lastLine = line; |
148 lastLine = line; |
123 } |
149 } |
124 br.close(); |
150 br.close(); |
125 |
151 |
|
152 if (verbose) { |
|
153 System.err.println("<begin hs_err contents>"); |
|
154 System.err.print(saved_hs_err); |
|
155 System.err.println("<end hs_err contents>"); |
|
156 } |
|
157 |
126 if (currentPattern < pattern.length) { |
158 if (currentPattern < pattern.length) { |
|
159 if (!verbose) { |
|
160 System.err.println("<begin hs_err contents>"); |
|
161 System.err.print(saved_hs_err); |
|
162 System.err.println("<end hs_err contents>"); |
|
163 } |
127 throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPattern + ")"); |
164 throw new RuntimeException("hs-err file incomplete (first missing pattern: " + currentPattern + ")"); |
128 } |
165 } |
129 |
166 |
130 System.out.println("OK."); |
167 System.out.println("OK."); |
131 |
168 |
132 } |
169 } |
133 |
170 |
134 } |
171 } |
135 |
|