Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba3e1a0

Browse files
committedMar 5, 2025·
DML Options Code Coverage
1 parent cfbe190 commit ba3e1a0

File tree

2 files changed

+155
-38
lines changed

2 files changed

+155
-38
lines changed
 

‎src/main/java/org/apache/sysds/api/DMLOptions.java

+40-38
Original file line numberDiff line numberDiff line change
@@ -141,34 +141,32 @@ public static DMLOptions parseCLArguments(String[] args)
141141
String lineageTypes[] = line.getOptionValues("lineage");
142142
if (lineageTypes != null) {
143143
for (String lineageType : lineageTypes) {
144-
if (lineageType != null){
145-
if (lineageType.equalsIgnoreCase("dedup"))
146-
dmlOptions.lineage_dedup = lineageType.equalsIgnoreCase("dedup");
147-
else if (lineageType.equalsIgnoreCase("reuse_full")
148-
|| lineageType.equalsIgnoreCase("reuse"))
149-
dmlOptions.linReuseType = ReuseCacheType.REUSE_FULL;
150-
else if (lineageType.equalsIgnoreCase("reuse_partial"))
151-
dmlOptions.linReuseType = ReuseCacheType.REUSE_PARTIAL;
152-
else if (lineageType.equalsIgnoreCase("reuse_multilevel"))
153-
dmlOptions.linReuseType = ReuseCacheType.REUSE_MULTILEVEL;
154-
else if (lineageType.equalsIgnoreCase("reuse_hybrid"))
155-
dmlOptions.linReuseType = ReuseCacheType.REUSE_HYBRID;
156-
else if (lineageType.equalsIgnoreCase("none"))
157-
dmlOptions.linReuseType = ReuseCacheType.NONE;
158-
else if (lineageType.equalsIgnoreCase("policy_lru"))
159-
dmlOptions.linCachePolicy = LineageCachePolicy.LRU;
160-
else if (lineageType.equalsIgnoreCase("policy_costnsize"))
161-
dmlOptions.linCachePolicy = LineageCachePolicy.COSTNSIZE;
162-
else if (lineageType.equalsIgnoreCase("policy_dagheight"))
163-
dmlOptions.linCachePolicy = LineageCachePolicy.DAGHEIGHT;
164-
else if (lineageType.equalsIgnoreCase("estimate"))
165-
dmlOptions.lineage_estimate = lineageType.equalsIgnoreCase("estimate");
166-
else if (lineageType.equalsIgnoreCase("debugger"))
167-
dmlOptions.lineage_debugger = lineageType.equalsIgnoreCase("debugger");
168-
else
169-
throw new org.apache.commons.cli.ParseException(
170-
"Invalid argument specified for -lineage option: " + lineageType);
171-
}
144+
if (lineageType.equalsIgnoreCase("dedup"))
145+
dmlOptions.lineage_dedup = lineageType.equalsIgnoreCase("dedup");
146+
else if (lineageType.equalsIgnoreCase("reuse_full")
147+
|| lineageType.equalsIgnoreCase("reuse"))
148+
dmlOptions.linReuseType = ReuseCacheType.REUSE_FULL;
149+
else if (lineageType.equalsIgnoreCase("reuse_partial"))
150+
dmlOptions.linReuseType = ReuseCacheType.REUSE_PARTIAL;
151+
else if (lineageType.equalsIgnoreCase("reuse_multilevel"))
152+
dmlOptions.linReuseType = ReuseCacheType.REUSE_MULTILEVEL;
153+
else if (lineageType.equalsIgnoreCase("reuse_hybrid"))
154+
dmlOptions.linReuseType = ReuseCacheType.REUSE_HYBRID;
155+
else if (lineageType.equalsIgnoreCase("none"))
156+
dmlOptions.linReuseType = ReuseCacheType.NONE;
157+
else if (lineageType.equalsIgnoreCase("policy_lru"))
158+
dmlOptions.linCachePolicy = LineageCachePolicy.LRU;
159+
else if (lineageType.equalsIgnoreCase("policy_costnsize"))
160+
dmlOptions.linCachePolicy = LineageCachePolicy.COSTNSIZE;
161+
else if (lineageType.equalsIgnoreCase("policy_dagheight"))
162+
dmlOptions.linCachePolicy = LineageCachePolicy.DAGHEIGHT;
163+
else if (lineageType.equalsIgnoreCase("estimate"))
164+
dmlOptions.lineage_estimate = true;
165+
else if (lineageType.equalsIgnoreCase("debugger"))
166+
dmlOptions.lineage_debugger = true;
167+
else
168+
throw new org.apache.commons.cli.ParseException(
169+
"Invalid argument specified for -lineage option: " + lineageType);
172170
}
173171
}
174172
}
@@ -186,13 +184,11 @@ else if (lineageType.equalsIgnoreCase("debugger"))
186184
}
187185
if (line.hasOption("exec")){
188186
String execMode = line.getOptionValue("exec");
189-
if (execMode != null){
190-
if (execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = ExecMode.SINGLE_NODE;
191-
else if (execMode.equalsIgnoreCase("hybrid")) dmlOptions.execMode = ExecMode.HYBRID;
192-
else if (execMode.equalsIgnoreCase("spark")) dmlOptions.execMode = ExecMode.SPARK;
193-
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -exec option, must be one of [hadoop, singlenode, hybrid, HYBRID, spark]");
194-
}
195-
}
187+
if (execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = ExecMode.SINGLE_NODE;
188+
else if (execMode.equalsIgnoreCase("hybrid")) dmlOptions.execMode = ExecMode.HYBRID;
189+
else if (execMode.equalsIgnoreCase("spark")) dmlOptions.execMode = ExecMode.SPARK;
190+
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -exec option, must be one of [hadoop, singlenode, hybrid, HYBRID, spark]");
191+
}
196192
if (line.hasOption("explain")) {
197193
dmlOptions.explainType = ExplainType.RUNTIME;
198194
String explainType = line.getOptionValue("explain");
@@ -222,7 +218,7 @@ else if (lineageType.equalsIgnoreCase("debugger"))
222218
dmlOptions.statsNGrams = line.hasOption("ngrams");
223219
if (dmlOptions.statsNGrams){
224220
String[] nGramArgs = line.getOptionValues("ngrams");
225-
if (nGramArgs.length >= 2) {
221+
if (nGramArgs != null && nGramArgs.length >= 2) {
226222
try {
227223
String[] nGramSizeSplit = nGramArgs[0].split(",");
228224
dmlOptions.statsNGramSizes = new int[nGramSizeSplit.length];
@@ -273,11 +269,17 @@ else if (lineageType.equalsIgnoreCase("debugger"))
273269

274270
if (line.hasOption("fedMonitoring")) {
275271
dmlOptions.fedMonitoring= true;
276-
dmlOptions.fedMonitoringPort = Integer.parseInt(line.getOptionValue("fedMonitoring"));
272+
String port = line.getOptionValue("fedMonitoring");
273+
if(port != null)
274+
dmlOptions.fedMonitoringPort = Integer.parseInt(port);
275+
else
276+
throw new org.apache.commons.cli.ParseException("No port [integer] specified for -fedMonitoring option");
277277
}
278278

279279
if (line.hasOption("fedMonitoringAddress")) {
280280
dmlOptions.fedMonitoringAddress = line.getOptionValue("fedMonitoringAddress");
281+
if(dmlOptions.fedMonitoringAddress == null)
282+
throw new org.apache.commons.cli.ParseException("No address [String] specified for -fedMonitoringAddress option");
281283
}
282284

283285
if (line.hasOption("f")){
@@ -326,7 +328,7 @@ else if (lineageType.equalsIgnoreCase("debugger"))
326328
OptimizerUtils.FEDERATED_COMPILATION = true;
327329
dmlOptions.federatedCompilation = true;
328330
String[] fedCompSpecs = line.getOptionValues("federatedCompilation");
329-
if ( fedCompSpecs != null && fedCompSpecs.length > 0 ){
331+
if (fedCompSpecs != null){
330332
for ( String spec : fedCompSpecs ){
331333
String[] specPair = spec.split("=");
332334
if (specPair.length != 2){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.apache.sysds.test.api;
2+
3+
import org.apache.commons.cli.ParseException;
4+
import org.apache.sysds.api.DMLOptions;
5+
import org.apache.sysds.runtime.lineage.LineageCacheConfig;
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
import javax.validation.constraints.AssertTrue;
10+
11+
import static org.apache.sysds.api.DMLOptions.parseCLArguments;
12+
13+
public class DMLOptionsTest {
14+
15+
@Test
16+
public void parseCLArgumentsLineageTest() throws ParseException {
17+
String[] args = new String[]{"-f", "test", "-lineage", "policy_dagheight"};
18+
DMLOptions opts = parseCLArguments(args);
19+
Assert.assertTrue(opts.lineage && opts.linCachePolicy == LineageCacheConfig.LineageCachePolicy.DAGHEIGHT);
20+
21+
args = new String[]{"-f", "test", "-lineage", "estimate"};
22+
opts = parseCLArguments(args);
23+
Assert.assertTrue(opts.lineage && opts.lineage_estimate);
24+
}
25+
26+
@Test
27+
public void parseCLArgumentsGPUExplainTest() throws ParseException {
28+
String[] args = new String[]{"-f", "test", "-gpu",};
29+
parseCLArguments(args);
30+
args = new String[]{"-f", "test","-explain","XYZ"};
31+
try {
32+
parseCLArguments(args);
33+
} catch (ParseException e) {
34+
assert e.getMessage().equals("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime, codegen, codegen_recompile]");
35+
}
36+
}
37+
38+
@Test
39+
public void parseCLArgumentsNGramsTest() throws ParseException {
40+
String[] args = new String[]{"-f", "test", "-ngrams",};
41+
parseCLArguments(args);
42+
args = new String[]{"-f", "test", "-ngrams","1"};
43+
parseCLArguments(args);
44+
args = new String[]{"-f", "test", "-ngrams","1","1","FALSE"};
45+
parseCLArguments(args);
46+
args = new String[]{"-f", "test","-ngrams","1,2","b"};
47+
try {
48+
parseCLArguments(args);
49+
} catch (ParseException e) {
50+
assert e.getMessage().equals("Invalid argument specified for -ngrams option, must be a valid integer");
51+
}
52+
}
53+
54+
@Test
55+
public void parseCLArgumentsFEDStatsTest() throws ParseException {
56+
String[] args = new String[]{"-f", "test", "-fedStats",};
57+
parseCLArguments(args);
58+
59+
args = new String[]{"-f", "test", "-fedStats", "21"};
60+
DMLOptions opts = parseCLArguments(args);
61+
Assert.assertEquals(21, opts.fedStatsCount);
62+
63+
args = new String[]{"-f", "test", "-fedStats", "xyz"};
64+
try {
65+
parseCLArguments(args);
66+
} catch (ParseException e) {
67+
assert e.getMessage().equals("Invalid argument specified for -fedStats option, must be a valid integer");
68+
}
69+
}
70+
71+
@Test
72+
public void parseCLArgumentsFEDMonitoringTest() throws ParseException {
73+
String[] args = new String[]{"-fedMonitoring"};
74+
try {
75+
parseCLArguments(args);
76+
} catch (ParseException e) {
77+
assert e.getMessage().equals("No port [integer] specified for -fedMonitoring option");
78+
}
79+
80+
args = new String[]{"-fedMonitoring","21", "-fedMonitoringAddress"};
81+
try {
82+
parseCLArguments(args);
83+
} catch (ParseException e) {
84+
assert e.getMessage().equals("No address [String] specified for -fedMonitoringAddress option");
85+
}
86+
87+
args = new String[]{"-fedMonitoring", "21"};
88+
DMLOptions opts = parseCLArguments(args);
89+
Assert.assertTrue(opts.fedMonitoring);
90+
Assert.assertEquals(21, opts.fedMonitoringPort);
91+
92+
args = new String[]{"-fedMonitoring", "21", "-fedMonitoringAddress", "xyz"};
93+
opts = parseCLArguments(args);
94+
Assert.assertTrue(opts.fedMonitoring);
95+
Assert.assertEquals(21, opts.fedMonitoringPort);
96+
Assert.assertEquals("xyz", opts.fedMonitoringAddress);
97+
}
98+
99+
@Test
100+
public void parseCLArgumentsFEDCompilationTest() throws ParseException {
101+
String[] args = new String[]{"-f", "test", "-federatedCompilation"};
102+
parseCLArguments(args);
103+
104+
args = new String[]{"-f", "test", "-federatedCompilation", "1=NONE"};
105+
DMLOptions opts = parseCLArguments(args);
106+
Assert.assertTrue(opts.federatedCompilation);
107+
}
108+
@Test
109+
public void parseCLArgumentsFEDNoRuntimeConversonTest() throws ParseException {
110+
String[] args = new String[]{"-f", "test", "-noFedRuntimeConversion"};
111+
DMLOptions opts = parseCLArguments(args);
112+
Assert.assertTrue(opts.noFedRuntimeConversion);
113+
}
114+
115+
}

0 commit comments

Comments
 (0)
Please sign in to comment.