Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/value/value003.java
41160 views
/*1* Copyright (c) 2000, 2018, 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*/2223package nsk.jdi.Argument.value;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.connect.*;31import java.io.*;32import javax.naming.directory.Attribute;33import java.util.*;3435/**36* Test for the control of37*38* Interface: com.sun.jdi.connect.Connector.Argument39* Method: public java.lang.String value()40* Assertion: "Returns the current value of the argument."41*42*43* Comments: The test aims on the concrete Sun's JDI44* reference implementations. It uses45* com.sun.jdi.CommandLineLaunch connector and its46* "options" and "main" arguments.47* The test sets up the new "options" and "main" arguments48* values and then checks that new values remain previously49* after connection establishing with debugee VM and50* after debugee VM finishing.51*/5253public class value003 {54private static Log log;5556public static void main(String argv[] ) {57System.exit(run(argv, System.out)+95); // JCK-compatible exit status58}5960public static int run(String argv[], PrintStream out) {61ArgumentHandler argHandler = new ArgumentHandler(argv);62log = new Log(out, argHandler);63VirtualMachineManager vmm = Bootstrap.virtualMachineManager();6465String javaKind = argHandler.getOptions().getProperty("debugee.vmkind");66boolean java_g = javaKind != null && javaKind.startsWith("java_g"); // ...or java_g.exe67if (java_g)68log.display("Test option: java_g");6970List lcl = vmm.launchingConnectors();71if (lcl.size() > 0) {72log.display("Number of all known JDI launching connectors: " +73lcl.size());74} else {75log.complain("FAILURE: no JDI launching connectors found!");76return 2;77}7879Iterator lci = lcl.iterator();80for (int i = 1; lci.hasNext(); i++) {81Connector c = (Connector) lci.next();82if (c.name().compareTo("com.sun.jdi.CommandLineLaunch") != 0) {83continue;84}85Map<String,? extends Connector.Argument> cdfltArgmnts = c.defaultArguments();86int ksz = cdfltArgmnts.size();87String av[] = new String[ksz + 1];88Set ks = cdfltArgmnts.keySet();89if (ks.isEmpty()) {90log.complain("FAILURE: empty default argument set is found "91+ "for " + c.name() + " connector!");92return 2;93}9495log.display("Looking over " + c.name() + " connector arguments: ");9697boolean flg = false;98Iterator argi = ks.iterator();99String ovl = null;100String nvl = null;101for (int j = 1; argi.hasNext(); j++) {102String argkey = (String)argi.next();103Connector.Argument argval =104(Connector.Argument)cdfltArgmnts.get((Object) argkey);105106if (java_g && argval.name().equals("vmexec")) {107log.display("Substitute: vmexec --> java_g");108argval.setValue("java_g");109};110111log.display("Connector.Argument argval = "+ argval);112if (argkey.compareTo("options") != 0 &&113argkey.compareTo("main") != 0) {114continue;115}116if (argkey.compareTo("main") == 0) {117if (argval.isValid("nsk.jdi.Argument.value.value003a")) {118argval.setValue("nsk.jdi.Argument.value.value003a");119} else {120log.complain("FAILURE: Can't set up new value for "121+ "main-argument");122return 2;123}124continue;125}126flg = true;127ovl = argval.value();128if (argval.isValid(ovl + "-verify ")) {129argval.setValue(ovl + "-verify ");130} else {131log.complain("FAILURE: Can't set up new value for "132+ "options-argument");133return 2;134}135136nvl = argval.value();137if (nvl.compareTo(ovl + "-verify ") != 0) {138log.complain("FAILURE: Can't set up argument value!");139return 2;140}141log.display("Changed " + argval.name() + " argument's "142+ "value is: " + nvl);143};144145Binder binder = new Binder(argHandler, log);146Debugee debugee = null;147148try {149if (flg) {150flg = false;151VirtualMachine vm =152((LaunchingConnector) c).launch(cdfltArgmnts);153log.display("VM = (" + vm + ")");154debugee = binder.enwrapDebugee(vm, vm.process());155156if (((Connector.Argument)cdfltArgmnts157.get((Object)"options")).value()158.compareTo(ovl + "-verify ") != 0) {159log.complain("FAILURE: Current 'options' argument "160+ "value is not coinsides with the last "161+ "setted up value.");162return 2;163}164if (((Connector.Argument)c.defaultArguments()165.get((Object) "options")).value()166.compareTo(ovl) != 0) {167log.complain("FAILURE: Default 'options' argument "168+ "value can not be changed.");169return 2;170}171172debugee.resume();173}174} catch ( java.io.IOException exc) {175log.complain("FAILURE: Unable to launch, so "176+ "java.io.IOException is arisen.");177log.complain(exc.getMessage());178return 2;179} catch (com.sun.jdi.connect.IllegalConnectorArgumentsException180exc) {181log.complain("FAILURE: One of the connector arguments is "182+ "invalid, so IllegalConnectorArgumentsException "183+ "is arisen.");184log.complain(exc.getMessage());185return 2;186} catch ( com.sun.jdi.connect.VMStartException exc) {187log.complain("FAILURE: VM was terminated with error before "188+ "a connection could be established, so "189+ "VMStartException is arisen.");190log.complain(exc.getMessage());191log.complain(Binder.readVMStartExceptionOutput(exc, log.getOutStream()));192return 2;193} finally {194if (debugee != null) {195try {196debugee.dispose();197} catch (VMDisconnectedException ignore) {198}199200int extcd = debugee.waitFor();201if (extcd != 95) {202log.complain("FAILURE: Launching VM crushes with "203+ extcd + " exit code.");204return 2;205}206}207}208};209210log.display("Test PASSED!");211return 0;212}213}214215216