Repository: incubator-systemml Updated Branches: refs/heads/master f73673d59 -> 32924dc60
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/api/MLContext.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/MLContext.java b/src/main/java/org/apache/sysml/api/MLContext.java index 809776a..b3102e9 100644 --- a/src/main/java/org/apache/sysml/api/MLContext.java +++ b/src/main/java/org/apache/sysml/api/MLContext.java @@ -771,7 +771,7 @@ public class MLContext { args[i] = entry.getKey() + "=" + entry.getValue(); i++; } - return compileAndExecuteScript(dmlScriptFilePath, args, true, parsePyDML, configFilePath); + return compileAndExecuteScript(dmlScriptFilePath, args, true, parsePyDML ? ScriptType.PYDML : ScriptType.DML, configFilePath); } /** @@ -785,17 +785,7 @@ public class MLContext { * @throws ParseException if ParseException occurs */ public MLOutput execute(String dmlScriptFilePath, Map<String, String> namedArgs, String configFilePath) throws IOException, DMLException, ParseException { - String [] args = new String[namedArgs.size()]; - int i = 0; - for(Entry<String, String> entry : namedArgs.entrySet()) { - if(entry.getValue().trim().isEmpty()) - args[i] = entry.getKey() + "=\"" + entry.getValue() + "\""; - else - args[i] = entry.getKey() + "=" + entry.getValue(); - i++; - } - - return compileAndExecuteScript(dmlScriptFilePath, args, true, false, configFilePath); + return execute(dmlScriptFilePath, namedArgs, false, configFilePath); } /** @@ -1014,7 +1004,7 @@ public class MLContext { * @throws ParseException if ParseException occurs */ public MLOutput execute(String dmlScriptFilePath, String [] args, boolean parsePyDML, String configFilePath) throws IOException, DMLException, ParseException { - return compileAndExecuteScript(dmlScriptFilePath, args, false, parsePyDML, configFilePath); + return compileAndExecuteScript(dmlScriptFilePath, args, false, parsePyDML ? ScriptType.PYDML : ScriptType.DML, configFilePath); } /** @@ -1067,7 +1057,7 @@ public class MLContext { * @throws ParseException if ParseException occurs */ public MLOutput execute(String dmlScriptFilePath, boolean parsePyDML, String configFilePath) throws IOException, DMLException, ParseException { - return compileAndExecuteScript(dmlScriptFilePath, null, false, parsePyDML, configFilePath); + return compileAndExecuteScript(dmlScriptFilePath, null, false, parsePyDML ? ScriptType.PYDML : ScriptType.DML, configFilePath); } /** @@ -1314,7 +1304,7 @@ public class MLContext { public MLOutput executeScript(String dmlScript, boolean isPyDML, String configFilePath) throws IOException, DMLException { - return compileAndExecuteScript(dmlScript, null, false, false, isPyDML, configFilePath); + return compileAndExecuteScript(dmlScript, null, false, false, isPyDML ? ScriptType.PYDML : ScriptType.DML, configFilePath); } /* @@ -1391,7 +1381,7 @@ public class MLContext { args[i] = entry.getKey() + "=" + entry.getValue(); i++; } - return compileAndExecuteScript(dmlScript, args, false, true, isPyDML, configFilePath); + return compileAndExecuteScript(dmlScript, args, false, true, isPyDML ? ScriptType.PYDML : ScriptType.DML, configFilePath); } private void checkIfRegisteringInputAllowed() throws DMLRuntimeException { @@ -1400,26 +1390,29 @@ public class MLContext { } } - private MLOutput compileAndExecuteScript(String dmlScriptFilePath, String [] args, boolean isNamedArgument, boolean isPyDML, String configFilePath) throws IOException, DMLException { - return compileAndExecuteScript(dmlScriptFilePath, args, true, isNamedArgument, isPyDML, configFilePath); + private MLOutput compileAndExecuteScript(String dmlScriptFilePath, String [] args, boolean isNamedArgument, ScriptType scriptType, String configFilePath) throws IOException, DMLException { + return compileAndExecuteScript(dmlScriptFilePath, args, true, isNamedArgument, scriptType, configFilePath); } - + /** * All the execute() methods call this, which after setting appropriate input/output variables * calls _compileAndExecuteScript * We have explicitly synchronized this function because MLContext/SystemML does not yet support multi-threading. + * @throws ParseException if ParseException occurs * @param dmlScriptFilePath script file path * @param args arguments - * @param isNamedArgument is named argument + * @param isFile whether the string is a path + * @param isNamedArgument is named argument + * @param scriptType type of script (DML or PyDML) + * @param configFilePath path to config file * @return output as MLOutput * @throws IOException if IOException occurs * @throws DMLException if DMLException occurs - * @throws ParseException if ParseException occurs */ - private synchronized MLOutput compileAndExecuteScript(String dmlScriptFilePath, String [] args, boolean isFile, boolean isNamedArgument, boolean isPyDML, String configFilePath) throws IOException, DMLException { + private synchronized MLOutput compileAndExecuteScript(String dmlScriptFilePath, String [] args, boolean isFile, boolean isNamedArgument, ScriptType scriptType, String configFilePath) throws IOException, DMLException { try { - DMLScript.SCRIPT_TYPE = isPyDML ? ScriptType.PYDML : ScriptType.DML; + DMLScript.SCRIPT_TYPE = scriptType; if(getActiveMLContext() != null) { throw new DMLRuntimeException("SystemML (and hence by definition MLContext) doesnot support parallel execute() calls from same or different MLContexts. " @@ -1439,7 +1432,7 @@ public class MLContext { Map<String, String> argVals = DMLScript.createArgumentsMap(isNamedArgument, args); // Run the DML script - ExecutionContext ec = executeUsingSimplifiedCompilationChain(dmlScriptFilePath, isFile, argVals, isPyDML, inputs, outputs, _variables, configFilePath); + ExecutionContext ec = executeUsingSimplifiedCompilationChain(dmlScriptFilePath, isFile, argVals, scriptType, inputs, outputs, _variables, configFilePath); SparkExecutionContext sec = (SparkExecutionContext) ec; // Now collect the output @@ -1482,7 +1475,7 @@ public class MLContext { * @param dmlScriptFilePath script file path * @param isFile true if file, false otherwise * @param argVals map of args - * @param parsePyDML true if pydml, false otherwise + * @param scriptType type of script (DML or PyDML) * @param inputs the inputs * @param outputs the outputs * @param inputSymbolTable the input symbol table @@ -1492,7 +1485,7 @@ public class MLContext { * @throws DMLException if DMLException occurs * @throws ParseException if ParseException occurs */ - private ExecutionContext executeUsingSimplifiedCompilationChain(String dmlScriptFilePath, boolean isFile, Map<String, String> argVals, boolean parsePyDML, + private ExecutionContext executeUsingSimplifiedCompilationChain(String dmlScriptFilePath, boolean isFile, Map<String, String> argVals, ScriptType scriptType, String[] inputs, String[] outputs, LocalVariableMap inputSymbolTable, String configFilePath) throws IOException, DMLException { @@ -1511,13 +1504,13 @@ public class MLContext { ConfigurationManager.setGlobalConfig(cconf); //read dml script string - String dmlScriptStr = DMLScript.readDMLScript( isFile?"-f":"-s", dmlScriptFilePath); + String dmlScriptStr = DMLScript.readDMLScript( isFile, dmlScriptFilePath); //simplified compilation chain _rtprog = null; //parsing - ParserWrapper parser = ParserFactory.createParser(parsePyDML); + ParserWrapper parser = ParserFactory.createParser(scriptType); DMLProgram prog; if (isFile) { prog = parser.parse(dmlScriptFilePath, null, argVals); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/api/jmlc/Connection.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/jmlc/Connection.java b/src/main/java/org/apache/sysml/api/jmlc/Connection.java index fe37a6c..0e26c62 100644 --- a/src/main/java/org/apache/sysml/api/jmlc/Connection.java +++ b/src/main/java/org/apache/sysml/api/jmlc/Connection.java @@ -166,7 +166,7 @@ public class Connection implements Closeable try { //parsing - ParserWrapper parser = ParserFactory.createParser(parsePyDML); + ParserWrapper parser = ParserFactory.createParser(parsePyDML ? ScriptType.PYDML : ScriptType.DML); DMLProgram prog = parser.parse(null, script, args); //language validate http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java index e9270c5..ac2b92c 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/ScriptExecutor.java @@ -432,7 +432,7 @@ public class ScriptExecutor { */ protected void parseScript() { try { - ParserWrapper parser = ParserFactory.createParser(script.getScriptType().isPYDML()); + ParserWrapper parser = ParserFactory.createParser(script.getScriptType()); Map<String, Object> inputParameters = script.getInputParameters(); Map<String, String> inputParametersStringMaps = MLContextUtil.convertInputParametersForParser( inputParameters, script.getScriptType()); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/parser/ParserFactory.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/ParserFactory.java b/src/main/java/org/apache/sysml/parser/ParserFactory.java index 37c62df..2d4e273 100644 --- a/src/main/java/org/apache/sysml/parser/ParserFactory.java +++ b/src/main/java/org/apache/sysml/parser/ParserFactory.java @@ -19,6 +19,7 @@ package org.apache.sysml.parser; +import org.apache.sysml.api.mlcontext.ScriptType; import org.apache.sysml.parser.common.CommonSyntacticValidator; import org.apache.sysml.parser.dml.DMLParserWrapper; import org.apache.sysml.parser.pydml.PyDMLParserWrapper; @@ -28,19 +29,18 @@ public class ParserFactory { /** * Factory method for creating parser wrappers * - * @param pydml - * true if a PyDMLParserWrapper is needed, false if a DMLParserWrapper is needed + * @param scriptType + * type of script * @return parser wrapper (DMLParserWrapper or PyDMLParserWrapper) */ - public static ParserWrapper createParser(boolean pydml) { + public static ParserWrapper createParser(ScriptType scriptType) { ParserWrapper ret = null; // create the parser instance - if (pydml) - ret = new PyDMLParserWrapper(); - else - ret = new DMLParserWrapper(); - + switch (scriptType) { + case DML: ret = new DMLParserWrapper(); break; + case PYDML: ret = new PyDMLParserWrapper(); break; + } CommonSyntacticValidator.init(); return ret; http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/utils/Explain.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/utils/Explain.java b/src/main/java/org/apache/sysml/utils/Explain.java index b6e7b6f..af7102b 100644 --- a/src/main/java/org/apache/sysml/utils/Explain.java +++ b/src/main/java/org/apache/sysml/utils/Explain.java @@ -26,7 +26,6 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; -import org.apache.sysml.api.DMLException; import org.apache.sysml.hops.Hop; import org.apache.sysml.hops.HopsException; import org.apache.sysml.hops.LiteralOp; @@ -40,18 +39,18 @@ import org.apache.sysml.hops.globalopt.gdfgraph.GDFNode.NodeType; import org.apache.sysml.hops.ipa.FunctionCallGraph; import org.apache.sysml.lops.Lop; import org.apache.sysml.parser.DMLProgram; -import org.apache.sysml.parser.ForStatement; import org.apache.sysml.parser.ExternalFunctionStatement; +import org.apache.sysml.parser.ForStatement; import org.apache.sysml.parser.ForStatementBlock; import org.apache.sysml.parser.FunctionStatement; import org.apache.sysml.parser.FunctionStatementBlock; import org.apache.sysml.parser.IfStatement; import org.apache.sysml.parser.IfStatementBlock; +import org.apache.sysml.parser.LanguageException; import org.apache.sysml.parser.ParForStatementBlock; +import org.apache.sysml.parser.StatementBlock; import org.apache.sysml.parser.WhileStatement; import org.apache.sysml.parser.WhileStatementBlock; -import org.apache.sysml.parser.LanguageException; -import org.apache.sysml.parser.StatementBlock; import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.controlprogram.ExternalFunctionProgramBlock; import org.apache.sysml.runtime.controlprogram.ForProgramBlock; @@ -436,30 +435,7 @@ public class Explain return counts; } - - public static ExplainType parseExplainType( String arg ) - throws DMLException - { - ExplainType ret = ExplainType.NONE; - - if( arg !=null ) - { - if( arg.equalsIgnoreCase("hops") ) - ret = ExplainType.HOPS; - else if( arg.equalsIgnoreCase("runtime") ) - ret = ExplainType.RUNTIME; - else if( arg.equalsIgnoreCase("recompile_hops") ) - ret = ExplainType.RECOMPILE_HOPS; - else if( arg.equalsIgnoreCase("recompile_runtime") ) - ret = ExplainType.RECOMPILE_RUNTIME; - else - throw new DMLException("Failed to parse explain type: "+arg+" " + - "(valid types: hops, runtime, recompile_hops, recompile_runtime)."); - } - - return ret; - } - + public static String getIdentation( int level ) { return createOffset(level); } http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/java/org/apache/sysml/yarn/DMLYarnClient.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/yarn/DMLYarnClient.java b/src/main/java/org/apache/sysml/yarn/DMLYarnClient.java index bd9116d..c4da603 100644 --- a/src/main/java/org/apache/sysml/yarn/DMLYarnClient.java +++ b/src/main/java/org/apache/sysml/yarn/DMLYarnClient.java @@ -52,7 +52,6 @@ import org.apache.hadoop.yarn.client.api.YarnClientApplication; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.util.ConverterUtils; import org.apache.hadoop.yarn.util.Records; - import org.apache.sysml.conf.DMLConfig; import org.apache.sysml.parser.ParseException; import org.apache.sysml.runtime.DMLRuntimeException; @@ -429,7 +428,7 @@ public class DMLYarnClient command.append(' '); if( i>0 && _args[i-1].equals("-f") ){ command.append(_hdfsDMLScript); - command.append(" -config=" + _hdfsDMLConfig); + command.append(" -config " + _hdfsDMLConfig); } else if( _args[i].startsWith("-config") ){ //ignore because config added with -f http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/resources/scripts/sparkDML.sh ---------------------------------------------------------------------- diff --git a/src/main/resources/scripts/sparkDML.sh b/src/main/resources/scripts/sparkDML.sh index cd57ae0..a68d34a 100644 --- a/src/main/resources/scripts/sparkDML.sh +++ b/src/main/resources/scripts/sparkDML.sh @@ -116,7 +116,7 @@ $SPARK_HOME/bin/spark-submit \ ${conf} \ ${SYSTEMML_HOME}/${project.artifactId}-${project.version}.jar \ -f ${f} \ - -config=${SYSTEMML_HOME}/SystemML-config.xml \ + -config ${SYSTEMML_HOME}/SystemML-config.xml \ -exec hybrid_spark \ $explain \ $stats \ http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/standalone/runStandaloneSystemML.bat ---------------------------------------------------------------------- diff --git a/src/main/standalone/runStandaloneSystemML.bat b/src/main/standalone/runStandaloneSystemML.bat index 9275d9e..35ebbc7 100644 --- a/src/main/standalone/runStandaloneSystemML.bat +++ b/src/main/standalone/runStandaloneSystemML.bat @@ -46,7 +46,7 @@ set CMD=java %SYSTEMML_STANDALONE_OPTS% ^ org.apache.sysml.api.DMLScript ^ -f %1 ^ -exec singlenode ^ - -config=SystemML-config.xml ^ + -config SystemML-config.xml ^ %ALLBUTFIRST% :: execute the java command @@ -72,6 +72,6 @@ GOTO Msg :Msg ECHO Usage: runStandaloneSystemML.bat ^<dml-filename^> [arguments] [-help] ECHO Default Java options (-Xmx4g -Xms4g -Xmn400m) can be overridden by setting SYSTEMML_STANDALONE_OPTS. -ECHO Script internally invokes 'java [SYSTEMML_STANDALONE_OPTS] -cp ./lib/* -Dlog4j.configuration=file:log4j.properties org.apache.sysml.api.DMLScript -f ^<dml-filename^> -exec singlenode -config=SystemML-config.xml [arguments]' +ECHO Script internally invokes 'java [SYSTEMML_STANDALONE_OPTS] -cp ./lib/* -Dlog4j.configuration=file:log4j.properties org.apache.sysml.api.DMLScript -f ^<dml-filename^> -exec singlenode -config SystemML-config.xml [arguments]' :End http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/main/standalone/runStandaloneSystemML.sh ---------------------------------------------------------------------- diff --git a/src/main/standalone/runStandaloneSystemML.sh b/src/main/standalone/runStandaloneSystemML.sh index 28000b4..2980080 100644 --- a/src/main/standalone/runStandaloneSystemML.sh +++ b/src/main/standalone/runStandaloneSystemML.sh @@ -76,7 +76,7 @@ java ${SYSTEMML_STANDALONE_OPTS} \ org.apache.sysml.api.DMLScript \ -f ${SCRIPT_FILE} \ -exec singlenode \ --config=$CURRENT_PATH"/SystemML-config.xml" \ +-config $CURRENT_PATH"/SystemML-config.xml" \ $@" $CMD http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/AutomatedTestBase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/AutomatedTestBase.java b/src/test/java/org/apache/sysml/test/integration/AutomatedTestBase.java index f3ede65..f7071ba 100644 --- a/src/test/java/org/apache/sysml/test/integration/AutomatedTestBase.java +++ b/src/test/java/org/apache/sysml/test/integration/AutomatedTestBase.java @@ -32,7 +32,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import org.apache.sysml.lops.Lop; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.spark.sql.SparkSession; @@ -46,6 +45,7 @@ import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM; import org.apache.sysml.api.MLContext; import org.apache.sysml.conf.DMLConfig; import org.apache.sysml.hops.OptimizerUtils; +import org.apache.sysml.lops.Lop; import org.apache.sysml.parser.DataExpression; import org.apache.sysml.parser.Expression.DataType; import org.apache.sysml.parser.Expression.ValueType; @@ -56,15 +56,19 @@ import org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext; import org.apache.sysml.runtime.io.FrameReader; import org.apache.sysml.runtime.io.FrameReaderFactory; import org.apache.sysml.runtime.matrix.MatrixCharacteristics; -import org.apache.sysml.runtime.matrix.data.InputInfo; -import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; import org.apache.sysml.runtime.matrix.data.CSVFileFormatProperties; import org.apache.sysml.runtime.matrix.data.FrameBlock; +import org.apache.sysml.runtime.matrix.data.InputInfo; +import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex; import org.apache.sysml.runtime.matrix.data.OutputInfo; import org.apache.sysml.runtime.util.MapReduceTool; import org.apache.sysml.test.utils.TestUtils; import org.apache.sysml.utils.ParameterBuilder; import org.apache.sysml.utils.Statistics; +import org.apache.wink.json4j.JSONObject; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; /** @@ -826,7 +830,7 @@ public abstract class AutomatedTestBase * comparison files. * </p> * - * @param configurationName + * @param config * test configuration name * */ @@ -841,7 +845,7 @@ public abstract class AutomatedTestBase * comparison files. * </p> * - * @param configurationName + * @param config * test configuration name * @param cacheDirectory * subdirectory for reusing R script expected results @@ -1219,7 +1223,8 @@ public abstract class AutomatedTestBase throw new RuntimeException("Unknown runtime platform: " + rtplatform); } //use optional config file since default under SystemML/DML - args.add("-config="+ getCurConfigFile().getPath()); + args.add("-config"); + args.add(getCurConfigFile().getPath()); if(TEST_GPU) args.add("-gpu"); @@ -1704,7 +1709,7 @@ public abstract class AutomatedTestBase * * @param name * directory name - * @param matrix + * @param data * two dimensional frame data * @param bIncludeR * generates also the corresponding R frame data http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest1.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest1.java b/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest1.java deleted file mode 100644 index c7006df..0000000 --- a/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest1.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sysml.test.integration.functions.dmlscript; - -import org.junit.Test; - -import org.apache.sysml.test.integration.AutomatedTestBase; -import org.apache.sysml.test.integration.TestConfiguration; - - -/** - * <p> - * <b>Positive tests:</b> - * </p> - * <ul> - * <li>text format</li> - * <li>binary format</li> - * </ul> - * <p> - * <b>Negative tests:</b> - * </p> - * <ul> - * </ul> - * - * - */ -public class DMLScriptTest1 extends AutomatedTestBase -{ - - private final static String TEST_DIR = "functions/dmlscript/"; - private final static String TEST_CLASS_DIR = TEST_DIR + DMLScriptTest1.class.getSimpleName() + "/"; - private final static String TEST_NAME = "DMLScriptTest"; - - @Override - public void setUp() { - // positive tests - TestConfiguration config = new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "a" }); - addTestConfiguration(TEST_NAME, config); - - // negative tests - } - - @Test - public void testWithFile() { - int rows = 10; - int cols = 10; - - TestConfiguration config = getTestConfiguration(TEST_NAME); - config.addVariable("rows", rows); - config.addVariable("cols", cols); - config.addVariable("format", "text"); - loadTestConfiguration(config); - - String HOME = SCRIPT_DIR + TEST_DIR; - fullDMLScriptName = HOME + "DMLScriptTest.dml"; - - programArgs = new String[]{"-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - - double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); - writeInputMatrix("a", a, true); - - runTest(true, false, null, -1); - - programArgs = new String[]{"-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - programArgs = new String[]{"-exec", "hybrid", "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - programArgs = new String[]{"-exec", "hybrid", "-config=" + HOME + "SystemML-config.xml", - "-args", input("a"), Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - } - - @Test - public void testWithString() { - String s = " A = read($1, rows=$2, cols=$3, format=$4); \n " + - "write(A, $5, format=$4); \n"; - int rows = 10; - int cols = 10; - String HOME = SCRIPT_DIR + TEST_DIR; - - TestConfiguration config = getTestConfiguration(TEST_NAME); - config.addVariable("rows", rows); - config.addVariable("cols", cols); - config.addVariable("format", "text"); - loadTestConfiguration(config); - - programArgs = new String[]{"-s", s, "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - - double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); - writeInputMatrix("a", a, true); - - runTest(true, false, null, -1); - - programArgs = new String[]{"-s", s, "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - programArgs = new String[]{"-s", s, "-config=" + HOME + "SystemML-config.xml", "-exec", "hybrid", - "-args", input("a"), Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - } -} http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest2.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest2.java b/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest2.java deleted file mode 100644 index 123146c..0000000 --- a/src/test/java/org/apache/sysml/test/integration/functions/dmlscript/DMLScriptTest2.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sysml.test.integration.functions.dmlscript; - -import org.junit.Test; - -import org.apache.sysml.api.DMLException; -import org.apache.sysml.test.integration.AutomatedTestBase; -import org.apache.sysml.test.integration.TestConfiguration; - - -/** - * <p> - * <b>Positive tests:</b> - * </p> - * <ul> - * <li>text format</li> - * <li>binary format</li> - * </ul> - * <p> - * <b>Negative tests:</b> - * </p> - * <ul> - * </ul> - * - * - */ -public class DMLScriptTest2 extends AutomatedTestBase -{ - - private final static String TEST_DIR = "functions/dmlscript/"; - private final static String TEST_CLASS_DIR = TEST_DIR + DMLScriptTest2.class.getSimpleName() + "/"; - private final static String TEST_NAME = "DMLScriptTest2"; - - /** - * Main method for running one test at a time. - */ - public static void main(String[] args) { - long startMsec = System.currentTimeMillis(); - - DMLScriptTest2 t = new DMLScriptTest2(); - t.setUpBase(); - t.setUp(); - t.testWithString(); - t.tearDown(); - - long elapsedMsec = System.currentTimeMillis() - startMsec; - System.err.printf("Finished in %1.3f sec\n", elapsedMsec / 1000.0); - } - - @Override - public void setUp() { - // positive tests - - // negative tests - TestConfiguration config = new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "a" }); - addTestConfiguration(TEST_NAME, config); - } - - @Test - public void testWithFile() { - int rows = 10; - int cols = 10; - String HOME = SCRIPT_DIR + TEST_DIR; - - TestConfiguration config = getTestConfiguration(TEST_NAME); - config.addVariable("rows", rows); - config.addVariable("cols", cols); - config.addVariable("format", "text"); - loadTestConfiguration(config); - - double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); - writeInputMatrix("a", a, true); - - //Expect to print out an ERROR message. -f or -s must be the first argument. - fullDMLScriptName = HOME + "DMLScriptTest.dml"; - programArgs = new String[]{ "-exec", "hybrid", "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - //Expect to print out an ERROR message. -args should be the last argument. - programArgs = new String[]{"-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a"), "-exec", "hybrid"}; - runTest(true, true, DMLException.class, -1); - - //Expect to print out an ERROR message, -de is an unknown argument - programArgs = new String[]{"-de", "-exec", "hybrid", "-config=" + HOME + "SystemML-config.xml", - "-args", input("a"), Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - //Expect to print out an ERROR message, -config syntax is -config=<config file> - programArgs = new String[]{"-exec", "hybrid", "-config", HOME + "SystemML-config.xml", - "-args", input("a"), Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - } - - @Test - public void testWithString() { - String s = " A = read($1, rows=$2, cols=$3, format=$4); \n " + - "write(A, $5, format=$4); \n"; - int rows = 10; - int cols = 10; - String HOME = SCRIPT_DIR + TEST_DIR; - - TestConfiguration config = availableTestConfigurations.get("DMLScriptTest2"); - config.addVariable("rows", rows); - config.addVariable("cols", cols); - config.addVariable("format", "text"); - loadTestConfiguration(config); - - double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1); - writeInputMatrix("a", a, true); - - //Expect to print out an ERROR message. -f or -s must be the first argument. - programArgs = new String[]{ "-v", "-s", s, "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - //Expect to print out an ERROR message. -args should be the last argument. - programArgs = new String[]{"-s", s, "-args", "-v", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - //Expect to print out an ERROR message, -de is an unknown argument - programArgs = new String[]{"-s", s, "-de", "-args", input("a"), - Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - - //Expect to print out an ERROR message, -config syntax is -config=<config file> - programArgs = new String[]{"-s", s, "-config", HOME + "SystemML-config.xml", "-exec", "hybrid", - "-args", input("a"), Integer.toString(rows), Integer.toString(cols), "text", output("a")}; - runTest(true, false, null, -1); - } -} http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/functions/misc/DataTypeChangeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/misc/DataTypeChangeTest.java b/src/test/java/org/apache/sysml/test/integration/functions/misc/DataTypeChangeTest.java index 899037c..6462969 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/misc/DataTypeChangeTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/misc/DataTypeChangeTest.java @@ -148,11 +148,7 @@ public class DataTypeChangeTest extends AutomatedTestBase public void testDataTypeChangeValidate4f() { runTest("dt_change_4f", false); } - /** - * - * @param cfc - * @param vt - */ + private void runTest( String testName, boolean exceptionExpected ) { String RI_HOME = SCRIPT_DIR + TEST_DIR; @@ -166,11 +162,7 @@ public class DataTypeChangeTest extends AutomatedTestBase runTest(true, exceptionExpected, DMLException.class, -1); } - /** - * - * @param scriptFilename - * @param expectedException - */ + private void runValidateTest( String fullTestName, boolean expectedException ) { boolean raisedException = false; @@ -197,7 +189,7 @@ public class DataTypeChangeTest extends AutomatedTestBase } //parsing and dependency analysis - ParserWrapper parser = ParserFactory.createParser(false); + ParserWrapper parser = ParserFactory.createParser(org.apache.sysml.api.mlcontext.ScriptType.DML); DMLProgram prog = parser.parse(DMLScript.DML_FILE_PATH_ANTLR_PARSER, dmlScriptString, argVals); DMLTranslator dmlt = new DMLTranslator(prog); dmlt.liveVariableAnalysis(prog); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/functions/parfor/ParForDependencyAnalysisTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/parfor/ParForDependencyAnalysisTest.java b/src/test/java/org/apache/sysml/test/integration/functions/parfor/ParForDependencyAnalysisTest.java index 76d7ffa..049b704 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/parfor/ParForDependencyAnalysisTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/parfor/ParForDependencyAnalysisTest.java @@ -351,7 +351,7 @@ public class ParForDependencyAnalysisTest extends AutomatedTestBase } //parsing and dependency analysis - ParserWrapper parser = ParserFactory.createParser(false); + ParserWrapper parser = ParserFactory.createParser(org.apache.sysml.api.mlcontext.ScriptType.DML); DMLProgram prog = parser.parse(DMLScript.DML_FILE_PATH_ANTLR_PARSER, dmlScriptString, argVals); DMLTranslator dmlt = new DMLTranslator(prog); dmlt.validateParseTree(prog); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformFrameEncodeDecodeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformFrameEncodeDecodeTest.java b/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformFrameEncodeDecodeTest.java index 68b434b..a879356 100644 --- a/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformFrameEncodeDecodeTest.java +++ b/src/test/java/org/apache/sysml/test/integration/functions/transform/TransformFrameEncodeDecodeTest.java @@ -19,8 +19,6 @@ package org.apache.sysml.test.integration.functions.transform; -import org.junit.Assert; -import org.junit.Test; import org.apache.sysml.api.DMLScript; import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM; import org.apache.sysml.hops.OptimizerUtils; @@ -34,6 +32,8 @@ import org.apache.sysml.test.integration.AutomatedTestBase; import org.apache.sysml.test.integration.TestConfiguration; import org.apache.sysml.test.utils.TestUtils; import org.apache.sysml.utils.Statistics; +import org.junit.Assert; +import org.junit.Test; public class TransformFrameEncodeDecodeTest extends AutomatedTestBase { @@ -161,8 +161,15 @@ public class TransformFrameEncodeDecodeTest extends AutomatedTestBase "DATA=" + HOME + "input/" + DATASET, "TFSPEC=" + HOME + "input/" + SPEC, "TFDATA=" + output("tfout"), "SEP=,", - "OFMT=" + ofmt, "OSEP=\",\"" }; - + "OFMT=" + ofmt, "OSEP=," }; + + // Originally OSEP was set to + // OSEP="," + // Apache Commons CLI strips away the leading and trailing quotes, leaving us with + // OSEP=", + // This is just a feature/bug and is reported in CLI-262, + // though even a fix is unlikely to be backported to 1.2 + OptimizerUtils.ALLOW_FRAME_CSV_REBLOCK = true; runTest(true, false, null, -1); http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test/java/org/apache/sysml/test/unit/CLIOptionsParserTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/unit/CLIOptionsParserTest.java b/src/test/java/org/apache/sysml/test/unit/CLIOptionsParserTest.java new file mode 100644 index 0000000..8018bcf --- /dev/null +++ b/src/test/java/org/apache/sysml/test/unit/CLIOptionsParserTest.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sysml.test.unit; + +import java.util.Map; + +import org.apache.commons.cli.AlreadySelectedException; +import org.apache.commons.cli.MissingOptionException; +import org.apache.commons.cli.Options; +import org.apache.commons.cli.ParseException; +import org.apache.sysml.api.DMLScript; +import org.apache.sysml.api.mlcontext.ScriptType; +import org.apache.sysml.utils.Explain; +import org.junit.Assert; +import org.junit.Test; + + +public class CLIOptionsParserTest { + + @Test(expected = MissingOptionException.class) + public void testNoOptions() throws Exception { + String cl = "systemml"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test + public void testFile() throws Exception { + String cl = "systemml -f test.dml"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals("test.dml", o.filePath); + Assert.assertEquals(ScriptType.DML, o.scriptType); + + } + + @Test + public void testScript() throws Exception { + String cl = "systemml -s \"print('hello')\""; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals("print('hello')", o.script); + } + + @Test + public void testConfig() throws Exception { + String cl = "systemml -s \"print('hello')\" -config SystemML-config.xml"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals("print('hello')", o.script); + Assert.assertEquals("SystemML-config.xml", o.configFile); + } + + @Test + public void testDebug() throws Exception { + String cl = "systemml -s \"print('hello')\" -debug"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals("print('hello')", o.script); + Assert.assertEquals(true, o.debug); + } + + @Test + public void testClean() throws Exception { + String cl = "systemml -clean"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.clean); + } + + @Test(expected = AlreadySelectedException.class) + public void testBadClean() throws Exception { + String cl = "systemml -clean -f test.dml"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test(expected = AlreadySelectedException.class) + public void testBadScript() throws Exception { + String cl = "systemml -f test.dml -s \"print('hello')\""; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test + public void testStats() throws Exception { + String cl = "systemml -f test.dml -stats"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.stats); + Assert.assertEquals(10, o.statsCount); + } + + @Test + public void testStatsCount() throws Exception { + String cl = "systemml -f test.dml -stats 9123"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.stats); + Assert.assertEquals(9123, o.statsCount); + } + + @Test(expected = ParseException.class) + public void testBadStats() throws Exception { + String cl = "systemml -f test.dml -stats help"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.stats); + } + + @Test + public void testGPUForce() throws Exception { + String cl = "systemml -f test.dml -gpu force"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.gpu); + Assert.assertEquals(true, o.forceGPU); + } + + @Test(expected = ParseException.class) + public void testBadGPUOption() throws Exception { + String cl = "systemml -f test.dml -gpu f2orce"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test + public void testPython() throws Exception { + String cl = "systemml -f test.dml -python"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(ScriptType.PYDML, o.scriptType); + } + + @Test + public void testHelp() throws Exception { + String cl = "systemml -help"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.help); + } + + @Test(expected = AlreadySelectedException.class) + public void testBadHelp() throws Exception { + String cl = "systemml -help -clean"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(true, o.help); + } + + @Test + public void testExplain1() throws Exception { + String cl = "systemml -f test.dml -explain"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(Explain.ExplainType.RUNTIME, o.explainType); + } + + @Test + public void testExplain2() throws Exception { + String cl = "systemml -f test.dml -explain hops"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(Explain.ExplainType.HOPS, o.explainType); + } + + @Test + public void testExplain3() throws Exception { + String cl = "systemml -f test.dml -explain runtime"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(Explain.ExplainType.RUNTIME, o.explainType); + } + + @Test + public void testExplain4() throws Exception { + String cl = "systemml -f test.dml -explain recompile_hops"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(Explain.ExplainType.RECOMPILE_HOPS, o.explainType); + } + + @Test + public void testExplain5() throws Exception { + String cl = "systemml -f test.dml -explain recompile_runtime"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(Explain.ExplainType.RECOMPILE_RUNTIME, o.explainType); + } + + @Test + public void testExec1() throws Exception { + String cl = "systemml -f test.dml -exec hadoop"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(DMLScript.RUNTIME_PLATFORM.HADOOP, o.execMode); + } + + @Test + public void testExec2() throws Exception { + String cl = "systemml -f test.dml -exec spark"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(DMLScript.RUNTIME_PLATFORM.SPARK, o.execMode); + } + + @Test + public void testExec3() throws Exception { + String cl = "systemml -f test.dml -exec singlenode"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(DMLScript.RUNTIME_PLATFORM.SINGLE_NODE, o.execMode); + } + + @Test + public void testExec4() throws Exception { + String cl = "systemml -f test.dml -exec hybrid"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(DMLScript.RUNTIME_PLATFORM.HYBRID, o.execMode); + } + + @Test + public void testExec5() throws Exception { + String cl = "systemml -f test.dml -exec hybrid_spark"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Assert.assertEquals(DMLScript.RUNTIME_PLATFORM.HYBRID_SPARK, o.execMode); + } + + @Test(expected = ParseException.class) + public void testBadExec() throws Exception { + String cl = "systemml -f test.dml -exec new_system"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test + public void testArgs1() throws Exception { + String cl = "systemml -f test.dml -args 10 \"x.csv\""; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals(2, m.size()); + Assert.assertEquals("10", m.get("$1")); + Assert.assertEquals("x.csv", m.get("$2")); + } + + @Test + public void testArgs2() throws Exception { + String cl = "systemml -f test.dml -args 10 \"x.csv\" 1234.2 systemml.conf -config systemml.conf"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals(4, m.size()); + Assert.assertEquals("10", m.get("$1")); + Assert.assertEquals("x.csv", m.get("$2")); + Assert.assertEquals("1234.2", m.get("$3")); + Assert.assertEquals("systemml.conf", m.get("$4")); + } + + @Test(expected = ParseException.class) + public void testBadArgs1() throws Exception { + String cl = "systemml -f test.dml -args -config systemml.conf"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test + public void testNVArgs1() throws Exception { + String cl = "systemml -f test.dml -nvargs A=12 B=x.csv my123=12.2"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals(3, m.size()); + Assert.assertEquals("12", m.get("$A")); + Assert.assertEquals("x.csv", m.get("$B")); + Assert.assertEquals("12.2", m.get("$my123")); + } + + @Test(expected = ParseException.class) + public void testBadNVArgs1() throws Exception { + String cl = "systemml -f test.dml -nvargs"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test(expected = ParseException.class) + public void testBadNVArgs2() throws Exception { + String cl = "systemml -f test.dml -nvargs asd qwe"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test(expected = ParseException.class) + public void testBadNVArgs3() throws Exception { + String cl = "systemml -f test.dml -nvargs $X=12"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + @Test(expected = ParseException.class) + public void testBadNVArgs4() throws Exception { + String cl = "systemml -f test.dml -nvargs 123=123"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.parseCLArguments(args, options); + } + + /** + * For Apache Commons CLI, if an argument to an option is enclosed in quotes, + * the leading and trailing quotes are stripped away. For instance, if the options is -arg and the + * argument is "foo" + * -args "foo" + * Commons CLI will strip the quotes from "foo". This becomes troublesome when you really do + * want to pass in "foo" and not just foo. + * A way around this is to use 'foo` as done in {@link CLIOptionsParserTest#testNVArgs3()} + */ + @Test + public void testNVArgs2() throws Exception { + String cl = "systemml -f test.dml -args \"def\""; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals("def", m.get("$1")); + } + + + /** + * See comment in {@link CLIOptionsParserTest#testNVArgs2()} + */ + @Test + public void testNVArgs3() throws Exception { + String cl = "systemml -f test.dml -args 'def'"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals("'def'", m.get("$1")); + } + + /** + * See comment in {@link CLIOptionsParserTest#testNVArgs2()} + * Additionally, if we try to pass something like + * -nvargs X="foo" + * Commons CLI will strip the leading and trailing quotes (viz. double quotes), which + * causes it to return + * X="foo + * The way to overcome this is to enclose the <value> of the <key=value> pair in single quotes + * and strip them away in the parsing code ourselves. + * TODO: Read the javadoc for this method, we can add in this logic if required + */ + @Test + public void testNVArgs4() throws Exception { + String cl = "systemml -f test.dml -nvargs abc='def'"; + String[] args = cl.split(" "); + Options options = DMLScript.createCLIOptions(); + DMLScript.DMLOptions o = DMLScript.parseCLArguments(args, options); + Map<String, String> m = o.argVals; + Assert.assertEquals("'def'", m.get("$abc")); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/32924dc6/src/test_suites/java/org/apache/sysml/test/integration/functions/dmlscript/ZPackageSuite.java ---------------------------------------------------------------------- diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/dmlscript/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/dmlscript/ZPackageSuite.java deleted file mode 100644 index 713c46d..0000000 --- a/src/test_suites/java/org/apache/sysml/test/integration/functions/dmlscript/ZPackageSuite.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.sysml.test.integration.functions.dmlscript; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** Group together the tests in this package into a single suite so that the Maven build - * won't run two of them at once. */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ - DMLScriptTest1.class, - DMLScriptTest2.class -}) - - -/** This class is just a holder for the above JUnit annotations. */ -public class ZPackageSuite { - -}