hotspot/test/serviceability/dcmd/jvmti/LoadJavaAgentDcmdTest.java
changeset 36403 3bc27d7f3e75
parent 36402 7c20aae43c41
parent 36401 fb588215d43d
child 36404 165ddc1dd2e9
child 36570 9608a7830fe9
equal deleted inserted replaced
36402:7c20aae43c41 36403:3bc27d7f3e75
     1 /*
       
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    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 import java.io.*;
       
    24 import jdk.test.lib.*;
       
    25 import jdk.test.lib.dcmd.*;
       
    26 import org.testng.annotations.Test;
       
    27 
       
    28 /*
       
    29  * Test to attach JVMTI java agent.
       
    30  *
       
    31  * @test
       
    32  * @bug 8147388
       
    33  * @library /testlibrary
       
    34  * @modules java.base/sun.misc
       
    35  *          java.compiler
       
    36  *          java.instrument
       
    37  *          java.management
       
    38  *          jdk.jvmstat/sun.jvmstat.monitor
       
    39  * @build ClassFileInstaller jdk.test.lib.* SimpleJvmtiAgent
       
    40  * @run main ClassFileInstaller SimpleJvmtiAgent
       
    41  * @run testng LoadJavaAgentDcmdTest
       
    42  */
       
    43 public class LoadJavaAgentDcmdTest {
       
    44     public void run(CommandExecutor executor)  {
       
    45         try{
       
    46             PrintWriter pw = new PrintWriter("MANIFEST.MF");
       
    47             pw.println("Agent-Class: SimpleJvmtiAgent");
       
    48             pw.close();
       
    49 
       
    50             ProcessBuilder pb = new ProcessBuilder();
       
    51             pb.command(new String[] { JDKToolFinder.getJDKTool("jar"),
       
    52                                       "cmf",
       
    53                                       "MANIFEST.MF",
       
    54                                       "agent.jar",
       
    55                                       "SimpleJvmtiAgent.class"});
       
    56             pb.start().waitFor();
       
    57 
       
    58             // Test 1: No argument
       
    59             OutputAnalyzer output = executor.execute("JVMTI.agent_load " +
       
    60                                                      "agent.jar");
       
    61             output.stderrShouldBeEmpty();
       
    62 
       
    63             // Test 2: With argument
       
    64             output = executor.execute("JVMTI.agent_load " +
       
    65                                       "\"agent.jar=foo=bar\"");
       
    66             output.stderrShouldBeEmpty();
       
    67         } catch (Exception e) {
       
    68             throw new RuntimeException(e);
       
    69         }
       
    70     }
       
    71 
       
    72     @Test
       
    73     public void jmx() throws Throwable {
       
    74         run(new JMXExecutor());
       
    75     }
       
    76 
       
    77     @Test
       
    78     public void cli() throws Throwable {
       
    79         run(new PidJcmdExecutor());
       
    80     }
       
    81 }