1 /*
   2  * Copyright (c) 2017, 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 jdk.test.lib.dcmd.*;
  24 import jdk.test.lib.Platform;
  25 import jdk.test.lib.process.OutputAnalyzer;
  26 import org.testng.annotations.Test;
  27 
  28 /*
  29  * @test
  30  * @bug 8165736
  31  * @library /test/lib
  32  * @run testng AttachIncorrectLibrary
  33  */
  34 public class AttachIncorrectLibrary {
  35 
  36     public void run(CommandExecutor executor)  {
  37         try{
  38             OutputAnalyzer output = executor.execute("JVMTI.agent_load " +
  39                                               sharedObjectName("SilverBullet"));
  40             output.shouldContain(" was not loaded");
  41         } catch (Exception e) {
  42             throw new RuntimeException(e);
  43         }
  44     }
  45 
  46     /**
  47      * Build name of shared object according to platform rules
  48      */
  49     public static String sharedObjectName(String name) {
  50         if (Platform.isWindows()) {
  51             return name + ".dll";
  52         }
  53         if (Platform.isOSX()) {
  54             return "lib" + name + ".dylib";
  55         }
  56         return "lib" + name + ".so";
  57     }
  58 
  59     @Test
  60     public void jmx() throws Throwable {
  61         run(new JMXExecutor());
  62     }
  63 
  64     @Test
  65     public void cli() throws Throwable {
  66         run(new PidJcmdExecutor());
  67     }
  68 }