2424import org .apache .commons .cli .AlreadySelectedException ;
2525import org .apache .commons .cli .MissingOptionException ;
2626import org .apache .commons .cli .ParseException ;
27+ import org .apache .sysds .hops .OptimizerUtils ;
28+ import org .apache .sysds .runtime .instructions .fed .FEDInstruction ;
29+ import org .apache .sysds .runtime .lineage .LineageCacheConfig ;
2730import org .junit .Assert ;
2831import org .junit .Test ;
2932import org .apache .sysds .api .DMLOptions ;
3033import org .apache .sysds .common .Types .ExecMode ;
3134import org .apache .sysds .runtime .lineage .LineageCacheConfig .ReuseCacheType ;
3235import org .apache .sysds .utils .Explain ;
3336
37+ import static org .apache .sysds .api .DMLOptions .parseCLArguments ;
38+
3439@ net .jcip .annotations .NotThreadSafe
3540public class CLIOptionsParserTest {
3641
@@ -450,4 +455,182 @@ public void testNVArgs4() throws Exception {
450455 Map <String , String > m = o .argVals ;
451456 Assert .assertEquals ("'def'" , m .get ("$abc" ));
452457 }
458+
459+ @ Test
460+ public void parseCLArgumentsLineageDAGHEIGHTTest () throws ParseException {
461+ String [] args = new String []{"-f" , "test" , "-lineage" , "policy_dagheight" };
462+ DMLOptions opts = parseCLArguments (args );
463+ Assert .assertTrue (opts .lineage && opts .linCachePolicy == LineageCacheConfig .LineageCachePolicy .DAGHEIGHT );
464+ }
465+
466+ @ Test
467+ public void parseCLIArgumentsLineageEstimateTest () throws ParseException {
468+ String [] args = new String []{"-f" , "test" , "-lineage" , "estimate" };
469+ DMLOptions opts = parseCLArguments (args );
470+ Assert .assertTrue (opts .lineage && opts .lineage_estimate );
471+ }
472+
473+ @ Test
474+ public void parseCLArgumentsGPUTest () throws ParseException {
475+ String [] args = new String []{"-f" , "test" , "-gpu" ,};
476+ DMLOptions opts = parseCLArguments (args );
477+ Assert .assertTrue (opts .gpu );
478+ }
479+
480+ @ Test
481+ public void parseCLArgumentsInvalidExplainTest () throws ParseException {
482+ String [] args = new String []{"-f" , "test" ,"-explain" ,"XYZ" };
483+ try {
484+ parseCLArguments (args );
485+ } catch (ParseException e ) {
486+ assert e .getMessage ().equals ("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime, codegen, codegen_recompile]" );
487+ }
488+ }
489+ @ Test
490+ public void parseCLArgumentsExplainCodegenRecompileTest () throws ParseException {
491+ String [] args = new String []{"-f" , "test" ,"-explain" ,"codegen_recompile" };
492+ DMLOptions opts = parseCLArguments (args );
493+ Assert .assertEquals (opts .explainType , Explain .ExplainType .CODEGEN_RECOMPILE );
494+ }
495+
496+
497+ @ Test
498+ public void parseCLArgumentsNGramsTest1 () throws ParseException {
499+ String [] args = new String []{"-f" , "test" , "-ngrams" ,};
500+ DMLOptions opts = parseCLArguments (args );
501+ Assert .assertTrue (opts .statsNGrams );
502+ }
503+
504+ @ Test
505+ public void parseCLArgumentsNGramsTest2 () throws ParseException {
506+ String [] args = new String []{"-f" , "test" , "-ngrams" ,"1" };
507+ DMLOptions opts = parseCLArguments (args );
508+ Assert .assertTrue (opts .statsNGrams );
509+ }
510+
511+ @ Test
512+ public void parseCLArgumentsNGramsTest3 () throws ParseException {
513+ String [] args = new String []{"-f" , "test" , "-ngrams" ,"1" ,"1" ,"FALSE" };
514+ DMLOptions opts = parseCLArguments (args );
515+ Assert .assertTrue (opts .statsNGrams );
516+ Assert .assertEquals (opts .statsNGramSizes [0 ], 1 );
517+ Assert .assertEquals (opts .statsTopKNGrams , 1 );
518+ Assert .assertFalse (opts .statsNGramsUseLineage );
519+ }
520+
521+ @ Test
522+ public void parseCLArgumentsNGramsTest4 () throws ParseException {
523+ String [] args = new String []{"-f" , "test" , "-ngrams" ,"1,3" ,"1" };
524+ DMLOptions opts = parseCLArguments (args );
525+ Assert .assertTrue (opts .statsNGrams );
526+ Assert .assertEquals (opts .statsNGramSizes [0 ], 1 );
527+ Assert .assertEquals (opts .statsNGramSizes [1 ], 3 );
528+ Assert .assertEquals (opts .statsTopKNGrams , 1 );
529+ Assert .assertTrue (opts .statsNGramsUseLineage );
530+ }
531+
532+ @ Test
533+ public void parseCLArgumentsNGramsTest5 () throws ParseException {
534+ String [] args = new String []{"-f" , "test" ,"-ngrams" ,"1,2" ,"b" };
535+ try {
536+ parseCLArguments (args );
537+ } catch (ParseException e ) {
538+ assert e .getMessage ().equals ("Invalid argument specified for -ngrams option, must be a valid integer" );
539+ }
540+ }
541+
542+ @ Test
543+ public void parseCLArgumentsFEDStatsTest1 () throws ParseException {
544+ String [] args = new String []{"-f" , "test" , "-fedStats" ,};
545+ DMLOptions opts = parseCLArguments (args );
546+ Assert .assertTrue (opts .fedStats );
547+ }
548+
549+ @ Test
550+ public void parseCLArgumentsFEDStatsTest2 () throws ParseException {
551+ String [] args = new String []{"-f" , "test" , "-fedStats" , "21" };
552+ DMLOptions opts = parseCLArguments (args );
553+ Assert .assertTrue (opts .fedStats );
554+ Assert .assertEquals (21 , opts .fedStatsCount );
555+ }
556+
557+ @ Test
558+ public void parseCLArgumentsFEDStatsTest3 () {
559+ String [] args = new String []{"-f" , "test" , "-fedStats" , "xyz" };
560+ try {
561+ parseCLArguments (args );
562+ } catch (ParseException e ) {
563+ assert e .getMessage ().equals ("Invalid argument specified for -fedStats option, must be a valid integer" );
564+ }
565+ }
566+
567+ @ Test
568+ public void parseCLArgumentsFEDMonitoringTest1 () {
569+ String [] args = new String []{"-fedMonitoring" };
570+ try {
571+ parseCLArguments (args );
572+ } catch (ParseException e ) {
573+ assert e .getMessage ().equals ("No port [integer] specified for -fedMonitoring option" );
574+ }
575+ }
576+
577+ @ Test
578+ public void parseCLArgumentsFEDMonitoringTest2 () {
579+ String [] args = new String []{"-fedMonitoring" ,"21" , "-fedMonitoringAddress" };
580+ try {
581+ parseCLArguments (args );
582+ } catch (ParseException e ) {
583+ assert e .getMessage ().equals ("No address [String] specified for -fedMonitoringAddress option" );
584+ }
585+ }
586+
587+ @ Test
588+ public void parseCLArgumentsFEDMonitoringTest3 () throws ParseException {
589+ String [] args = new String []{"-fedMonitoring" , "21" };
590+ DMLOptions opts = parseCLArguments (args );
591+ Assert .assertTrue (opts .fedMonitoring );
592+ Assert .assertEquals (21 , opts .fedMonitoringPort );
593+ }
594+
595+ @ Test
596+ public void parseCLArgumentsFEDMonitoringTest4 () throws ParseException {
597+ String [] args = new String []{"-fedMonitoring" , "21" , "-fedMonitoringAddress" , "xyz" };
598+ DMLOptions opts = parseCLArguments (args );
599+ Assert .assertTrue (opts .fedMonitoring );
600+ Assert .assertEquals (21 , opts .fedMonitoringPort );
601+ Assert .assertEquals ("xyz" , opts .fedMonitoringAddress );
602+ }
603+
604+ @ Test
605+ public void parseCLArgumentsFEDCompilationTest1 () throws ParseException {
606+ String [] args = new String []{"-f" , "test" , "-federatedCompilation" };
607+ DMLOptions opts = parseCLArguments (args );
608+ Assert .assertTrue (opts .federatedCompilation );
609+ }
610+
611+ @ Test
612+ public void parseCLArgumentsFEDCompilationTest2 () throws ParseException {
613+ String [] args = new String []{"-f" , "test" , "-federatedCompilation" , "1=NONE" };
614+ DMLOptions opts = parseCLArguments (args );
615+ Assert .assertTrue (opts .federatedCompilation );
616+ Assert .assertEquals (OptimizerUtils .FEDERATED_SPECS .get (1 ), FEDInstruction .FederatedOutput .NONE );
617+ }
618+
619+ @ Test
620+ public void parseCLArgumentsFEDCompilationTest3 () {
621+ String [] args = new String []{"-f" ,"test" , "-federatedCompilation" ,"1=n=n" };
622+ try {
623+ parseCLArguments (args );
624+ throw new AssertionError ("Test should have resulted in Exception" );
625+ } catch (ParseException e ){
626+ Assert .assertEquals ("Invalid argument specified for -federatedCompilation option, must be a list of space separated K=V pairs, where K is a line number of the DML script and V is a federated output value" ,e .getMessage ());
627+ }
628+ }
629+
630+ @ Test
631+ public void parseCLArgumentsFEDNoRuntimeConversionTest () throws ParseException {
632+ String [] args = new String []{"-f" , "test" , "-noFedRuntimeConversion" };
633+ DMLOptions opts = parseCLArguments (args );
634+ Assert .assertTrue (opts .noFedRuntimeConversion );
635+ }
453636}
0 commit comments