8199380: [TESTBUG] Open source VM testbase AOD tests
Reviewed-by: erikj, sspitsyn
This commit is contained in:
parent
657250f3c5
commit
91cff962f9
@ -134,6 +134,11 @@ NSK_JVMTI_AOD_INCLUDES := \
|
||||
-I$(VM_TESTBASE_DIR)/nsk/share/jvmti \
|
||||
-I$(VM_TESTBASE_DIR)/nsk/share/jvmti/aod
|
||||
|
||||
NSK_AOD_INCLUDES := \
|
||||
-I$(VM_TESTBASE_DIR)/nsk/share/aod \
|
||||
-I$(VM_TESTBASE_DIR)/nsk/share/native \
|
||||
-I$(VM_TESTBASE_DIR)/nsk/share/jni
|
||||
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libProcessUtils := $(VM_SHARE_INCLUDES)
|
||||
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libThreadController := $(NSK_MONITORING_INCLUDES)
|
||||
@ -823,6 +828,12 @@ BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libattach021Agent00 := $(NSK_JVMTI_AOD_INCL
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libattach050Agent00 := $(NSK_JVMTI_AOD_INCLUDES)
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libattach002Agent00 := $(NSK_JVMTI_AOD_INCLUDES)
|
||||
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine07agent00 := $(NSK_AOD_INCLUDES)
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine07agent01 := $(NSK_AOD_INCLUDES)
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine07agent02 := $(NSK_AOD_INCLUDES)
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine07agent03 := $(NSK_AOD_INCLUDES)
|
||||
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libVirtualMachine09agent00 := $(NSK_AOD_INCLUDES)
|
||||
|
||||
################################################################################
|
||||
|
||||
# Platform specific setup
|
||||
|
@ -1870,6 +1870,10 @@ vmTestbase_vm_heapdump_quick = \
|
||||
vmTestbase/heapdump/JMapHeapCore/TestDescription.java \
|
||||
vmTestbase/heapdump/JMapMetaspace/TestDescription.java
|
||||
|
||||
# Tests for attach-on-demand implementation
|
||||
vmTestbase_nsk_aod = \
|
||||
vmTestbase/nsk/aod
|
||||
|
||||
# JDB tests
|
||||
vmTestbase_nsk_jdb = \
|
||||
vmTestbase/nsk/jdb
|
||||
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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/AttachProvider/AttachProvider01.
|
||||
* 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.
|
||||
* This test checks that method AttachProvider.listVirtualMachines() returns
|
||||
* VirtualMachineDescriptors for 2 VMs started by this test.
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.AttachProvider.AttachProvider01.AttachProvider01
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.AttachProvider.AttachProvider01.AttachProvider01
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.AttachProvider.AttachProvider01;
|
||||
|
||||
import java.util.List;
|
||||
import com.sun.tools.attach.*;
|
||||
import com.sun.tools.attach.spi.AttachProvider;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Test checks method AttachProvider.listVirtualMachines()
|
||||
* (test checks that collection returned by AttachProvider.listVirtualMachines() contains current VM
|
||||
* and another VM started by this test)
|
||||
*/
|
||||
public class AttachProvider01 extends AODTestRunner {
|
||||
|
||||
public AttachProvider01(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
String currentVMId = getCurrentVMId();
|
||||
|
||||
for (AttachProvider provider : AttachProvider.providers()) {
|
||||
log.display("Checking AttachProvider.listVirtualMachines() (provider: " + provider + ")");
|
||||
checkList(provider.listVirtualMachines(), currentVMId, targetVMId);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkList(List<VirtualMachineDescriptor> vmDescriptors, String currentVMId, String targetVMId) {
|
||||
VirtualMachineDescriptor currentVMDesc = null;
|
||||
VirtualMachineDescriptor targetVMDesc = null;
|
||||
|
||||
for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {
|
||||
log.display("VirtualMachineDescriptor: " + vmDescriptor);
|
||||
|
||||
if (vmDescriptor.id().equals(currentVMId)) {
|
||||
currentVMDesc = vmDescriptor;
|
||||
} else if (vmDescriptor.id().equals(targetVMId)) {
|
||||
targetVMDesc = vmDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
TestUtils.assertNotNull(currentVMDesc, "VirtualMachine.list() didn't return descriptor for the current VM");
|
||||
TestUtils.assertNotNull(targetVMDesc, "VirtualMachine.list() didn't return descriptor for VM with id '" +
|
||||
targetVMId + "'");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new AttachProvider01(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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/AttachProvider/AttachProvider02.
|
||||
* 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.
|
||||
* This test tries to attach to the VM started by this test using 2 methods:
|
||||
* - AttachProvider.attachVirtualMachine(String id)
|
||||
* - AttachProvider.attachVirtualMachine(VirtualMachineDescriptor vmd)
|
||||
* After attaching test tries to use created VirtualMachine object (tries to call VirtualMachine.getSystemProperties()).
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.AttachProvider.AttachProvider02.AttachProvider02
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData
|
||||
* PropertyResolvingWrapper
|
||||
* nsk.aod.AttachProvider.AttachProvider02.AttachProvider02
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.AttachProvider.AttachProvider02;
|
||||
|
||||
import java.util.Properties;
|
||||
import com.sun.tools.attach.*;
|
||||
import com.sun.tools.attach.spi.AttachProvider;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Test checks following methods:
|
||||
* - AttachProvider.attachVirtualMachine(String id)
|
||||
* - AttachProvider.attachVirtualMachine(VirtualMachineDescriptor vmd)
|
||||
*/
|
||||
public class AttachProvider02 extends AODTestRunner {
|
||||
|
||||
public AttachProvider02(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "Method AttachProvider.providers() returns empty collection");
|
||||
|
||||
String currentVMId = getCurrentVMId();
|
||||
|
||||
for (AttachProvider provider : AttachProvider.providers()) {
|
||||
log.display("Provider: " + provider);
|
||||
log.display("Provider.name(): " + provider.name());
|
||||
log.display("Provider.type(): " + provider.type());
|
||||
|
||||
TestUtils.assertNotNull(provider.name(), "Provider.name() returns null");
|
||||
TestUtils.assertNotNull(provider.type(), "Provider.type() returns null");
|
||||
|
||||
tryAttach(provider, currentVMId, false);
|
||||
|
||||
tryAttach(provider, currentVMId, true);
|
||||
|
||||
tryAttach(provider, targetVMId, false);
|
||||
|
||||
tryAttach(provider, targetVMId, true);
|
||||
}
|
||||
}
|
||||
|
||||
void tryAttach(AttachProvider provider, String vmId, boolean useVMDescriptor) throws Throwable {
|
||||
log.display("Attaching to vm " + vmId + " using " +
|
||||
(useVMDescriptor ? "VirtualMachineDescriptor " : "VM id"));
|
||||
|
||||
VirtualMachine vm;
|
||||
|
||||
if (useVMDescriptor)
|
||||
vm = provider.attachVirtualMachine(new VirtualMachineDescriptor(provider, vmId));
|
||||
else
|
||||
vm = provider.attachVirtualMachine(vmId);
|
||||
|
||||
try {
|
||||
log.display("Attached to vm: " + vm);
|
||||
TestUtils.assertEquals(vm.id(), vmId, "VirtualMachine.id() returns unexpected value for attached vm: " + vm.id());
|
||||
|
||||
// try to use created VirtualMachine
|
||||
|
||||
log.display("Trying to call VirtualMachine.getSystemProperties()");
|
||||
Properties properties = vm.getSystemProperties();
|
||||
TestUtils.assertNotNull(properties, "VirtualMachine.getSystemProperties() returns null");
|
||||
|
||||
TestUtils.assertTrue(properties.size() > 0, "VirtualMachine.getSystemProperties() returns empty collection");
|
||||
} finally {
|
||||
vm.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new AttachProvider02(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,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();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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/VirtualMachine02.
|
||||
* 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 following methods:
|
||||
* - VirtualMachine.attach(String id) (test tries to attach to the VM running test
|
||||
* and to the another VM started by this test)
|
||||
* - VirtualMachine.attach(VirtualMachineDescriptor vmd) (test tries to attach to the VM running test
|
||||
* and to the another VM started by this test)
|
||||
* - VirtualMachine.detach() (test checks that after detaching operations on VirtualMachine throw IOException)
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine02.VirtualMachine02
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData
|
||||
* PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine02.VirtualMachine02
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine02;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.sun.tools.attach.*;
|
||||
import com.sun.tools.attach.spi.AttachProvider;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Test checks following methods:
|
||||
* - VirtualMachine.attach(String) (test tries to attach to current and to another VM)
|
||||
*
|
||||
* - VirtualMachine.attach(VirtualMachineDescriptor) (test tries to attach to current and to another VM)
|
||||
*
|
||||
* - VirtualMachine.detach() (test checks that after detaching operations on VirtualMachine
|
||||
* throw IOException)
|
||||
*/
|
||||
public class VirtualMachine02 extends AODTestRunner {
|
||||
|
||||
public VirtualMachine02(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
log.display("Executing test for current VM");
|
||||
String currentVMId = getCurrentVMId();
|
||||
doTest(currentVMId);
|
||||
log.display("");
|
||||
|
||||
log.display("Executing test for another VM (id = " + targetVMId + ")");
|
||||
doTest(targetVMId);
|
||||
}
|
||||
|
||||
void doTest(String targetVMId) throws Throwable {
|
||||
VirtualMachine vm;
|
||||
|
||||
log.display("Trying to attach using VirtualMachine(\"" + targetVMId + "\")");
|
||||
vm = VirtualMachine.attach(targetVMId);
|
||||
log.display("Attached: " + vm);
|
||||
checkDetach(vm);
|
||||
|
||||
log.display("Trying to attach using VirtualMachine(VirtualMachineDescriptor)");
|
||||
AttachProvider provider;
|
||||
TestUtils.assertTrue(AttachProvider.providers().size() > 0, "AttachProvider.providers() returns empty list");
|
||||
provider = AttachProvider.providers().get(0);
|
||||
log.display("Create VirtualMachineDescriptor using provider '" + provider + "'");
|
||||
VirtualMachineDescriptor vmDescriptor = new VirtualMachineDescriptor(provider, targetVMId);
|
||||
vm = VirtualMachine.attach(vmDescriptor);
|
||||
log.display("Attached: " + vm);
|
||||
TestUtils.assertEquals(vm.provider(), provider, "vm.provider() returns unexpected value: " + vm.provider());
|
||||
checkDetach(vm);
|
||||
}
|
||||
|
||||
void checkDetach(VirtualMachine vm) throws Throwable {
|
||||
log.display("Detaching from " + vm);
|
||||
vm.detach();
|
||||
|
||||
try {
|
||||
vm.getSystemProperties();
|
||||
TestUtils.testFailed("Expected IOException wasn't thrown");
|
||||
} catch (IOException e) {
|
||||
// expected exception
|
||||
}
|
||||
try {
|
||||
vm.getAgentProperties();
|
||||
TestUtils.testFailed("Expected IOException wasn't thrown");
|
||||
} catch (IOException e) {
|
||||
// expected exception
|
||||
}
|
||||
try {
|
||||
vm.loadAgent("agent");
|
||||
TestUtils.testFailed("Expected IOException wasn't thrown");
|
||||
} catch (IOException e) {
|
||||
// expected exception
|
||||
}
|
||||
try {
|
||||
vm.loadAgentLibrary("agent");
|
||||
TestUtils.testFailed("Expected IOException wasn't thrown");
|
||||
} catch (IOException e) {
|
||||
// expected exception
|
||||
}
|
||||
try {
|
||||
vm.loadAgentPath("agent");
|
||||
TestUtils.testFailed("Expected IOException wasn't thrown");
|
||||
} catch (IOException e) {
|
||||
// expected exception
|
||||
}
|
||||
|
||||
// shouldn't throw exception
|
||||
log.display("Trying to call detach one more time for " + vm);
|
||||
vm.detach();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine02(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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/VirtualMachine03.
|
||||
* 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 semantics of the method VirtualMachine.equals(Object obj).
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine03.VirtualMachine03
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -Djdk.attach.allowAttachSelf -XX:+UsePerfData
|
||||
* PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine03.VirtualMachine03
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine03;
|
||||
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Test checks method VirtualMachine.equals(Object)
|
||||
*/
|
||||
public class VirtualMachine03 extends AODTestRunner {
|
||||
|
||||
public VirtualMachine03(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
String currentVMId = getCurrentVMId();
|
||||
|
||||
VirtualMachine vm1 = VirtualMachine.attach(currentVMId);
|
||||
|
||||
VirtualMachine vm2 = VirtualMachine.attach(targetVMId);
|
||||
|
||||
try {
|
||||
TestUtils.assertEquals(vm1.id(), currentVMId, "vm.id() returns unexpected value: " + vm1.id());
|
||||
|
||||
TestUtils.assertEquals(vm2.id(), targetVMId, "vm.id() returns unexpected value: " + vm2.id());
|
||||
|
||||
TestUtils.assertTrue(!vm1.equals(vm2), vm1 + ".equals(" + vm2 + ") returns 'true'");
|
||||
|
||||
checkVM(vm1);
|
||||
|
||||
checkVM(vm2);
|
||||
} finally {
|
||||
vm1.detach();
|
||||
|
||||
vm2.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void checkVM(VirtualMachine vm1) throws Throwable {
|
||||
TestUtils.assertEquals(vm1, vm1, "vm.equals(itself) returns 'false'");
|
||||
|
||||
// create one more VirtualMachine object for the same VM
|
||||
VirtualMachine vm2 = VirtualMachine.attach(vm1.id());
|
||||
try {
|
||||
TestUtils.assertEquals(vm1, vm2, vm1 + ".equals(" + vm2 + ") returns 'false'");
|
||||
|
||||
TestUtils.assertTrue(vm1.hashCode() == vm2.hashCode(), "vm.hashCode() returns different values for " + vm1 + " and " + vm2);
|
||||
|
||||
TestUtils.assertEquals(vm1.provider(), vm2.provider(), "vm.provider() returns non-equals objects for " + vm1 + " and " + vm2);
|
||||
} finally {
|
||||
vm2.detach();
|
||||
}
|
||||
|
||||
TestUtils.assertTrue(!vm1.equals(new String()), "vm.equals(String) returns 'true'");
|
||||
|
||||
TestUtils.assertTrue(!vm1.equals(null), "vm.equals(null) returns 'true'");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine03(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine04;
|
||||
|
||||
import nsk.share.TestBug;
|
||||
import nsk.share.aod.DummyTargetApplication;
|
||||
|
||||
/*
|
||||
* This target application during initialization sets special system property,
|
||||
* main test application tries to get this property using VirtualMachine.getSystemProperties()
|
||||
*/
|
||||
public class VM04Target extends DummyTargetApplication {
|
||||
|
||||
static String testPropertyKey = "VirtualMachine04_testPropertyKey";
|
||||
|
||||
static String testPropertyValue = "VirtualMachine04_testPropertyValue";
|
||||
|
||||
static String changedTestPropertyValue = "VirtualMachine04_testPropertyValue_changed";
|
||||
|
||||
VM04Target(String[] args) {
|
||||
super(args);
|
||||
|
||||
log.display("Setting property " + testPropertyKey + " = " + testPropertyValue);
|
||||
System.setProperty(testPropertyKey, testPropertyValue);
|
||||
}
|
||||
|
||||
protected void targetApplicationActions() {
|
||||
String signal = pipe.readln();
|
||||
log.display("Received signal: " + signal);
|
||||
if (!signal.equals(VirtualMachine04.SIGNAL_CHANGE_PROPERTY))
|
||||
throw new TestBug("Received unexpected signal: " + signal);
|
||||
|
||||
log.display("Setting property " + testPropertyKey + " = " + changedTestPropertyValue);
|
||||
System.setProperty(testPropertyKey, changedTestPropertyValue);
|
||||
|
||||
log.display("Sending signal " + VirtualMachine04.SIGNAL_PROPERTY_CHANGED);
|
||||
pipe.println(VirtualMachine04.SIGNAL_PROPERTY_CHANGED);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VM04Target(args).runTargetApplication();
|
||||
}
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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/VirtualMachine04.
|
||||
* 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 following methods:
|
||||
* - VirtualMachine.getSystemProperties() (test checks that returned properties contains
|
||||
* expected property and tested method returns properties whose key and value is a String)
|
||||
* - VirtualMachine.getAgentProperties() (test checks that method returns properties whose
|
||||
* key and value is a String)
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine04
|
||||
* nsk.aod.VirtualMachine.VirtualMachine04.VM04Target
|
||||
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine04
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.aod.VirtualMachine.VirtualMachine04.VM04Target
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine04;
|
||||
|
||||
import java.util.Properties;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import nsk.share.aod.AODTestRunner;
|
||||
import nsk.share.test.TestUtils;
|
||||
import nsk.share.*;
|
||||
|
||||
/*
|
||||
* Test checks following methods:
|
||||
* - VirtualMachine.getSystemProperties()
|
||||
*
|
||||
* - VirtualMachine.getAgentProperties()
|
||||
*/
|
||||
public class VirtualMachine04 extends AODTestRunner {
|
||||
|
||||
static final String SIGNAL_CHANGE_PROPERTY = "change_property";
|
||||
|
||||
static final String SIGNAL_PROPERTY_CHANGED = "property_changed";
|
||||
|
||||
public VirtualMachine04(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
VirtualMachine vm = VirtualMachine.attach(targetVMId);
|
||||
|
||||
try {
|
||||
checkSystemProperties(vm, VM04Target.testPropertyKey, VM04Target.testPropertyValue);
|
||||
|
||||
log.display("Sending signal " + SIGNAL_CHANGE_PROPERTY);
|
||||
pipe.println(SIGNAL_CHANGE_PROPERTY);
|
||||
String signal = pipe.readln();
|
||||
log.display("Received signal " + signal);
|
||||
if (!signal.equals(SIGNAL_PROPERTY_CHANGED))
|
||||
throw new TestBug("Unexpected signal received: " + signal);
|
||||
|
||||
checkSystemProperties(vm, VM04Target.testPropertyKey, VM04Target.changedTestPropertyValue);
|
||||
|
||||
Properties properties = vm.getAgentProperties();
|
||||
System.out.println("VirtualMachine.getAgentProperties(): " + properties);
|
||||
checkProperties(properties);
|
||||
} finally {
|
||||
vm.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void checkSystemProperties(VirtualMachine vm,
|
||||
String propertyToCheck,
|
||||
String expectedPropertyValue) throws Throwable {
|
||||
|
||||
Properties properties = vm.getSystemProperties();
|
||||
System.out.println("VirtualMachine.getSystemProperties(): " + properties);
|
||||
checkProperties(properties);
|
||||
|
||||
String checkedPropertyValue = properties.getProperty(propertyToCheck);
|
||||
TestUtils.assertNotNull(checkedPropertyValue, "Properties doesn't contain property '" + propertyToCheck + "'");
|
||||
TestUtils.assertEquals(checkedPropertyValue, expectedPropertyValue,
|
||||
"Unexpected value of the property '" + propertyToCheck + "': " + checkedPropertyValue + ", expected value is '" + expectedPropertyValue + "'");
|
||||
}
|
||||
|
||||
/*
|
||||
* Check following spec clause: VirtualMachine.getSystemProperties() and
|
||||
* VirtualMachine.getAgentProperties() return the properties whose key and value is a String
|
||||
*/
|
||||
void checkProperties(Properties properties) {
|
||||
TestUtils.assertNotNull(properties, "Method returns null Properties");
|
||||
|
||||
for (Object key : properties.keySet()) {
|
||||
Object value = properties.get(key);
|
||||
log.display("Value of '" + key + "' = " + value);
|
||||
|
||||
TestUtils.assertTrue(key instanceof String, "Property key isn't String: " + key.getClass().getName());
|
||||
|
||||
TestUtils.assertTrue(value instanceof String, "Property value isn't String: " + value.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine04(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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/VirtualMachine05.
|
||||
* 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.
|
||||
* This test checks that method VirtualMachine.list() returns
|
||||
* VirtualMachineDescriptors for 2 VMs started by this test.
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine05.VirtualMachine05
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine05.VirtualMachine05
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine05;
|
||||
|
||||
import java.util.List;
|
||||
import com.sun.tools.attach.*;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Test checks method VirtualMachine.list()
|
||||
* (test checks that collection returned by VirtualMachine.list() contains current VM
|
||||
* and another VM started by this test)
|
||||
*/
|
||||
public class VirtualMachine05 extends AODTestRunner {
|
||||
|
||||
public VirtualMachine05(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
String currentVMId = getCurrentVMId();
|
||||
|
||||
log.display("Checking VirtualMachine.list()");
|
||||
checkList(VirtualMachine.list(), currentVMId, targetVMId);
|
||||
}
|
||||
|
||||
private void checkList(List<VirtualMachineDescriptor> vmDescriptors, String currentVMId, String targetVMId) {
|
||||
VirtualMachineDescriptor currentVM = null;
|
||||
VirtualMachineDescriptor targetVM = null;
|
||||
|
||||
for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {
|
||||
log.display("VirtualMachineDescriptor: " + vmDescriptor);
|
||||
|
||||
if (vmDescriptor.id().equals(currentVMId)) {
|
||||
currentVM = vmDescriptor;
|
||||
} else if (vmDescriptor.id().equals(targetVMId)) {
|
||||
targetVM = vmDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
TestUtils.assertNotNull(currentVM, "VirtualMachine.list() didn't return descriptor for the current VM");
|
||||
|
||||
TestUtils.assertNotNull(targetVM, "VirtualMachine.list() didn't return descriptor for VM with id '" +
|
||||
targetVMId + "'");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine05(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine06;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
import nsk.share.aod.TargetApplicationWaitingAgents;
|
||||
|
||||
public class VM06Agent00 {
|
||||
public static void agentmain(String options, Instrumentation inst) {
|
||||
boolean success = true;
|
||||
|
||||
TargetApplicationWaitingAgents.agentLoaded(VM06Agent00.class.getName());
|
||||
try {
|
||||
System.out.println("Agent options: " + options);
|
||||
if (options != null) {
|
||||
success = false;
|
||||
System.out.println("ERROR: unexpected non-null options");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
success = false;
|
||||
System.out.println("Unexpected exception: " + t);
|
||||
} finally {
|
||||
TargetApplicationWaitingAgents.agentFinished(VM06Agent00.class.getName(), success);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Agent-Class: nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent00
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine06;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
import nsk.share.aod.TargetApplicationWaitingAgents;
|
||||
|
||||
public class VM06Agent01 {
|
||||
public static void agentmain(String options, Instrumentation inst) {
|
||||
boolean success = true;
|
||||
|
||||
TargetApplicationWaitingAgents.agentLoaded(VM06Agent01.class.getName());
|
||||
try {
|
||||
System.out.println("Agent options: " + options);
|
||||
if (options != null) {
|
||||
success = false;
|
||||
System.out.println("ERROR: unexpected non-null options");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
success = false;
|
||||
System.out.println("Unexpected exception: " + t);
|
||||
} finally {
|
||||
TargetApplicationWaitingAgents.agentFinished(VM06Agent01.class.getName(), success);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Agent-Class: nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent01
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine06;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
import nsk.share.aod.TargetApplicationWaitingAgents;
|
||||
|
||||
public class VM06Agent02 {
|
||||
public static void agentmain(String options, Instrumentation inst) {
|
||||
boolean success = true;
|
||||
|
||||
TargetApplicationWaitingAgents.agentLoaded(VM06Agent02.class.getName());
|
||||
try {
|
||||
System.out.println("Agent options: " + options);
|
||||
if (options == null || !options.equals("VirtualMachine06_TestOptions")) {
|
||||
success = false;
|
||||
System.out.println("ERROR: unexpected non-null options");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
success = false;
|
||||
System.out.println("Unexpected exception: " + t);
|
||||
} finally {
|
||||
TargetApplicationWaitingAgents.agentFinished(VM06Agent02.class.getName(), success);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Agent-Class: nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent02
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine06;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
|
||||
import nsk.share.aod.TargetApplicationWaitingAgents;
|
||||
|
||||
public class VM06Agent03 {
|
||||
public static void agentmain(String options, Instrumentation inst) {
|
||||
TargetApplicationWaitingAgents.agentLoaded(VM06Agent03.class.getName());
|
||||
TargetApplicationWaitingAgents.agentFinished(VM06Agent03.class.getName(), true);
|
||||
|
||||
throw new RuntimeException("Test exception");
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Agent-Class: nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent03
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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/VirtualMachine06.
|
||||
* 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.
|
||||
* This test checks methods VirtualMachine.loadAgent(String agent) and
|
||||
* VirtualMachine.loadAgent(String agent, String options).
|
||||
* Test checks following cases:
|
||||
* - it is possible to pass options to agent using loadAgent(String agent, String options)
|
||||
* - it is possible to specify null options (in this case null is passed to the agentmain)
|
||||
* - if agent throws exception from 'agentmain' VirtualMachine.loadAgent throws AgentInitializationException
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
*
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
*
|
||||
* @comment compile VM06Agent0[0-3].java to current directory
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent00
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent01
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent02
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent03
|
||||
* @run driver ClassFileInstaller
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent00
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent01
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent02
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VM06Agent03
|
||||
*
|
||||
* @comment create VM06Agent0[0-3].jar in current directory
|
||||
* @build ExecDriver
|
||||
* @run driver PropertyResolvingWrapper ExecDriver --cmd
|
||||
* ${test.jdk}/bin/jar -cmf VM06Agent00.mf VM06Agent00.jar
|
||||
* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent00.class
|
||||
* @run driver PropertyResolvingWrapper ExecDriver --cmd
|
||||
* ${test.jdk}/bin/jar -cmf VM06Agent01.mf VM06Agent01.jar
|
||||
* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent01.class
|
||||
* @run driver PropertyResolvingWrapper ExecDriver --cmd
|
||||
* ${test.jdk}/bin/jar -cmf VM06Agent02.mf VM06Agent02.jar
|
||||
* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent02.class
|
||||
* @run driver PropertyResolvingWrapper ExecDriver --cmd
|
||||
* ${test.jdk}/bin/jar -cmf VM06Agent03.mf VM06Agent03.jar
|
||||
* nsk/aod/VirtualMachine/VirtualMachine06/VM06Agent03.class
|
||||
*
|
||||
*
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine06.VirtualMachine06
|
||||
* nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine06.VirtualMachine06
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* -ja VM06Agent00.jar,VM06Agent01.jar,VM06Agent02.jar,VM06Agent03.jar
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine06;
|
||||
|
||||
import nsk.share.TestBug;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
import java.util.*;
|
||||
import com.sun.tools.attach.*;
|
||||
|
||||
/*
|
||||
* Test checks following methods:
|
||||
* - VirtualMachine.loadAgent(String)
|
||||
*
|
||||
* - VirtualMachine.loadAgent(String, String)
|
||||
*/
|
||||
public class VirtualMachine06 extends AODTestRunner {
|
||||
|
||||
public VirtualMachine06(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
// check that all required parameters were passed to the test
|
||||
List<AgentInformation> agents = argParser.getAgents();
|
||||
if (agents.size() != 4)
|
||||
throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified");
|
||||
|
||||
for (AgentInformation agent : agents) {
|
||||
if (!agent.jarAgent)
|
||||
throw new TestBug("Non JAR agent was specified");
|
||||
}
|
||||
|
||||
VirtualMachine vm = VirtualMachine.attach(targetVMId);
|
||||
|
||||
try {
|
||||
AgentInformation agent;
|
||||
|
||||
agent = agents.get(0);
|
||||
log.display("Loading '" + agent.pathToAgent + "'");
|
||||
// pass null options to agent
|
||||
vm.loadAgent(agent.pathToAgent);
|
||||
|
||||
agent = agents.get(1);
|
||||
log.display("Loading '" + agent.pathToAgent + "'");
|
||||
// pass null options to agent
|
||||
vm.loadAgent(agent.pathToAgent, null);
|
||||
|
||||
agent = agents.get(2);
|
||||
log.display("Loading '" + agent.pathToAgent + "'");
|
||||
// pass non-null options to agent
|
||||
vm.loadAgent(agent.pathToAgent, "VirtualMachine06_TestOptions");
|
||||
|
||||
agent = agents.get(3);
|
||||
log.display("Loading '" + agent.pathToAgent + "' (this agent throws exception from agentmain)");
|
||||
try {
|
||||
// check agent throwing exception from agentmain
|
||||
vm.loadAgent(agent.pathToAgent);
|
||||
TestUtils.testFailed("Expected AgentInitializationException wasn't thrown");
|
||||
} catch (AgentInitializationException e) {
|
||||
// expected exception
|
||||
}
|
||||
} finally {
|
||||
vm.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine06(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* 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/VirtualMachine07.
|
||||
* 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.
|
||||
* This test checks methods VirtualMachine.loadAgentLibrary(String agent) and
|
||||
* VirtualMachine.loadAgentLibrary(String agent, String options).
|
||||
* Test checks following cases:
|
||||
* - it is possible to pass options to agent using loadAgentLibrary(String agent, String options)
|
||||
* - it is possible to specify null options (in this case zero-length is passed to the Agent_OnAttach)
|
||||
* - if Agent_OnAttach returns error code loadAgentLibrary throws AgentInitializationException and
|
||||
* AgentInitializationException.returnValue() returns this error code
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07
|
||||
* nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* -na VirtualMachine07agent00,VirtualMachine07agent01,VirtualMachine07agent02,VirtualMachine07agent03
|
||||
* -testedMethod loadAgentLibrary
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine07;
|
||||
|
||||
import nsk.share.*;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.tools.attach.*;
|
||||
|
||||
/*
|
||||
* Test is written to test following methods:
|
||||
* - VirtualMachine.loadAgentLibrary
|
||||
*
|
||||
* - VirtualMachine.loadAgentPath
|
||||
*
|
||||
*(method to test is specified via command line parameter 'testedMethod')
|
||||
*/
|
||||
public class VirtualMachine07 extends AODTestRunner {
|
||||
|
||||
static class ArgParser extends AODRunnerArgParser {
|
||||
|
||||
final String testedMethodOpt = "testedMethod";
|
||||
|
||||
ArgParser(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
protected boolean checkOption(String option, String value) {
|
||||
if (super.checkOption(option, value))
|
||||
return true;
|
||||
|
||||
if (option.equals(testedMethodOpt)) {
|
||||
if (value.equals("loadAgentLibrary") || value.equals("loadAgentPath"))
|
||||
return true;
|
||||
else
|
||||
throw new TestBug("Unexpected value of '" + testedMethodOpt + "': " + value);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void checkOptions() {
|
||||
super.checkOptions();
|
||||
|
||||
// if test loadAgentPath parameter arch is needed
|
||||
if (!testLoadAgentLibrary()) {
|
||||
if (!options.containsKey("arch"))
|
||||
throw new TestBug("Option 'arch' wasn't specified");
|
||||
}
|
||||
}
|
||||
|
||||
boolean testLoadAgentLibrary() {
|
||||
return options.getProperty(testedMethodOpt).equals("loadAgentLibrary");
|
||||
}
|
||||
}
|
||||
|
||||
public VirtualMachine07(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
/*
|
||||
* When test method loadAgentPath platform specific agent name should be
|
||||
* created (lib<agent>.so for unix, lib<agent>.dylib for macosx and
|
||||
* <agent>.dll for windows)
|
||||
*/
|
||||
protected String expandAgentPath(String path) {
|
||||
int index = path.lastIndexOf('/');
|
||||
if (index < 0)
|
||||
throw new TestBug("Unexpected agent library name format");
|
||||
|
||||
String dir = path.substring(0, index);
|
||||
String libName = path.substring(index + 1);
|
||||
|
||||
if (argParser.getArch().startsWith("windows")) {
|
||||
return dir + "/" + libName + ".dll";
|
||||
} else if (argParser.getArch().startsWith("mac")) {
|
||||
return dir + "/" + "lib" + libName + ".dylib";
|
||||
} else {
|
||||
return dir + "/" + "lib" + libName + ".so";
|
||||
}
|
||||
}
|
||||
|
||||
protected AODRunnerArgParser createArgParser(String[] args) {
|
||||
return new ArgParser(args);
|
||||
}
|
||||
|
||||
protected void loadAgent(VirtualMachine vm, String agent) throws Throwable {
|
||||
boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary();
|
||||
|
||||
if (testLoadAgentLibrary)
|
||||
log.display("Test method VirtualMachine.loadAgentLibrary");
|
||||
else
|
||||
log.display("Test method VirtualMachine.loadAgentPath");
|
||||
|
||||
if (testLoadAgentLibrary) {
|
||||
log.display("Loading '" + agent + "'");
|
||||
vm.loadAgentLibrary(agent);
|
||||
} else {
|
||||
String expandedName = (agent == null ? null : expandAgentPath(agent));
|
||||
log.display("Loading '" + expandedName + "'");
|
||||
vm.loadAgentPath(expandedName);
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadAgent(VirtualMachine vm, String agent, String options) throws Throwable {
|
||||
boolean testLoadAgentLibrary = ((ArgParser) argParser).testLoadAgentLibrary();
|
||||
|
||||
if (testLoadAgentLibrary)
|
||||
log.display("Test method VirtualMachine.loadAgentLibrary");
|
||||
else
|
||||
log.display("Test method VirtualMachine.loadAgentPath");
|
||||
|
||||
if (testLoadAgentLibrary) {
|
||||
log.display("Loading '" + agent + "'");
|
||||
vm.loadAgentLibrary(agent, options);
|
||||
} else {
|
||||
String expandedName = (agent == null ? null : expandAgentPath(agent));
|
||||
log.display("Loading '" + expandedName + "'");
|
||||
vm.loadAgentPath(expandedName, options);
|
||||
}
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
// check that all required parameters were passed to the test
|
||||
List<AgentInformation> agents = argParser.getAgents();
|
||||
if (agents.size() != 4)
|
||||
throw new TestBug("Test requires 4 agents, actually " + agents.size() + " were specified");
|
||||
|
||||
for (AgentInformation agent : agents) {
|
||||
if (agent.jarAgent)
|
||||
throw new TestBug("Non native agent was specified");
|
||||
}
|
||||
|
||||
VirtualMachine vm = VirtualMachine.attach(targetVMId);
|
||||
|
||||
try {
|
||||
AgentInformation agent;
|
||||
|
||||
agent = agents.get(0);
|
||||
loadAgent(vm, agent.pathToAgent);
|
||||
|
||||
agent = agents.get(1);
|
||||
loadAgent(vm, agent.pathToAgent, null);
|
||||
|
||||
agent = agents.get(2);
|
||||
loadAgent(vm, agent.pathToAgent, "VirtualMachine_TestOptions");
|
||||
|
||||
agent = agents.get(3);
|
||||
log.display("Loading '" + agent.pathToAgent + "' (this agent fails to initialize)");
|
||||
try {
|
||||
loadAgent(vm, agent.pathToAgent);
|
||||
|
||||
TestUtils.testFailed("Expected AgentInitializationException wasn't thrown");
|
||||
} catch (AgentInitializationException e) {
|
||||
log.display("Expected AgentInitializationException was caught");
|
||||
log.display("AgentInitializationException.returnValue(): " + e.returnValue());
|
||||
TestUtils.assertEquals(e.returnValue(), 10,
|
||||
"AgentInitializationException.returnValue() returns unexpected value: " + e.returnValue()+ ", expected value is 10");
|
||||
}
|
||||
} finally {
|
||||
vm.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine07(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <aod.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AGENT_NAME "VMNativeAgent00"
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
JNIEnv* jni;
|
||||
int success = 1;
|
||||
|
||||
// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here
|
||||
|
||||
if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
|
||||
return JNI_ERR;
|
||||
|
||||
printf("%s: initialization was done\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
|
||||
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, AGENT_NAME)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (optionsString == NULL) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected null options\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
} else {
|
||||
size_t length = strlen(optionsString);
|
||||
if (length != 0) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected non-zero length options string: '%s'\n", AGENT_NAME, optionsString);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
nsk_aod_agentFinished(jni, AGENT_NAME, success);
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <aod.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AGENT_NAME "VMNativeAgent01"
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
JNIEnv* jni;
|
||||
int success = 1;
|
||||
|
||||
// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here
|
||||
|
||||
if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
|
||||
return JNI_ERR;
|
||||
|
||||
printf("%s: initialization was done\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
|
||||
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, AGENT_NAME)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (optionsString == NULL) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected null options\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
} else {
|
||||
size_t length = strlen(optionsString);
|
||||
if (length != 0) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected non-zero length options string: '%s'\n", AGENT_NAME, optionsString);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
nsk_aod_agentFinished(jni, AGENT_NAME, success);
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <aod.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AGENT_NAME "VMNativeAgent02"
|
||||
|
||||
#define EXPECTED_OPTIONS "VirtualMachine_TestOptions"
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
JNIEnv* jni;
|
||||
int success = 1;
|
||||
|
||||
// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here
|
||||
|
||||
if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
|
||||
return JNI_ERR;
|
||||
|
||||
printf("%s: initialization was done\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
|
||||
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, AGENT_NAME)))
|
||||
return JNI_ERR;
|
||||
|
||||
if (optionsString == NULL) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected null options\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
} else {
|
||||
if (strcmp(optionsString, EXPECTED_OPTIONS)) {
|
||||
success = 0;
|
||||
printf("%s: ERROR: unexpected options string: '%s', expected is '%s'\n",
|
||||
AGENT_NAME, optionsString, EXPECTED_OPTIONS);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
nsk_aod_agentFinished(jni, AGENT_NAME, success);
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <aod.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AGENT_NAME "VMNativeAgent03"
|
||||
|
||||
#define ON_ATTACH_EXIT_CODE 10
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
JNIEnv* jni;
|
||||
|
||||
if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
|
||||
return JNI_ERR;
|
||||
|
||||
// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here
|
||||
|
||||
printf("%s: initialization was done\n", AGENT_NAME);
|
||||
fflush(stdout);
|
||||
|
||||
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, AGENT_NAME)))
|
||||
return JNI_ERR;
|
||||
|
||||
nsk_aod_agentFinished(jni, AGENT_NAME, 1);
|
||||
|
||||
printf("%s: warning: agent is intentionally exiting from Agent_OnAttach with error code %d\n", AGENT_NAME, ON_ATTACH_EXIT_CODE);
|
||||
fflush(stdout);
|
||||
|
||||
return ON_ATTACH_EXIT_CODE;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#include "aod.c"
|
||||
#include "jni_tools.c"
|
||||
#include "nsk_tools.c"
|
||||
#include "agent00.c"
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#include "aod.c"
|
||||
#include "jni_tools.c"
|
||||
#include "nsk_tools.c"
|
||||
#include "agent01.c"
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#include "aod.c"
|
||||
#include "jni_tools.c"
|
||||
#include "nsk_tools.c"
|
||||
#include "agent02.c"
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#include "aod.c"
|
||||
#include "jni_tools.c"
|
||||
#include "nsk_tools.c"
|
||||
#include "agent03.c"
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 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/VirtualMachine08.
|
||||
* 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.
|
||||
* This test checks methods VirtualMachine.loadAgentPath(String agent) and
|
||||
* VirtualMachine.loadAgentPath(String agent, String options).
|
||||
* Test checks following cases:
|
||||
* - it is possible to pass options to agent using loadAgentPath(String agent, String options)
|
||||
* - it is possible to specify null options (in this case zero-length is passed to the Agent_OnAttach)
|
||||
* - if Agent_OnAttach returns error code loadAgentPath throws AgentInitializationException and
|
||||
* AgentInitializationException.returnValue() returns this error code
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07
|
||||
* nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.TargetApplicationWaitingAgents
|
||||
* -na ${test.nativepath}/VirtualMachine07agent00,${test.nativepath}/VirtualMachine07agent01,${test.nativepath}/VirtualMachine07agent02,${test.nativepath}/VirtualMachine07agent03
|
||||
* -testedMethod loadAgentPath
|
||||
* -arch ${os.family}-${os.simpleArch}
|
||||
*/
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package nsk.aod.VirtualMachine.VirtualMachine09;
|
||||
|
||||
import nsk.share.aod.TargetApplicationWaitingAgents;
|
||||
|
||||
public class VM09Target {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.loadLibrary("VirtualMachine09agent00");
|
||||
System.out.println("Agent library was loaded");
|
||||
|
||||
new TargetApplicationWaitingAgents().runTargetApplication(args);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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/VirtualMachine09.
|
||||
* 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.
|
||||
* This test checks method VirtualMachine.loadAgentLibrary(String agent).
|
||||
* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded
|
||||
* prior to invoking this method". In this test the same agent library first loaded via VM command line
|
||||
* option 'agentlib:', then it is loaded using method 'System.loadLibrary' and than dynamically attached.
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09
|
||||
* nsk.aod.VirtualMachine.VirtualMachine09.VM09Target
|
||||
* @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.aod.VirtualMachine.VirtualMachine09.VM09Target
|
||||
* -na VirtualMachine09agent00
|
||||
* -testedMethod loadAgentLibrary
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachine.VirtualMachine09;
|
||||
|
||||
import nsk.aod.VirtualMachine.VirtualMachine07.VirtualMachine07;
|
||||
import nsk.share.TestBug;
|
||||
import nsk.share.aod.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.tools.attach.*;
|
||||
|
||||
/*
|
||||
* Test checks methods VirtualMachine.loadAgentLib and VirtualMachineloadAgentPath.
|
||||
*
|
||||
* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded
|
||||
* prior to invoking this method"
|
||||
*/
|
||||
public class VirtualMachine09 extends VirtualMachine07 {
|
||||
|
||||
public VirtualMachine09(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
// check that all required parameters were passed to the test
|
||||
List<AgentInformation> agents = argParser.getAgents();
|
||||
if (agents.size() != 1)
|
||||
throw new TestBug("Test requires 1 agent, actually " + agents.size() + " were specified");
|
||||
|
||||
for (AgentInformation agent : agents) {
|
||||
if (agent.jarAgent)
|
||||
throw new TestBug("Non native agent was specified");
|
||||
}
|
||||
|
||||
VirtualMachine vm = VirtualMachine.attach(targetVMId);
|
||||
|
||||
try {
|
||||
AgentInformation agent;
|
||||
agent = agents.get(0);
|
||||
loadAgent(vm, agent.pathToAgent, agent.agentOptions);
|
||||
} finally {
|
||||
vm.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachine09(args).runTest();
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jni.h>
|
||||
#include <aod.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded
|
||||
* prior to invoking this method"
|
||||
*
|
||||
* This agent is loaded as static agent via 'agentlib:' VM option and also dynamically attached, so this agent
|
||||
* has both Agent_OnLoad and Agent_OnAttach.
|
||||
*/
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
// can't use NSK_DISPLAY since needed for nsk_ functions initialization isn't done here
|
||||
printf("Agent_OnLoad: agent is loaded\n");
|
||||
fflush(stdout);
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Agent_OnAttach(JavaVM *vm, char *optionsString, void *reserved) {
|
||||
JNIEnv* jni = NULL;
|
||||
Options* options = NULL;
|
||||
const char* agentName;
|
||||
|
||||
if (!NSK_VERIFY((options = (Options*) nsk_aod_createOptions(optionsString)) != NULL))
|
||||
return JNI_ERR;
|
||||
|
||||
agentName = nsk_aod_getOptionValue(options, NSK_AOD_AGENT_NAME_OPTION);
|
||||
|
||||
if ((jni = (JNIEnv*) nsk_aod_createJNIEnv(vm)) == NULL)
|
||||
return JNI_ERR;
|
||||
|
||||
NSK_DISPLAY1("%s: initialization was done\n", agentName);
|
||||
|
||||
if (!NSK_VERIFY(nsk_aod_agentLoaded(jni, agentName)))
|
||||
return JNI_ERR;
|
||||
|
||||
nsk_aod_agentFinished(jni, agentName, 1);
|
||||
|
||||
return JNI_OK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
|
||||
#include "aod.c"
|
||||
#include "jni_tools.c"
|
||||
#include "nsk_tools.c"
|
||||
#include "agent00.c"
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 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/VirtualMachine10.
|
||||
* 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.
|
||||
* This test checks method VirtualMachine.loadAgentPath(String agent).
|
||||
* Test checks following spec clause: "Agent_OnAttach function is invoked even if the agent library was loaded
|
||||
* prior to invoking this method". In this test the same agent library first loaded via VM command line
|
||||
* option 'agentlib:', then it is loaded using method 'System.loadLibrary' and than dynamically attached.
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09
|
||||
* nsk.aod.VirtualMachine.VirtualMachine09.VM09Target
|
||||
* @run main/othervm/native -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachine.VirtualMachine09.VirtualMachine09
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-agentlib:VirtualMachine09agent00 -XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.aod.VirtualMachine.VirtualMachine09.VM09Target
|
||||
* -na ${test.nativepath}/VirtualMachine09agent00
|
||||
* -testedMethod loadAgentPath
|
||||
* -arch ${os.family}-${os.simpleArch}
|
||||
*/
|
||||
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* 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/VirtualMachineDescriptor/VirtualMachineDescriptor01.
|
||||
* 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.
|
||||
* This is sanity test for class VirtualMachineDescriptor.
|
||||
* Test checks that its methods toString(), displayName(), id(), provider() return
|
||||
* non-null values and also test checks semantics of the method VirtualMachineDescriptor.equals(Object obj).
|
||||
* Tested VirtualMachineDescriptors are obtained using VirtualMachine.list()
|
||||
*
|
||||
* @library /vmTestbase /test/hotspot/jtreg/vmTestbase
|
||||
* /test/lib
|
||||
* @run driver jdk.test.lib.FileInstaller . .
|
||||
* @build nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01.VirtualMachineDescriptor01
|
||||
* nsk.share.aod.DummyTargetApplication
|
||||
* @run main/othervm -XX:+UsePerfData PropertyResolvingWrapper
|
||||
* nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01.VirtualMachineDescriptor01
|
||||
* -jdk ${test.jdk}
|
||||
* "-javaOpts=-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"
|
||||
* -target nsk.share.aod.DummyTargetApplication
|
||||
*/
|
||||
|
||||
package nsk.aod.VirtualMachineDescriptor.VirtualMachineDescriptor01;
|
||||
|
||||
import com.sun.tools.attach.*;
|
||||
import com.sun.tools.attach.spi.AttachProvider;
|
||||
import nsk.share.aod.*;
|
||||
import nsk.share.test.TestUtils;
|
||||
|
||||
/*
|
||||
* Basic sanity checks for class com.sun.tools.attach.VirtualMachineDescriptor
|
||||
*/
|
||||
public class VirtualMachineDescriptor01 extends AODTestRunner {
|
||||
|
||||
public VirtualMachineDescriptor01(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
public void doTestActions(String targetVMId) throws Throwable {
|
||||
String currentVMId = getCurrentVMId();
|
||||
|
||||
VirtualMachineDescriptor currentVMDesc = null;
|
||||
VirtualMachineDescriptor targetVMDesc = null;
|
||||
|
||||
for (VirtualMachineDescriptor vmDescriptor : VirtualMachine.list()) {
|
||||
log.display("VirtualMachineDescriptor: " + vmDescriptor);
|
||||
log.display("VirtualMachineDescriptor.displayName(): " + vmDescriptor.displayName());
|
||||
log.display("VirtualMachineDescriptor.id(): " + vmDescriptor.id());
|
||||
log.display("VirtualMachineDescriptor.provider(): " + vmDescriptor.provider());
|
||||
|
||||
TestUtils.assertNotNull(vmDescriptor.toString(), "VirtualMachineDescriptor.toString() returns null");
|
||||
TestUtils.assertNotNull(vmDescriptor.displayName(), "VirtualMachineDescriptor.displayName() returns null");
|
||||
TestUtils.assertNotNull(vmDescriptor.id(), "VirtualMachineDescriptor.id() returns null");
|
||||
TestUtils.assertNotNull(vmDescriptor.provider(), "VirtualMachineDescriptor.provider() returns null");
|
||||
|
||||
TestUtils.assertTrue(AttachProvider.providers().contains(vmDescriptor.provider()),
|
||||
"AttachProvider.providers() doesn't contain provider '" + vmDescriptor.provider() + "'");
|
||||
|
||||
if (vmDescriptor.id().equals(currentVMId)) {
|
||||
currentVMDesc = vmDescriptor;
|
||||
} else if (vmDescriptor.id().equals(targetVMId)) {
|
||||
targetVMDesc = vmDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
TestUtils.assertNotNull(currentVMDesc, "VirtualMachine.list() didn't return descriptor for the current VM");
|
||||
TestUtils.assertNotNull(targetVMDesc, "VirtualMachine.list() didn't return descriptor for VM with id '" + targetVMId + "'");
|
||||
|
||||
TestUtils.assertTrue(!currentVMDesc.equals(targetVMDesc),
|
||||
"VirtualMachineDescriptor.equals() returns 'true' for '" + currentVMDesc + "' and '" + targetVMDesc + "'");
|
||||
TestUtils.assertTrue(currentVMDesc.hashCode() != targetVMDesc.hashCode(),
|
||||
"VirtualMachineDescriptor.hashCode() returns the same value (" + currentVMDesc.hashCode() + ")" + " for '"
|
||||
+ currentVMDesc + "' and '" + targetVMDesc + "'");
|
||||
|
||||
VirtualMachine targetVM = VirtualMachine.attach(targetVMDesc);
|
||||
|
||||
try {
|
||||
// create another VirtualMachineDescriptor for target VM
|
||||
VirtualMachineDescriptor targetVMDesc2 = new VirtualMachineDescriptor(targetVM.provider(), targetVM.id());
|
||||
|
||||
TestUtils.assertEquals(targetVMDesc, targetVMDesc2,
|
||||
"VirtualMachineDescriptor.equals() returns 'false' for '" + targetVMDesc + "' and '" + targetVMDesc2 + "'");
|
||||
|
||||
TestUtils.assertEquals(targetVMDesc.hashCode(), targetVMDesc2.hashCode(),
|
||||
"VirtualMachineDescriptor.hashCode() returns different values " + "(" + targetVMDesc.hashCode() + " and " + targetVMDesc2.hashCode() + ")" +
|
||||
" for '" + targetVMDesc + "' and '" + targetVMDesc2 + "'");
|
||||
} finally {
|
||||
targetVM.detach();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new VirtualMachineDescriptor01(args).runTest();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user