--- a/test/hotspot/jtreg/serviceability/sa/TestIntConstant.java Mon Feb 04 17:35:38 2019 -0800
+++ b/test/hotspot/jtreg/serviceability/sa/TestIntConstant.java Tue Feb 05 00:43:38 2019 +0530
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,14 +23,11 @@
import java.util.ArrayList;
import java.util.List;
-import java.io.IOException;
-import java.util.stream.Collectors;
-import java.io.OutputStream;
import jdk.test.lib.apps.LingeredApp;
-import jdk.test.lib.JDKToolLauncher;
-import jdk.test.lib.Platform;
-import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.Utils;
+import java.util.Map;
+import java.util.HashMap;
+import jtreg.SkippedException;
/**
* @test
@@ -44,96 +41,45 @@
public class TestIntConstant {
- private static void testClhsdbForIntConstant(
- long lingeredAppPid,
- String commandString,
- String[] expectedOutputStrings) throws Exception {
-
- Process p;
- JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jhsdb");
- launcher.addToolArg("clhsdb");
- launcher.addToolArg("--pid");
- launcher.addToolArg(Long.toString(lingeredAppPid));
-
- ProcessBuilder pb = new ProcessBuilder();
- pb.command(launcher.getCommand());
- pb.redirectError(ProcessBuilder.Redirect.INHERIT);
- System.out.println(
- pb.command().stream().collect(Collectors.joining(" ")));
-
- try {
- p = pb.start();
- } catch (Exception attachE) {
- throw new Error("Couldn't start jhsdb or attach to LingeredApp : " + attachE);
- }
-
- // Issue the 'intConstant' inputs at the clhsdb prompt.
- OutputStream input = p.getOutputStream();
+ public static void main (String... args) throws Exception {
+ System.out.println("Starting TestIntConstant test");
+ LingeredApp app = null;
try {
- input.write((commandString + "\n").getBytes());
- input.write("quit\n".getBytes());
- input.flush();
- } catch (IOException ioe) {
- throw new Error("Problem issuing the intConstant command: " +
- commandString + ioe);
- }
-
- OutputAnalyzer output = new OutputAnalyzer(p);
-
- System.out.println("Awaiting process completion");
- try {
- p.waitFor();
- } catch (InterruptedException ie) {
- p.destroyForcibly();
- throw new Error("Problem awaiting the child process: " + ie);
- }
-
- output.shouldHaveExitValue(0);
- System.out.println(output.getOutput());
- for (String expectedOutputString: expectedOutputStrings) {
- output.shouldContain(expectedOutputString);
- }
- }
-
- public static void testIntConstant() throws Exception {
- LingeredApp app = null;
-
- try {
- List<String> vmArgs = new ArrayList<String>();
- vmArgs.addAll(Utils.getVmOptions());
+ ClhsdbLauncher test = new ClhsdbLauncher();
+ List<String> vmArgs = new ArrayList<String>(Utils.getVmOptions());
app = LingeredApp.startApp(vmArgs);
+
System.out.println ("Started LingeredApp with pid " + app.getPid());
+ List<String> cmds = List.of("intConstant",
+ "intConstant _temp_constant 45",
+ "intConstant _temp_constant");
+
+ Map<String, List<String>> expStrMap = new HashMap<>();
+
// Strings to check for in the output of 'intConstant'. The
// 'intConstant' command prints out entries from the
// 'gHotSpotVMIntConstants', which is a table of integer constants,
// with names and the values derived from enums and #define preprocessor
// macros in hotspot.
- String[] defaultOutputStrings =
- {"CollectedHeap::G1 4",
+ expStrMap.put("intConstant", List.of(
+ "CollectedHeap::G1 4",
"RUNNABLE 2",
"Deoptimization::Reason_class_check 4",
"InstanceKlass::_misc_is_unsafe_anonymous 32",
"Generation::ParNew 1",
- "_thread_uninitialized 0"};
- String[] tempConstantString = {"intConstant _temp_constant 45"};
- testClhsdbForIntConstant(app.getPid(), "intConstant", defaultOutputStrings);
- testClhsdbForIntConstant(
- app.getPid(),
- "intConstant _temp_constant 45\nintConstant _temp_constant",
- tempConstantString);
- } finally {
- LingeredApp.stopApp(app);
- }
- }
-
- public static void main (String... args) throws Exception {
-
- try {
- testIntConstant();
- } catch (Exception e) {
- throw new Error("Test failed with " + e);
+ "_thread_uninitialized 0"));
+ expStrMap.put("intConstant _temp_constant", List.of(
+ "intConstant _temp_constant 45"));
+ test.run(app.getPid(), cmds, expStrMap, null);
+ } catch (SkippedException se) {
+ throw se;
+ } catch (Exception ex) {
+ throw new RuntimeException("Test ERROR " + ex, ex);
+ } finally {
+ LingeredApp.stopApp(app);
}
+ System.out.println("Test PASSED");
}
}