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 import java.util.Arrays;
25
26 import jdk.test.lib.process.OutputAnalyzer;
27 import jdk.test.lib.process.ProcessTools;
28 import jdk.test.lib.JDKToolLauncher;
29
30 /*
31 * @test
32 * @summary Unit test for jstack utility
33 * @library /test/lib
34 * @run main BasicJStackTest
35 */
36 public class BasicJStackTest {
37
38 private static ProcessBuilder processBuilder = new ProcessBuilder();
39
40 public static void main(String[] args) throws Exception {
41 testJstackNoArgs();
42 testJstack_l();
43 }
44
45 private static void testJstackNoArgs() throws Exception {
46 OutputAnalyzer output = jstack();
47 output.shouldHaveExitValue(0);
48 }
49
50 private static void testJstack_l() throws Exception {
51 OutputAnalyzer output = jstack("-l");
52 output.shouldHaveExitValue(0);
53 }
54
55 private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
56 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
57 launcher.addVMArg("-XX:+UsePerfData");
58 if (toolArgs != null) {
59 for (String toolArg : toolArgs) {
60 launcher.addToolArg(toolArg);
61 }
62 }
63 launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
64
65 processBuilder.command(launcher.getCommand());
66 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
67 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
68 System.out.println(output.getOutput());
69
70 return output;
71 }
72
73 }
|
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 import java.util.Arrays;
25
26 import jdk.test.lib.process.OutputAnalyzer;
27 import jdk.test.lib.process.ProcessTools;
28 import jdk.test.lib.JDKToolLauncher;
29
30 /*
31 * @test
32 * @summary Unit test for jstack utility
33 * @library /test/lib
34 * @run main BasicJStackTest
35 */
36 public class BasicJStackTest {
37
38 private static ProcessBuilder processBuilder = new ProcessBuilder();
39 private static String markerName = "markerName" + "\u00e4\u0bb5".repeat(10_000);
40
41 public static void main(String[] args) throws Exception {
42 testJstackNoArgs();
43 testJstack_l();
44 }
45
46 private static void testJstackNoArgs() throws Exception {
47 OutputAnalyzer output = jstack();
48 output.shouldHaveExitValue(0);
49 output.shouldContain(markerName);
50 }
51
52 private static void testJstack_l() throws Exception {
53 OutputAnalyzer output = jstack("-l");
54 output.shouldHaveExitValue(0);
55 output.shouldContain(markerName);
56 }
57
58 private static OutputAnalyzer jstack(String... toolArgs) throws Exception {
59 Thread.currentThread().setName(markerName);
60 JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jstack");
61 launcher.addVMArg("-XX:+UsePerfData");
62 if (toolArgs != null) {
63 for (String toolArg : toolArgs) {
64 launcher.addToolArg(toolArg);
65 }
66 }
67 launcher.addToolArg(Long.toString(ProcessTools.getProcessId()));
68
69 processBuilder.command(launcher.getCommand());
70 System.out.println(Arrays.toString(processBuilder.command().toArray()).replace(",", ""));
71 OutputAnalyzer output = ProcessTools.executeProcess(processBuilder);
72 System.out.println(output.getOutput());
73
74 return output;
75 }
76
77 }
|