|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2022, Google and/or its affiliates. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | +/* |
| 26 | + * @test id=default |
| 27 | + * @bug 8292695 |
| 28 | + * @summary Check that Ctrl-\ or Ctrl-Break (on Windows) causes HotSpot VM to print a full thread dump. |
| 29 | + * @library /vmTestbase |
| 30 | + * /test/lib |
| 31 | + * @run driver TestBreakSignalThreadDump |
| 32 | + */ |
| 33 | + |
| 34 | +/* |
| 35 | + * @test id=with_jsig |
| 36 | + * @bug 8292695 |
| 37 | + * @summary Check that Ctrl-\ causes HotSpot VM to print a full thread dump when signal chaining is used. |
| 38 | + * @requires os.family != "windows" & os.family != "aix" |
| 39 | + * @library /vmTestbase |
| 40 | + * /test/lib |
| 41 | + * @run driver TestBreakSignalThreadDump load_libjsig |
| 42 | + */ |
| 43 | + |
| 44 | +import java.nio.file.Files; |
| 45 | +import java.nio.file.Path; |
| 46 | +import java.util.Map; |
| 47 | +import jdk.test.lib.Platform; |
| 48 | +import jdk.test.lib.Utils; |
| 49 | +import jdk.test.lib.process.ProcessTools; |
| 50 | +import jdk.test.lib.process.OutputAnalyzer; |
| 51 | +import vm.share.ProcessUtils; |
| 52 | + |
| 53 | +public class TestBreakSignalThreadDump { |
| 54 | + |
| 55 | + static class TestProcess { |
| 56 | + static { |
| 57 | + System.loadLibrary("ProcessUtils"); |
| 58 | + } |
| 59 | + |
| 60 | + public static void main(String[] argv) throws Exception { |
| 61 | + ProcessUtils.sendCtrlBreak(); |
| 62 | + // Wait a bit, as JVM processes the break signal asynchronously. |
| 63 | + Thread.sleep(1000); |
| 64 | + System.out.println("Done!"); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + public static void main(String[] argv) throws Exception { |
| 69 | + String main = "TestBreakSignalThreadDump$TestProcess"; |
| 70 | + ProcessBuilder pb = ProcessTools.createTestJvm("-Djava.library.path=" + Utils.TEST_NATIVE_PATH, main); |
| 71 | + |
| 72 | + if (argv.length > 0 && argv[0].equals("load_libjsig")) { |
| 73 | + prepend_jsig_lib(pb.environment()); |
| 74 | + } |
| 75 | + |
| 76 | + OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
| 77 | + output.shouldHaveExitValue(0); |
| 78 | + output.shouldContain("Full thread dump "); |
| 79 | + output.shouldContain("java.lang.Thread.State: RUNNABLE"); |
| 80 | + output.shouldContain("Done!"); |
| 81 | + } |
| 82 | + |
| 83 | + private static void prepend_jsig_lib(Map<String, String> env) { |
| 84 | + Path libjsig = Platform.jvmLibDir().resolve("libjsig." + Platform.sharedLibraryExt()); |
| 85 | + if (!Files.exists(libjsig)) { |
| 86 | + throw new RuntimeException("File libjsig not found, path: " + libjsig); |
| 87 | + } |
| 88 | + String env_var = Platform.isOSX() ? "DYLD_INSERT_LIBRARIES" : "LD_PRELOAD"; |
| 89 | + env.put(env_var, libjsig.toString()); |
| 90 | + } |
| 91 | +} |
0 commit comments