Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine03/VirtualMachine03.java
41160 views
/*1* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25*26* @summary converted from VM Testbase nsk/aod/VirtualMachine/VirtualMachine03.27* VM Testbase keywords: [feature_282, jdk]28* VM Testbase readme:29* Description :30* Test checks work of Attach API (com.sun.tools.attach).31* Test is based on the nsk.share.aod framework.32* Test checks semantics of the method VirtualMachine.equals(Object obj).33*34* @library /vmTestbase /test/hotspot/jtreg/vmTestbase35* /test/lib36* @build nsk.share.aod.DummyTargetApplication37* @run main/othervm38* -Djdk.attach.allowAttachSelf39* -XX:+UsePerfData40* nsk.aod.VirtualMachine.VirtualMachine03.VirtualMachine0341* -jdk ${test.jdk}42* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"43* -target nsk.share.aod.DummyTargetApplication44*/4546package nsk.aod.VirtualMachine.VirtualMachine03;4748import com.sun.tools.attach.VirtualMachine;49import nsk.share.aod.AODTestRunner;50import nsk.share.test.TestUtils;5152/*53* Test checks method VirtualMachine.equals(Object)54*/55public class VirtualMachine03 extends AODTestRunner {5657public VirtualMachine03(String[] args) {58super(args);59}6061public void doTestActions(String targetVMId) throws Throwable {62String currentVMId = getCurrentVMId();6364VirtualMachine vm1 = VirtualMachine.attach(currentVMId);65try {66VirtualMachine vm2 = VirtualMachine.attach(targetVMId);67try {68TestUtils.assertEquals(vm1.id(), currentVMId, "vm.id() returns unexpected value: " + vm1.id());69TestUtils.assertEquals(vm2.id(), targetVMId, "vm.id() returns unexpected value: " + vm2.id());7071TestUtils.assertTrue(!vm1.equals(vm2), vm1 + ".equals(" + vm2 + ") returns 'true'");7273checkVM(vm1);74checkVM(vm2);75} finally {76vm2.detach();77}78} finally {79vm1.detach();80}81}8283void checkVM(VirtualMachine vm1) throws Throwable {84TestUtils.assertEquals(vm1, vm1, "vm.equals(itself) returns 'false'");8586// create one more VirtualMachine object for the same VM87VirtualMachine vm2 = VirtualMachine.attach(vm1.id());88try {89TestUtils.assertEquals(vm1, vm2, vm1 + ".equals(" + vm2 + ") returns 'false'");90TestUtils.assertTrue(vm1.hashCode() == vm2.hashCode(), "vm.hashCode() returns different values for " + vm1 + " and " + vm2);91TestUtils.assertEquals(vm1.provider(), vm2.provider(), "vm.provider() returns non-equals objects for " + vm1 + " and " + vm2);92} finally {93vm2.detach();94}9596TestUtils.assertTrue(!vm1.equals(""), "vm.equals(String) returns 'true'");9798TestUtils.assertTrue(!vm1.equals(null), "vm.equals(null) returns 'true'");99}100101public static void main(String[] args) {102new VirtualMachine03(args).runTest();103}104}105106107