25
import java.util.Arrays;
26
import java.util.HashMap;
30
import jdk.test.lib.Utils;
31
import jdk.test.lib.apps.LingeredApp;
32
import jdk.test.lib.JDKToolLauncher;
33
import jdk.test.lib.process.OutputAnalyzer;
34
import jdk.test.lib.SA.SATestUtils;
35
import jtreg.SkippedException;
46
public class ClhsdbDumpclass {
47
static final String APP_DOT_CLASSNAME = LingeredApp.class.getName();
48
static final String APP_SLASH_CLASSNAME = APP_DOT_CLASSNAME.replace('.', '/');
50
public static void main(String[] args) throws Exception {
51
if (SATestUtils.needsPrivileges()) {
53
throw new SkippedException("Cannot run this test on OSX if adding privileges is required.");
55
System.out.println("Starting ClhsdbDumpclass test");
57
LingeredApp theApp = null;
59
ClhsdbLauncher test = new ClhsdbLauncher();
61
theApp = LingeredApp.startApp();
62
System.out.println("Started LingeredApp with pid " + theApp.getPid());
65
String cmd = "dumpclass " + APP_DOT_CLASSNAME;
66
List<String> cmds = List.of(cmd);
67
Map<String, List<String>> unExpStrMap = new HashMap<>();
68
unExpStrMap.put(cmd, List.of("class not found"));
69
test.run(theApp.getPid(), cmds, null, unExpStrMap);
70
File classFile = new File(APP_SLASH_CLASSNAME + ".class");
71
if (!classFile.exists()) {
72
throw new RuntimeException("FAILED: Cannot find dumped .class file");
76
JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("javap");
77
launcher.addVMArgs(Utils.getTestJavaOpts());
79
launcher.addToolArg("-verbose");
80
launcher.addToolArg(classFile.toString());
81
System.out.println("> javap " + classFile.toString());
82
List<String> cmdStringList = Arrays.asList(launcher.getCommand());
83
ProcessBuilder pb = new ProcessBuilder(cmdStringList);
84
Process javap = pb.start();
85
OutputAnalyzer out = new OutputAnalyzer(javap);
87
System.out.println(out.getStdout());
88
System.err.println(out.getStderr());
89
out.shouldHaveExitValue(0);
90
out.shouldMatch("public class " + APP_DOT_CLASSNAME);
94
out.shouldContain("StackMapTable:");
95
out.shouldContain("BootstrapMethods:");
96
out.shouldNotContain("Error:");
97
} catch (SkippedException se) {
99
} catch (Exception ex) {
100
throw new RuntimeException("Test ERROR " + ex, ex);
102
LingeredApp.stopApp(theApp);
104
System.out.println("Test PASSED");