Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/value/value004.java
41160 views
/*1* Copyright (c) 2000, 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*/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.*;3435import jtreg.SkippedException;3637/**38* Test for the control of39*40* Interface: com.sun.jdi.connect.Connector.Argument41* Method: public java.lang.String value()42* Assertion: "Returns the current value of the argument."43*44*45* Comments: The test aims on the concrete Sun's JDI46* reference implementations. It uses47* com.sun.jdi.RawCommandLineLaunch connector and its48* "command" argument.49* The test sets up the new "command" argument50* value and then checks that new value remains previously51* after connection establishing with debugee VM and52* after debugee VM finishing.53*/5455public class value004 {56private static Log log;5758public static void main( String argv[] ) {59System.exit(run(argv, System.out)+95); // JCK-compatible exit status60}6162public static int run(String argv[],PrintStream out) {63ArgumentHandler argHandler = new ArgumentHandler(argv);64log = new Log(out, argHandler);65VirtualMachineManager vmm = Bootstrap.virtualMachineManager();6667String address = argHandler.getTransportPort();6869List lcl = vmm.launchingConnectors();70if (lcl.size() > 0) {71log.display("Number of all known JDI launching connectors: "72+ lcl.size());73} else {74log.complain("FAILURE: no JDI launching connectors found!");75return 2;76}7778boolean skipped = true;79Iterator lci = lcl.iterator();80while (lci.hasNext()) {81Connector c = (Connector) lci.next();82if (!"com.sun.jdi.RawCommandLineLaunch".equals(c.name())) {83log.display("skipping " + c);84continue;85}86log.display("Connector's transport is: " + c.transport().name());87Map<java.lang.String,? extends com.sun.jdi.connect.Connector.Argument> cdfltArgmnts = c.defaultArguments();88int ksz = cdfltArgmnts.size();89String av[] = new String[ksz + 1];90Set ks = cdfltArgmnts.keySet();91if (ks.isEmpty()) {92log.complain("FAILURE: empty default arguments set is "93+ "found for " + c.name() + " connector!");94return 2;95}9697log.display("Looking over " + c.name() + " connector arguments: ");9899boolean flg = false;100Iterator argi = ks.iterator();101String ovl = null;102String nvl = null;103for (int j = 1; argi.hasNext(); j++) {104String argkey = (String) argi.next();105Connector.Argument argval =106(Connector.Argument)cdfltArgmnts.get((Object) argkey);107log.display("Connector.Argument argval = "+ argval);108if (argkey.compareTo("command") != 0 &&109argkey.compareTo("address") != 0) {110continue;111}112if (argkey.compareTo("address") == 0) {113if (argval.isValid(address)) {114argval.setValue(address);115} else {116log.complain("FAILURE: Can't set up new value "117+ "for address-argument");118return 2;119}120continue;121}122flg = true;123ovl = argHandler.getLaunchExecPath() + " "124+ "-Xdebug -Xnoagent -Djava.compiler=NONE "125+ "-Xrunjdwp:transport=" + c.transport().name() + ",suspend=y,"126+ "address=" + address + " nsk.jdi.Argument.value.value004a";127if (argval.isValid(ovl)) {128argval.setValue(ovl);129} else {130log.complain("FAILURE: Can't set up new value for "131+ "command-argument");132return 2;133}134135nvl = argval.value();136if (nvl.compareTo(ovl) != 0) {137log.complain("FAILURE: Can't set up argument value!");138return 2;139}140log.display("Changed " + argval.name() + " argument's "141+ "value is: " + nvl);142};143144Binder binder = new Binder(argHandler, log);145Debugee debugee = null;146147try {148if (flg) {149flg = false;150VirtualMachine vm =151((LaunchingConnector)c).launch(cdfltArgmnts);152log.display("VM = (" + vm + ")");153debugee = binder.enwrapDebugee(vm, vm.process());154155if (((Connector.Argument) cdfltArgmnts156.get((Object) "command")).value()157.compareTo(ovl) != 0) {158log.complain("FAILURE: Current 'command' argument "159+ "value is not coinsides with the "160+ "last setted up value.");161return 2;162}163164debugee.resume();165}166} catch ( java.io.IOException exc) {167log.complain("FAILURE: Unable to launch, so "168+ "java.io.IOException is arisen.");169log.complain(exc.getMessage());170return 2;171} catch ( com.sun.jdi.connect.IllegalConnectorArgumentsException172exc) {173log.complain("FAILURE: One of the connector arguments "174+ "is invalid, so "175+ "IllegalConnectorArgumentsException is arisen.");176log.complain(exc.getMessage());177return 2;178} catch ( com.sun.jdi.connect.VMStartException exc) {179log.complain("FAILURE: VM was terminated with error before "180+ "a connection could be established, so "181+ "VMStartException is arisen.");182log.complain(exc.getMessage());183log.complain(Binder.readVMStartExceptionOutput(exc, log.getOutStream()));184return 2;185} finally {186if (debugee != null) {187try {188debugee.dispose();189} catch (VMDisconnectedException ignore) {190}191192int extcd = debugee.waitFor();193if (extcd != 95) {194log.complain("FAILURE: Launching VM crushes "195+ "with " + extcd + " exit code.");196return 2;197}198}199}200skipped = false;201}202if (skipped) {203throw new SkippedException("no suitable connectors");204}205log.display("Test PASSED!");206return 0;207}208}209210211