1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
* Copyright (c) 2008, 2018, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
*
* @summary converted from VM Testbase nsk/aod/VirtualMachine/VirtualMachine01.
* VM Testbase keywords: [feature_282, jdk]
* VM Testbase readme:
* Description :
* Test checks work of Attach API (com.sun.tools.attach).
* Test is based on the nsk.share.aod framework.
* Test checks that methods of VirtualMachine throws expected exceptions
* in following cases:
* - VirtualMachine.attach(null) should throw NullPointerException
* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException
* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),
* VirtualMachine.loadAgentPath(null) should throw NullPointerException
*
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
* /test/lib
* @run driver jdk.test.lib.FileInstaller . .
* @build nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine01
* nsk.share.aod.DummyTargetApplication
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
* nsk.aod.VirtualMachine.VirtualMachine01.VirtualMachine01
* -jdk ${test.jdk}
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
* -target nsk.share.aod.DummyTargetApplication
*/
package nsk.aod.VirtualMachine.VirtualMachine01;
import nsk.share.aod.*;
import nsk.share.test.TestUtils;
import com.sun.tools.attach.*;
import com.sun.tools.attach.spi.AttachProvider;
/*
* Test provokes exception which should be thrown by VirtualMachine methods:
* - VirtualMachine.attach(null) should throw NullPointerException
* - VirtualMachine.attach(<invalid vm id>) should throw AttachNotSupportedException
* - VirtualMachine.loadAgent(null), VirtualMachine.loadAgentLibrary(null),
* VirtualMachine.loadAgentPath(null) should throw NullPointerException
*/
public class VirtualMachine01 extends AODTestRunner {
VirtualMachine01(String[] args) {
super(args);
}
public void doTestActions(String targetVMId) throws Throwable {
try {
log.display("VirtualMachine.attach((String)null)");
VirtualMachine.attach((String) null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.attach((VirtualMachineDescriptor)null)");
VirtualMachine.attach((VirtualMachineDescriptor) null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
final String invalidVMId = "InvalidID";
try {
log.display("VirtualMachine.attach(" + invalidVMId + ")");
VirtualMachine.attach(invalidVMId);
TestUtils.testFailed("AttachNotSupportedException wasn't thrown");
} catch (AttachNotSupportedException e) {
log.display("Expected exception: " + e);
}
try {
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "AttachProvider.providers() returns empty list");
log.display("Create VirtualMachineDescriptor using provider '" + AttachProvider.providers().get(0) + "'");
VirtualMachineDescriptor vmd = new VirtualMachineDescriptor(AttachProvider.providers().get(0), invalidVMId);
log.display("VirtualMachine.attach(new VirtualMachineDescriptor(provider, " + invalidVMId + "))");
VirtualMachine.attach(vmd);
TestUtils.testFailed("AttachNotSupportedException wasn't thrown");
} catch (AttachNotSupportedException e) {
log.display("Expected exception: " + e);
}
// create VirtualMachine object VM to check non-static methods
VirtualMachine vm = VirtualMachine.attach(targetVMId);
try {
try {
log.display("VirtualMachine.loadAgent(null)");
vm.loadAgent(null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.loadAgent(null, null)");
vm.loadAgent(null, null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.loadAgentLibrary(null)");
vm.loadAgentLibrary(null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.loadAgentLibrary(null, null)");
vm.loadAgentLibrary(null, null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.loadAgentPath(null)");
vm.loadAgentPath(null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
try {
log.display("VirtualMachine.loadAgentPath(null, null)");
vm.loadAgentPath(null, null);
TestUtils.testFailed("NullPointerException wasn't thrown");
} catch (NullPointerException e) {
log.display("Expected exception: " + e);
}
} finally {
vm.detach();
}
}
public static void main(String[] args) {
new VirtualMachine01(args).runTest();
}
}
|