Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/aod/VirtualMachine/VirtualMachine04/VirtualMachine04.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/VirtualMachine04.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 following methods:33* - VirtualMachine.getSystemProperties() (test checks that returned properties contains34* expected property and tested method returns properties whose key and value is a String)35* - VirtualMachine.getAgentProperties() (test checks that method returns properties whose36* key and value is a String)37*38* @library /vmTestbase /test/hotspot/jtreg/vmTestbase39* /test/lib40* @build nsk.aod.VirtualMachine.VirtualMachine04.VM04Target41* @run main/othervm42* -XX:+UsePerfData43* nsk.aod.VirtualMachine.VirtualMachine04.VirtualMachine0444* -jdk ${test.jdk}45* -javaOpts="-XX:+UsePerfData ${test.vm.opts} ${test.java.opts}"46* -target nsk.aod.VirtualMachine.VirtualMachine04.VM04Target47*/4849package nsk.aod.VirtualMachine.VirtualMachine04;5051import com.sun.tools.attach.VirtualMachine;52import nsk.share.TestBug;53import nsk.share.aod.AODTestRunner;54import nsk.share.test.TestUtils;5556import java.util.Properties;5758/*59* Test checks following methods:60* - VirtualMachine.getSystemProperties()61* - VirtualMachine.getAgentProperties()62*/63public class VirtualMachine04 extends AODTestRunner {64static final String SIGNAL_CHANGE_PROPERTY = "change_property";65static final String SIGNAL_PROPERTY_CHANGED = "property_changed";6667public VirtualMachine04(String[] args) {68super(args);69}7071public void doTestActions(String targetVMId) throws Throwable {72VirtualMachine vm = VirtualMachine.attach(targetVMId);7374try {75checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.TEST_PROPERTY_VALUE);7677log.display("Sending signal " + SIGNAL_CHANGE_PROPERTY);78pipe.println(SIGNAL_CHANGE_PROPERTY);79String signal = pipe.readln();80log.display("Received signal " + signal);81if (!signal.equals(SIGNAL_PROPERTY_CHANGED)) {82throw new TestBug("Unexpected signal received: " + signal);83}84checkSystemProperties(vm, VM04Target.TEST_PROPERTY_KEY, VM04Target.CHANGED_TEST_PROPERTY_VALUE);8586Properties properties = vm.getAgentProperties();87System.out.println("VirtualMachine.getAgentProperties(): " + properties);88checkProperties(properties);89} finally {90vm.detach();91}92}9394void checkSystemProperties(VirtualMachine vm,95String propertyToCheck,96String expectedPropertyValue) throws Throwable {9798Properties properties = vm.getSystemProperties();99System.out.println("VirtualMachine.getSystemProperties(): " + properties);100checkProperties(properties);101102String checkedPropertyValue = properties.getProperty(propertyToCheck);103TestUtils.assertNotNull(checkedPropertyValue, "Properties doesn't contain property '" + propertyToCheck + "'");104TestUtils.assertEquals(checkedPropertyValue, expectedPropertyValue,105"Unexpected value of the property '" + propertyToCheck + "': " + checkedPropertyValue + ", expected value is '" + expectedPropertyValue + "'");106}107108/*109* Check following spec clause: VirtualMachine.getSystemProperties() and110* VirtualMachine.getAgentProperties() return the properties whose key and value is a String111*/112void checkProperties(Properties properties) {113TestUtils.assertNotNull(properties, "Method returns null Properties");114115for (Object key : properties.keySet()) {116Object value = properties.get(key);117log.display("Value of '" + key + "' = " + value);118119TestUtils.assertTrue(key instanceof String, "Property key isn't String: " + key.getClass().getName());120TestUtils.assertTrue(value instanceof String, "Property value isn't String: " + value.getClass().getName());121}122}123124public static void main(String[] args) {125new VirtualMachine04(args).runTest();126}127}128129130