Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/jdi/PlugConnectors.java
41161 views
/*1* Copyright (c) 2003, 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*/2223/*24* A Super class for pluggable connectors used by25* nsk/jdi/PlugConnectors tests26*/2728package nsk.share.jdi;2930import com.sun.jdi.*;31import com.sun.jdi.connect.*;32import java.io.*;33import java.util.*;3435public class PlugConnectors implements Connector {3637String plugConnectorName = "Undefined_PlugConnector_Name";38String plugConnectorDescription = "Undefined_PlugConnector_Description";39Transport plugConnectorTransport = new PlugConnectorsTransport();40Map<java.lang.String,com.sun.jdi.connect.Connector.Argument> plugConnectorDefaultArguments = new HashMap<java.lang.String,com.sun.jdi.connect.Connector.Argument>();4142/*43* Simple implementation of Connector.Argument44*/45public static class TestArgument implements Connector.Argument {46String argName;47String argLabel;48String argDescription;49String argStringValue;50boolean argMustSpecify;5152public TestArgument(53String argName,54String argLabel,55String argDescription,56String argValue,57boolean argMustSpecify) {5859this.argName = argName;60this.argLabel = argLabel;61this.argDescription = argDescription;62this.argStringValue = argValue;63this.argMustSpecify = argMustSpecify;64}6566public String name() {67return argName;68}6970public String label() {71return argLabel;72}7374public String description() {75return argDescription;76}7778public String value() {79return argStringValue;80}8182public void setValue(String argValue) {83this.argStringValue = argValue;84}8586public boolean isValid(String argValue) {87if ( argValue != null ) {88if (argValue.length() > 0) {89return true;90}91}92return false;93}9495public boolean mustSpecify() {96return argMustSpecify;97}98} // end of TestArgument static class99100/*101* Simple implementation of Connector.StringArgument102*/103public static class TestStringArgument extends TestArgument implements Connector.StringArgument {104105public TestStringArgument( String argName,106String argLabel,107String argDescription,108String argValue,109boolean argMustSpecify) {110111super(argName, argLabel, argDescription, argValue, argMustSpecify);112}113114} // end of TestStringArgument static class115116/*117* Simple implementation of Connector.IntegerArgument118*/119public static class TestIntegerArgument extends TestArgument implements Connector.IntegerArgument {120121int argIntValue;122int minArgIntValue;123int maxArgIntValue;124125public TestIntegerArgument(String argName,126String argLabel,127String argDescription,128int argValue,129int minArgIntValue,130int maxArgIntValue,131boolean argMustSpecify) {132133super(argName, argLabel, argDescription, "" + argValue, argMustSpecify);134this.argIntValue = argValue;135this.minArgIntValue = minArgIntValue;136this.maxArgIntValue = maxArgIntValue;137138}139140public int intValue() {141return argIntValue;142}143144public boolean isValid(int value) {145if ( value >= minArgIntValue && value <= maxArgIntValue ) {146return true;147}148return false;149}150151public boolean isValid(String stringValue) {152int intValue;153try {154intValue = Integer.parseInt(stringValue);155} catch (NumberFormatException exception) {156return false;157}158return isValid(intValue);159}160161public int max() {162return maxArgIntValue;163}164165public int min() {166return minArgIntValue;167}168169public void setValue(int value) {170argIntValue = value;171}172173public String stringValueOf(int value) {174return "" + value;175}176177} // end of TestIntegerArgument static class178179/*180* Simple implementation of Connector.BooleanArgument181*/182public static class TestBooleanArgument extends TestArgument implements Connector.BooleanArgument {183184static final String argStringValueTrue = "true";185static final String argStringValueFalse = "false";186boolean argBooleanValue;187188public TestBooleanArgument(String argName,189String argLabel,190String argDescription,191boolean argValue,192boolean argMustSpecify) {193194super(argName, argLabel, argDescription,195argValue ? argStringValueTrue : argStringValueFalse,196argMustSpecify);197this.argBooleanValue = argValue;198199}200201public boolean booleanValue() {202return argBooleanValue;203}204205public boolean isValid(String stringValue) {206if ( argStringValueTrue.equals(stringValue) || argStringValueFalse.equals(stringValue) ) {207return true;208}209return false;210}211212public void setValue(boolean value) {213argBooleanValue = value;214}215216public String stringValueOf(boolean value) {217if ( value ) {218return argStringValueTrue;219}220return argStringValueFalse;221}222223} // end of TestBooleanArgument static class224225/*226* Simple implementation of Connector.SelectedArgument227*/228public static class TestSelectedArgument extends TestArgument implements Connector.SelectedArgument {229230List<String> acceptableArgsList;231232public TestSelectedArgument( String argName,233String argLabel,234String argDescription,235String argValue,236List<String> acceptableArgsList,237boolean argMustSpecify) {238239super(argName, argLabel, argDescription, argValue, argMustSpecify);240this.acceptableArgsList = acceptableArgsList;241}242243public List<String> choices() {244return acceptableArgsList;245}246247public boolean isValid(String stringValue) {248249return acceptableArgsList.contains(stringValue);250}251252} // end of TestSelectedArgument static class253254public PlugConnectors(255String plugConnectorName,256String plugConnectorDescription,257Transport plugConnectorTransport,258Map<java.lang.String,com.sun.jdi.connect.Connector.Argument> plugConnectorDefaultArguments259) {260261this.plugConnectorName = plugConnectorName;262this.plugConnectorDescription = plugConnectorDescription;263this.plugConnectorTransport = plugConnectorTransport;264this.plugConnectorDefaultArguments = plugConnectorDefaultArguments;265}266267public String name() {268return plugConnectorName;269}270271public String description() {272return plugConnectorDescription;273}274275public Transport transport() {276return plugConnectorTransport;277}278279public Map<java.lang.String,com.sun.jdi.connect.Connector.Argument> defaultArguments() {280return plugConnectorDefaultArguments;281}282283public VirtualMachine launch(Map<String,? extends Connector.Argument> arguments) throws284IOException,285IllegalConnectorArgumentsException,286VMStartException {287288String exceptionMessage = "## PlugConnectors: Connector name = '" +289plugConnectorName + "';\nNon-authorized call of launch(...) method!";290291if ( true ) {292throw new RuntimeException(exceptionMessage);293}294295return null;296}297298public VirtualMachine attach(Map<String,? extends Connector.Argument> arguments) throws299java.io.IOException,300IllegalConnectorArgumentsException {301302String exceptionMessage = "## PlugConnectors: Connector name = '" +303plugConnectorName + "';\nNon-authorized call of attach(...) method!";304305if ( true ) {306throw new RuntimeException(exceptionMessage);307}308309return null;310}311312public String startListening(Map<String,? extends Connector.Argument> arguments) throws313java.io.IOException,314IllegalConnectorArgumentsException {315316String exceptionMessage = "## PlugConnectors: Connector name = '" +317plugConnectorName + "';\nNon-authorized call of startListening(...) method!";318319if ( true ) {320throw new RuntimeException(exceptionMessage);321}322323return null;324}325326public void stopListening(Map<String,? extends Connector.Argument> arguments) throws327java.io.IOException,328IllegalConnectorArgumentsException {329330String exceptionMessage = "## PlugConnectors: Connector name = '" +331plugConnectorName + "';\nNon-authorized call of stopListening(...) method!";332333if ( true ) {334throw new RuntimeException(exceptionMessage);335}336}337338public VirtualMachine accept(Map<String,? extends Connector.Argument> arguments) throws339java.io.IOException,340IllegalConnectorArgumentsException {341342String exceptionMessage = "## PlugConnectors: Connector name = '" +343plugConnectorName + "';\nNon-authorized call of accept(...) method!";344345if ( true ) {346throw new RuntimeException(exceptionMessage);347}348349return null;350}351352public boolean supportsMultipleConnections() {353354String exceptionMessage = "## PlugConnectors: Connector name = '" +355plugConnectorName + "';\nNon-authorized call of supportsMultipleConnections() method!";356357if ( true ) {358throw new RuntimeException(exceptionMessage);359}360361return false;362}363364public static class PlugConnectorsTransport implements Transport {365366String transportName = "Undefined_Transport_Name";367368public PlugConnectorsTransport() {369}370371public PlugConnectorsTransport(String transportName) {372this.transportName = transportName;373}374375public String name() {376return transportName;377}378379} // end of PlugConnectorsTransport class380381// Auxiliary general purpose methods for pluggable connectors' tests.382383public static String compareConnectors(384String errorLogPrefixHead,385String errorLogPrefix,386Connector referenceConnector,387Connector checkedConnector) {388389String emptyString = "";390String errorMessage = emptyString;391392// check that connectors have the same name393String referenceConnectorName = referenceConnector.name();394String checkedConnectorName = checkedConnector.name();395if ( ! referenceConnectorName.equals(checkedConnectorName) ) {396errorMessage = errorMessage +397errorLogPrefixHead + "Checked pluggable Connector has unexpected name:\n"398+ errorLogPrefix + "Expected Connector's name = '" + referenceConnectorName + "'\n"399+ errorLogPrefix + "Actual Connector's name = '" + checkedConnectorName + "'\n";400}401402// check that connectors have the same description403String referenceConnectorDescription = referenceConnector.description();404String checkedConnectorDescription = checkedConnector.description();405if ( ! referenceConnectorDescription.equals(checkedConnectorDescription) ) {406errorMessage = errorMessage +407errorLogPrefixHead + "Checked pluggable Connector has unexpected description:\n"408+ errorLogPrefix + "Expected Connector's description = '" + referenceConnectorDescription + "'\n"409+ errorLogPrefix + "Actual Connector's description = '" + checkedConnectorDescription + "'\n";410}411412// check that connectors have the same transport name413String referenceConnectorTransportName = referenceConnector.transport().name();414String checkedConnectorTransportName = checkedConnector.transport().name();415if ( ! referenceConnectorTransportName.equals(checkedConnectorTransportName) ) {416errorMessage = errorMessage +417errorLogPrefixHead + "Checked pluggable Connector has unexpected transport name:\n"418+ errorLogPrefix + "Expected Connector's transport name = '" + referenceConnectorTransportName + "'\n"419+ errorLogPrefix + "Actual Connector's transport name = '" + checkedConnectorTransportName + "'\n";420}421422// check that connectors have the same number of default arguments423int referenceConnectorArgumentsNumber = referenceConnector.defaultArguments().size();424int checkedConnectorArgumentsNumber = checkedConnector.defaultArguments().size();425if ( referenceConnectorArgumentsNumber != checkedConnectorArgumentsNumber ) {426errorMessage = errorMessage +427errorLogPrefixHead + "Checked pluggable Connector has unexpected number of default arguments:\n"428+ errorLogPrefix + "Expected number of default arguments = '" + referenceConnectorArgumentsNumber + "'\n"429+ errorLogPrefix + "Actual number of default arguments = '" + checkedConnectorArgumentsNumber + "'\n";430}431432433return errorMessage;434} // end of compareConnectors(...) method435436public static String compareConnectorArguments(437String errorLogPrefixHead,438String errorLogPrefix,439Connector.Argument referenceArgument,440Connector.Argument checkedArgument) {441442String emptyString = "";443String errorMessage = emptyString;444445if ( referenceArgument == null ) {446errorMessage =447errorLogPrefixHead + "Reference connector's argument is null!\n";448}449450if ( checkedArgument == null ) {451errorMessage = errorMessage +452errorLogPrefixHead + "Checked connector's argument is null!\n";453}454455if ( ! errorMessage.equals(emptyString) ) {456return errorMessage;457}458459String referenceArgumentName = referenceArgument.name();460String checkedArgumentName = checkedArgument.name();461if ( ! referenceArgumentName.equals(checkedArgumentName) ) {462errorMessage =463errorLogPrefixHead + "Checked connector's argument has unexpected name:\n"464+ errorLogPrefix + "Expected connector's argument name = '" + referenceArgumentName + "'\n"465+ errorLogPrefix + "Actual connector's argument name = '" + checkedArgumentName + "'";466return errorMessage;467}468469String referenceArgumentLabel = referenceArgument.label();470String checkedArgumentLabel = checkedArgument.label();471if ( ! referenceArgumentLabel.equals(checkedArgumentLabel) ) {472errorMessage =473errorLogPrefixHead + "Checked connector's argument has unexpected label:\n"474+ errorLogPrefix + "Expected connector's argument label = '" + referenceArgumentLabel + "'\n"475+ errorLogPrefix + "Actual connector's argument label = '" + checkedArgumentLabel + "'";476return errorMessage;477}478479String referenceArgumentDescription = referenceArgument.description();480String checkedArgumentDescription = checkedArgument.description();481if ( ! referenceArgumentDescription.equals(checkedArgumentDescription) ) {482errorMessage =483errorLogPrefixHead + "Checked connector's argument has unexpected description:\n"484+ errorLogPrefix + "Expected connector's argument description = '" + referenceArgumentDescription + "'\n"485+ errorLogPrefix + "Actual connector's argument description = '" + checkedArgumentDescription + "'";486return errorMessage;487}488489String referenceArgumentValue = referenceArgument.value();490String checkedArgumentValue = checkedArgument.value();491if ( ! referenceArgumentValue.equals(checkedArgumentValue) ) {492errorMessage =493errorLogPrefixHead + "Checked connector's argument has unexpected value:\n"494+ errorLogPrefix + "Expected connector's argument value = '" + referenceArgumentValue + "'\n"495+ errorLogPrefix + "Actual connector's argument value = '" + checkedArgumentValue + "'";496return errorMessage;497}498499boolean referenceArgumentMustSpecify = referenceArgument.mustSpecify();500boolean checkedArgumentMustSpecify = checkedArgument.mustSpecify();501if ( referenceArgumentMustSpecify != checkedArgumentMustSpecify ) {502errorMessage =503errorLogPrefixHead + "Checked connector's argument has unexpected 'mustSpecify' property:\n"504+ errorLogPrefix + "Expected connector's argument 'mustSpecify' property = '"505+ referenceArgumentMustSpecify + "'\n"506+ errorLogPrefix + "Actual connector's argument 'mustSpecify' property = '"507+ checkedArgumentMustSpecify + "'";508return errorMessage;509}510511if ( referenceArgument instanceof Connector.IntegerArgument ) {512513int referenceArgumentMin = ((Connector.IntegerArgument)referenceArgument).min();514int checkedArgumentMin = ((Connector.IntegerArgument)checkedArgument).min();515if ( referenceArgumentMin != checkedArgumentMin ) {516errorMessage =517errorLogPrefixHead + "Checked connector's integer argument has unexpected min value:\n"518+ errorLogPrefix + "Expected connector's argument min value = "519+ referenceArgumentMin + "\n"520+ errorLogPrefix + "Actual connector's argument min value = "521+ checkedArgumentMin + "\n";522}523524int referenceArgumentMax = ((Connector.IntegerArgument)referenceArgument).max();525int checkedArgumentMax = ((Connector.IntegerArgument)checkedArgument).max();526if ( referenceArgumentMax != checkedArgumentMax ) {527errorMessage = errorMessage +528errorLogPrefixHead + "Checked connector's integer argument has unexpected max value:\n"529+ errorLogPrefix + "Expected connector's argument max value = "530+ referenceArgumentMax + "\n"531+ errorLogPrefix + "Actual connector's argument max value = "532+ checkedArgumentMax + "\n";533}534535}536537if ( referenceArgument instanceof Connector.SelectedArgument ) {538539List referenceArgumentChoices = ((Connector.SelectedArgument)referenceArgument).choices();540List checkedArgumentChoices = ((Connector.SelectedArgument)checkedArgument).choices();541542int referenceArgumentChoicesSize = referenceArgumentChoices.size();543int checkedArgumentChoicesSize = checkedArgumentChoices.size();544545if ( referenceArgumentChoicesSize != checkedArgumentChoicesSize) {546errorMessage = errorMessage +547errorLogPrefixHead + "Checked connector's Selected argument has unexpected choices' size:\n"548+ errorLogPrefix + "Expected size = '"549+ referenceArgumentChoicesSize + "'\n"550+ errorLogPrefix + "Actual size = "551+ checkedArgumentChoicesSize;552return errorMessage;553}554555for (int i=0; i < referenceArgumentChoicesSize; i++) {556String referenceArgumentChoice = (String)(referenceArgumentChoices.get(i));557if ( ! checkedArgumentChoices.contains(referenceArgumentChoice) ) {558errorMessage = errorMessage +559errorLogPrefixHead + "Checked connector's Selected argument has NOT expected choices' element:\n"560+ errorLogPrefix + "Expected choices' element = '"561+ referenceArgumentChoice + "'\n";562}563564String checkedArgumentChoice = (String)(checkedArgumentChoices.get(i));565if ( ! referenceArgumentChoices.contains(checkedArgumentChoice) ) {566errorMessage = errorMessage +567errorLogPrefixHead + "Checked connector's Selected argument has unexpected choices' element:\n"568+ errorLogPrefix + "Unexpected choices' element = '"569+ checkedArgumentChoice + "'\n";570}571}572}573return errorMessage;574} // end of compareConnectorArguments(...) method575576public static Connector.Argument getConnectorDefaultArgument(577Connector connector,578String argumentName) {579580Connector.Argument foundArgument = null;581582Map connectorDefaultArguments = connector.defaultArguments();583Object[] defaultArgumentsArray = connectorDefaultArguments.values().toArray();584585for (int i=0; i < defaultArgumentsArray.length; i++) {586Connector.Argument connectorArgument = (Connector.Argument)defaultArgumentsArray[i];587if ( argumentName.equals(connectorArgument.name()) ) {588foundArgument = connectorArgument;589break;590}591}592return foundArgument;593}594595} // end of PlugConnectors class596597598