jdk/test/com/sun/tools/attach/BasicTests.java
changeset 25182 1f6766bac82c
parent 24366 57c0a8b7a936
child 28760 b83d51c77b31
equal deleted inserted replaced
25181:216e0899f503 25182:1f6766bac82c
    36 /*
    36 /*
    37  * @test
    37  * @test
    38  * @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
    38  * @bug 6173612 6273707 6277253 6335921 6348630 6342019 6381757
    39  * @summary Basic unit tests for the VM attach mechanism.
    39  * @summary Basic unit tests for the VM attach mechanism.
    40  * @library /lib/testlibrary
    40  * @library /lib/testlibrary
    41  * @run build jdk.testlibrary.* Agent BadAgent RedefineAgent Application Shutdown RedefineDummy RunnerUtil
    41  * @run build jdk.testlibrary.* Agent BadAgent RedefineAgent Application RedefineDummy RunnerUtil
    42  * @run main BasicTests
    42  * @run main BasicTests
    43  *
    43  *
    44  * This test will perform a number of basic attach tests.
    44  * This test will perform a number of basic attach tests.
    45  */
    45  */
    46 public class BasicTests {
    46 public class BasicTests {
    53      * 3. Find the pid and shutdown port of the running Application.
    53      * 3. Find the pid and shutdown port of the running Application.
    54      * 4. Launches the tests in nested class TestMain that will attach to the Application.
    54      * 4. Launches the tests in nested class TestMain that will attach to the Application.
    55      * 5. Shut down the Application.
    55      * 5. Shut down the Application.
    56      */
    56      */
    57     public static void main(String args[]) throws Throwable {
    57     public static void main(String args[]) throws Throwable {
    58         final String pidFile = "TestsBasic.Application.pid";
       
    59         ProcessThread processThread = null;
    58         ProcessThread processThread = null;
    60         RunnerUtil.ProcessInfo info = null;
       
    61         try {
    59         try {
    62             buildJars();
    60             buildJars();
    63             processThread = RunnerUtil.startApplication(pidFile);
    61             processThread = RunnerUtil.startApplication();
    64             info = RunnerUtil.readProcessInfo(pidFile);
    62             runTests(processThread.getPid());
    65             runTests(info.pid);
       
    66         } catch (Throwable t) {
    63         } catch (Throwable t) {
    67             System.out.println("TestBasic got unexpected exception: " + t);
    64             System.out.println("TestBasic got unexpected exception: " + t);
    68             t.printStackTrace();
    65             t.printStackTrace();
    69             throw t;
    66             throw t;
    70         } finally {
    67         } finally {
    71             // Make sure the Application process is stopped.
    68             // Make sure the Application process is stopped.
    72             RunnerUtil.stopApplication(info.shutdownPort, processThread);
    69             RunnerUtil.stopApplication(processThread);
    73         }
    70         }
    74     }
    71     }
    75 
    72 
    76     /**
    73     /**
    77      * Runs the actual tests in nested class TestMain.
    74      * Runs the actual tests in nested class TestMain.
    78      * The reason for running the tests in a separate process
    75      * The reason for running the tests in a separate process
    79      * is that we need to modify the class path.
    76      * is that we need to modify the class path.
    80      */
    77      */
    81     private static void runTests(int pid) throws Throwable {
    78     private static void runTests(long pid) throws Throwable {
    82         final String sep = File.separator;
    79         final String sep = File.separator;
    83 
    80 
    84         // Need to add jdk/lib/tools.jar to classpath.
    81         // Need to add jdk/lib/tools.jar to classpath.
    85         String classpath =
    82         String classpath =
    86             System.getProperty("test.class.path", "") + File.pathSeparator +
    83             System.getProperty("test.class.path", "") + File.pathSeparator +
    90         // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    87         // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    91         String[] args = {
    88         String[] args = {
    92             "-classpath",
    89             "-classpath",
    93             classpath,
    90             classpath,
    94             "BasicTests$TestMain",
    91             "BasicTests$TestMain",
    95             Integer.toString(pid),
    92             Long.toString(pid),
    96             testClassDir + "Agent.jar",
    93             testClassDir + "Agent.jar",
    97             testClassDir + "BadAgent.jar",
    94             testClassDir + "BadAgent.jar",
    98             testClassDir + "RedefineAgent.jar" };
    95             testClassDir + "RedefineAgent.jar" };
    99         OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    96         OutputAnalyzer output = ProcessTools.executeTestJvm(args);
   100         output.shouldHaveExitValue(0);
    97         output.shouldHaveExitValue(0);