-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
TLC.java
1720 lines (1599 loc) · 69.8 KB
/
TLC.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2003 Compaq Corporation. All rights reserved.
// Portions Copyright (c) 2003 Microsoft Corporation. All rights reserved.
// Last modified on Thu 10 April 2008 at 14:31:23 PST by lamport
// modified on Wed Dec 5 22:37:20 PST 2001 by yuanyu
package tlc2;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import model.InJarFilenameToStream;
import model.ModelInJar;
import tlc2.debug.TLCDebugger;
import tlc2.output.EC;
import tlc2.output.ErrorTraceMessagePrinterRecorder;
import tlc2.output.MP;
import tlc2.output.Messages;
import tlc2.tool.DFIDModelChecker;
import tlc2.tool.ITool;
import tlc2.tool.ModelChecker;
import tlc2.tool.Simulator;
import tlc2.tool.SingleThreadedSimulator;
import tlc2.tool.fp.FPSet;
import tlc2.tool.fp.FPSetConfiguration;
import tlc2.tool.fp.FPSetFactory;
import tlc2.tool.impl.DebugTool;
import tlc2.tool.impl.FastTool;
import tlc2.tool.impl.ParameterizedSpecObj;
import tlc2.tool.impl.ParameterizedSpecObj.PostCondition;
import tlc2.tool.impl.Tool;
import tlc2.tool.management.ModelCheckerMXWrapper;
import tlc2.tool.management.TLCStandardMBean;
import tlc2.tool.queue.IStateQueue;
import tlc2.util.DotStateWriter;
import tlc2.util.FP64;
import tlc2.util.IStateWriter;
import tlc2.util.NoopStateWriter;
import tlc2.util.RandomGenerator;
import tlc2.util.StateWriter;
import tlc2.value.RandomEnumerableValues;
import util.Assert.TLCRuntimeException;
import util.DebugPrinter;
import util.ExecutionStatisticsCollector;
import util.FileUtil;
import util.FilenameToStream;
import util.MailSender;
import util.SimpleFilenameToStream;
import util.TLAConstants;
import util.TLCRuntime;
import util.ToolIO;
import util.UniqueString;
import util.UsageGenerator;
/**
* Main TLC starter class.
*
* <b>Note:</b> If you are using a new instance of this class in an already existant JVM which has done processing with
* tlc2 parsers, please see the class javadocs for {@link TLCRunner}
*
* @author Yuan Yu
* @author Leslie Lamport
* @author Simon Zambrovski
*/
public class TLC {
/**
* Whether the TLA+ spec is encoded in a .jar file, not a TLA+ text file.
*/
private static boolean MODEL_PART_OF_JAR = false;
/**
* Possible TLC run modes: either model checking or simulation.
*/
public enum RunMode {
MODEL_CHECK, SIMULATE;
}
// SZ Feb 20, 2009: the class has been
// transformed from static to dynamic
/**
* Whether to run in model checking or simulation mode.
* Defaults to model checking.
*/
private RunMode runMode;
/**
* Whether to clean up the states directory.
*/
private boolean cleanup;
/**
* Whether to check for deadlock.
*/
private boolean deadlock;
/**
* Whether a seed for the random number generator was provided.
*/
private boolean noSeed;
/**
* The seed for the random number generator.
*/
private long seed;
/**
* Adjustment for random number generator seed.
*/
private long aril;
/**
* TLC processing start time.
*/
private long startTime;
/**
* Name of main TLA+ specification file.
*/
private String mainFile;
private String configFile;
private String metadir;
/**
* If instantiated with a non-Noop* instance, the trace will be written to the
* user provided file (-dump parameter).
* <p>
* Contrary to plain -dump, -dot will also write out transitions from state s to
* s' if s' is already known. Thus, the resulting graph shows all successors of
* s instead of just s's unexplored ones.
* <p>
* Off (NoopStateWriter) by default.
*/
private IStateWriter stateWriter = new NoopStateWriter();
/**
* Name of checkpoint from which TLC should recover.
*/
private String fromChkpt;
/**
* Fingerprint set function index to use.
* By default one is picked at random.
*/
private int fpIndex;
/**
* The number of traces/behaviors to generate in simulation mode
*/
private static long traceNum = Long.MAX_VALUE;
/**
* Name of the file to which to write state traces.
*/
private String traceFile = null;
private String traceActions = null;
/**
* Maximum state trace depth. Set to 100 by default.
*/
private int traceDepth;
private FilenameToStream resolver;
/**
* Whether welcome message has already been printed.
*/
private boolean welcomePrinted;
/**
* Fingerprint set configuration.
*/
private FPSetConfiguration fpSetConfiguration;
private final Map<String, Object> params;
private int debugPort = -1;
private boolean suspend = !Boolean.getBoolean(TLC.class.getName() + ".nosuspend");
private boolean halt = !Boolean.getBoolean(TLC.class.getName() + ".nohalt");
/**
* Interface to retrieve model properties.
*/
private volatile ITool tool;
/**
* Records errors as TLC runs.
*/
private final ErrorTraceMessagePrinterRecorder recorder = new ErrorTraceMessagePrinterRecorder();
/**
* Trace exploration spec generator.
*/
private TraceExplorationSpec teSpec;
/**
* Initialization
*/
public TLC() {
welcomePrinted = false;
runMode = RunMode.MODEL_CHECK;
cleanup = false;
deadlock = true;
noSeed = true;
seed = 0;
aril = 0;
mainFile = null;
configFile = null;
fromChkpt = null;
resolver = null;
fpIndex = new Random().nextInt(FP64.Polys.length);
traceDepth = 100;
fpSetConfiguration = new FPSetConfiguration();
params = new HashMap<>();
}
/*
* This TLA checker (TLC) provides the following functionalities:
* 1. Simulation of TLA+ specs:
* java tlc2.TLC -simulate spec[.tla]
* 2. Model checking of TLA+ specs:
* java tlc2.TLC [-modelcheck] spec[.tla]
*
* The command line also provides the following options observed for functionalities 1. & 2.:
* o -config file: provide the config file.
* Defaults to spec.cfg if not provided
* o -deadlock: do not check for deadlock.
* Defaults to checking deadlock if not specified
* o -depth num: specify the depth of random simulation
* Defaults to 100 if not specified
* o -seed num: provide the seed for random simulation
* Defaults to a random seed if not specified
* o -aril num: Adjust the seed for random simulation
* Defaults to 0 if not specified
* o -recover path: recover from the checkpoint at path
* Defaults to scratch run if not specified
* o -metadir path: store metadata in the directory at path
* Defaults to specdir/states if not specified
* o -userFile file: A full qualified/absolute path to a file to log user
* output (Print/PrintT/...) to
* o -workers num: the number of TLC worker threads
* Defaults to 1
* o -dfid num: use depth-first iterative deepening with initial depth num
* o -cleanup: clean up the states directory
* o -dumpTrace format file: dump all counter-examples into file in the given format.
* o -dump [dot] file: dump all the states into file. If "dot" as sub-parameter
* is given, the output will be in dot notation.
* o -postCondition mod!op: Evaluate the operator op in module mod after state-space exploration.
* o -difftrace: when printing trace, show only
* the differences between successive states
* Defaults to printing full state descriptions if not specified
* (Added by Rajeev Joshi)
* o -terse: do not expand values in Print statement
* Defaults to expand value if not specified
* o -coverage minutes: collect coverage information on the spec,
* print out the information every minutes.
* Defaults to no coverage if not specified
* o -continue: continue running even when invariant is violated
* Defaults to stop at the first violation if not specified
* o -lncheck: Check liveness properties at different times
* of model checking.
* Defaults to false increasing the overall model checking time.
* o -nowarning: disable all the warnings
* Defaults to report warnings if not specified
* o -fp num: use the num'th irreducible polynomial from the list
* stored in the class FP64.
* o -view: apply VIEW (if provided) when printing out states.
* o -gzip: control if gzip is applied to value input/output stream.
* Defaults to off if not specified
* o -debug: debbuging information (non-production use)
* o -debugger: Activate TLC debugger
* o -tool: tool mode (put output codes on console)
* o -generateSpecTE: will generate SpecTE assets if error-states are
* encountered during model checking; this will change
* to tool mode regardless of whether '-tool' was
* explicitly specified; add on 'nomonolith' to not
* embed the dependencies in the SpecTE
* o -checkpoint num: interval for check pointing (in minutes)
* Defaults to 30
* o -fpmem num: a value between 0 and 1, exclusive, representing the ratio
* of total system memory used to store the fingerprints of
* found states.
* Defaults to 1/4 physical memory. (Added 6 Apr 2010 by Yuan Yu.)
* o -fpbits num: the number of msb used by MultiFPSet to create nested FPSets.
* Defaults to 1
* o -maxSetSize num: the size of the largest set TLC will enumerate.
* Defaults to 1000000
*
*/
public static void main(String[] args) throws Exception
{
final TLC tlc = new TLC();
// Try to parse parameters.
if (!tlc.handleParameters(args)) {
// This is a tool failure. We must exit with a non-zero exit
// code or else we will mislead system tools and scripts into
// thinking everything went smoothly.
//
// FIXME: handleParameters should return an error object (or
// null), where the error object contains an error message.
// This makes handleParameters a function we can test.
System.exit(1);
}
if (!tlc.checkEnvironment()) {
System.exit(1);
}
final MailSender ms = new MailSender();
// Setup how spec files will be resolved in the filesystem.
if (MODEL_PART_OF_JAR) {
// There was not spec file given, it instead exists in the
// .jar file being executed. So we need to use a special file
// resolver to parse it.
tlc.setResolver(new InJarFilenameToStream(ModelInJar.PATH));
} else {
// The user passed us a spec file directly. To ensure we can
// recover it during semantic parsing, we must include its
// parent directory as a library path in the file resolver.
//
// If the spec file has no parent directory, use the "standard"
// library paths provided by SimpleFilenameToStream.
final String dir = FileUtil.parseDirname(tlc.getMainFile());
if (!dir.isEmpty()) {
tlc.setResolver(new SimpleFilenameToStream(dir));
} else {
tlc.setResolver(new SimpleFilenameToStream());
}
}
// Setup MailSender *before* calling tlc.process. The MailSender's task it to
// write the MC.out file. The MC.out file is e.g. used by CloudTLC to feed
// progress back to the Toolbox (see CloudDistributedTLCJob).
ms.setModelName(tlc.getModelName());
ms.setSpecName(tlc.getSpecName());
// Execute TLC.
final int errorCode = tlc.process();
// Send logged output by email.
//
// This is needed when TLC runs on another host and email is
// the only means for the user to get access to the model
// checking results.
boolean mailSent = ms.send(tlc.getModuleFiles());
// Treat failure to send mail as a tool failure.
//
// With distributed TLC and CloudDistributedTLCJob in particular,
// the cloud node is immediately turned off once the TLC process
// has finished. If we were to shutdown the node even when sending
// out the email has failed, the result would be lost.
if (!mailSent) {
System.exit(1);
}
// Be explicit about tool success.
System.exit(EC.ExitStatus.errorConstantToExitStatus(errorCode));
}
// false if the environment (JVM, OS, ...) makes model checking impossible.
// Might also result in warnings.
private boolean checkEnvironment() {
// Not a reasons to refuse startup but warn about non-ideal garbage collector.
// See https://twitter.com/lemmster/status/1089656514892070912 for actual
// performance penalty.
if (!TLCRuntime.getInstance().isThroughputOptimizedGC()) {
MP.printWarning(EC.TLC_ENVIRONMENT_JVM_GC);
}
return true;
}
public static void setTraceNum(long aTraceNum) {
traceNum = aTraceNum;
}
/**
* This method handles parameter arguments and prepares the actual call
* <strong>Note:</strong> This method set ups the static TLCGlobals variables
* @return status of parsing: true iff parameter check was ok, false otherwise
* @throws IOException
*/
// SZ Feb 23, 2009: added return status to indicate the error in parsing
@SuppressWarnings("deprecation") // we're emitting a warning to the user, but still accepting fpmem values > 1
public boolean handleParameters(String[] args)
{
String dumpFile = null;
boolean asDot = false;
boolean colorize = false;
boolean actionLabels = false;
boolean snapshot = false;
boolean constrained = false;
boolean stuttering = false;
boolean strict = false;
boolean generateTESpec = true;
boolean generateTESpecBinaryTrace = true;
boolean forceGenerateTESpec = false;
Path teSpecOut = null;
// SZ Feb 20, 2009: extracted this method to separate the
// parameter handling from the actual processing
int index = 0;
while (index < args.length)
{
if (args[index].equals("-simulate") || args[index].equals("-generate"))
{
if (args[index].equals("-generate")) {
System.setProperty(Tool.class.getName() + ".probabilistic", Boolean.TRUE.toString());
}
runMode = RunMode.SIMULATE;
index++;
// Simulation args can be:
// file=/path/to/file,num=4711 or num=4711,file=/path/to/file or num=4711 or
// file=/path/to/file
// "file=..." and "num=..." are only relevant for simulation which is why they
// are args to "-simulate".
if ((index < args.length) && (args[index].contains("stats=") || args[index].contains("file=")
|| args[index].contains("num=") ||args[index].contains("sched"))) {
final String[] simArgs = args[index].split(",");
index++; // consume simulate args
for (String arg : simArgs) {
if (arg.startsWith("num=")) {
traceNum = Long.parseLong(arg.replace("num=", ""));
} else if (arg.startsWith("file=")) {
traceFile = arg.replace("file=", "");
} else if (arg.equals("stats=basic")) {
traceActions = "BASIC";
} else if (arg.equals("stats=full")) {
traceActions = "FULL";
} else if (arg.equals("sched=rl")) {
System.setProperty(Simulator.class.getName() + ".rl", Boolean.TRUE.toString());
} else if (arg.equals("sched=rlaction")) {
System.setProperty(Simulator.class.getName() + ".rlaction", Boolean.TRUE.toString());
}
}
if(traceNum == Long.MAX_VALUE && traceFile != null) {
printErrorMsg("Error: You need to specify a 'num' argument when using the 'file' argument, for example: '\"num=5,file=test.txt\"'.");
return false;
}
}
} else if (args[index].equals("-modelcheck")) {
index++;
} else if (args[index].equals("-difftrace"))
{
index++;
TLCGlobals.printDiffsOnly = true;
} else if (args[index].equals("-deadlock"))
{
index++;
deadlock = false;
} else if (args[index].equals("-cleanup"))
{
index++;
cleanup = true;
} else if (args[index].equals("-nowarning"))
{
index++;
TLCGlobals.warn = false;
} else if (args[index].equals("-gzip"))
{
index++;
TLCGlobals.useGZIP = true;
} else if (args[index].equals("-terse"))
{
index++;
TLCGlobals.expand = false;
} else if (args[index].equals("-continue"))
{
index++;
TLCGlobals.continuation = true;
} else if (args[index].equals("-view"))
{
index++;
TLCGlobals.useView = true;
} else if (args[index].equals("-debug"))
{
index++;
TLCGlobals.debug = true;
} else if (args[index].equals("-debugger"))
{
index++;
debugPort = 4712; //standard port.
if ((index < args.length) && (args[index].contains("port=") || args[index].contains("nosuspend")
|| args[index].contains("nohalt") || args[index].contains("suspend")
|| args[index].contains("halt"))) {
suspend = !args[index].toLowerCase().contains("nosuspend");
halt = !args[index].toLowerCase().contains("nohalt");
final Matcher matcher = Pattern.compile(".*port=([0-9]{1,5}).*").matcher(args[index]);
if (matcher.find()) {
debugPort = Integer.parseInt(matcher.group(1));
}
index++;
}
} else if (args[index].equals("-tool"))
{
index++;
TLCGlobals.tool = true;
} else if (args[index].equals("-generateSpecTE")) {
index++;
forceGenerateTESpec = true;
if ((index < args.length) && args[index].equals("nomonolith")) {
index++;
}
} else if (args[index].equals("-noGenerateSpecTE") || args[index].equalsIgnoreCase("-noTE"))
{
index++;
generateTESpec = false;
} else if (args[index].equals("-noGenerateSpecTEBin") || args[index].equalsIgnoreCase("-noTEBin"))
{
index++;
generateTESpecBinaryTrace = false;
} else if (args[index].equals("-teSpecOutDir"))
{
index++;
if (index < args.length) {
String path = args[index];
try {
teSpecOut = Paths.get(path);
} catch (InvalidPathException e) {
printErrorMsg("Error: invalid path for -teSpecOutDir option: " + path);
return false;
}
index++;
} else {
printErrorMsg("Error: expected a path for -teSpecOutDir option.");
return false;
}
} else if (args[index].equals("-help") || args[index].equals("-h"))
{
// See note referring to "-help" in MP#getMessage0 for EC.WRONG_COMMANDLINE_PARAMS_TLC.
printUsage();
return false;
} else if (args[index].equals("-lncheck"))
{
index++;
if (index < args.length)
{
TLCGlobals.lnCheck = args[index].toLowerCase();
index++;
} else
{
printErrorMsg("Error: expect a strategy such as final for -lncheck option.");
return false;
}
} else if (args[index].equals("-config"))
{
index++;
if (index < args.length)
{
configFile = args[index];
if (configFile.endsWith(TLAConstants.Files.CONFIG_EXTENSION)) {
configFile = configFile.substring(0,
(configFile.length() - TLAConstants.Files.CONFIG_EXTENSION.length()));
}
index++;
} else
{
printErrorMsg("Error: expect a file name for -config option.");
return false;
}
} else if (args[index].equals("-dump"))
{
index++; // consume "-dump".
if (args[index].startsWith("class,"))
{
// The provided class must extend the {@link tlc2.util.IStateWriter} interface
// and a 0-arity constructor. It will be searched on the classpath.
final String cls = args[index++].replace("class,", "");
try {
Class<? extends IStateWriter> clazz = Class.forName(cls).asSubclass(IStateWriter.class);
this.stateWriter = clazz.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
e.printStackTrace();
printErrorMsg(
String.format("Trying to instantiate a custom IStateWriter implementation %s.", cls));
return false;
}
}
else if (((index + 1) < args.length) && args[index].startsWith("dot"))
{
final String dotArgs = args[index].toLowerCase();
index++; // consume "dot...".
asDot = true;
colorize = dotArgs.contains("colorize");
actionLabels = dotArgs.contains("actionlabels");
snapshot = dotArgs.contains("snapshot");
constrained = dotArgs.contains("constrained");
stuttering = dotArgs.contains("stuttering");
strict = dotArgs.contains("strict");
dumpFile = getDumpFile(args[index++], ".dot");
}
else if (index < args.length)
{
dumpFile = getDumpFile(args[index++], ".dump");
} else
{
printErrorMsg("Error: A file name for dumping states required.");
return false;
}
} else if (args[index].equalsIgnoreCase("-dumpTrace"))
{
index++; // consume "-dumpTrace".
if ((index + 1) < args.length) {
final String fmt = args[index++];
if ("json".equalsIgnoreCase(fmt)) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params.computeIfAbsent(
ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
pcs.add(new PostCondition("_JsonTrace", "_JsonTrace", "_JsonTraceFile", args[index++]));
} else if ("tla".equalsIgnoreCase(fmt)) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params.computeIfAbsent(
ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
pcs.add(new PostCondition("_TLAPlusCounterExample", "_TLAPlusCounterExample",
"_TLAPlusCounterExampleFile", args[index++]));
} else if ("tlc".equalsIgnoreCase(fmt)) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params.computeIfAbsent(
ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
pcs.add(new PostCondition("_TLCTrace", "_TLCTrace", "_TLCTraceFile", args[index++]));
} else if ("tlcplain".equalsIgnoreCase(fmt)) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params.computeIfAbsent(
ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
pcs.add(new PostCondition("_TLCTracePlain", "_TLCTrace", "_TLCTraceFile", args[index++]));
} else if ("dot".equalsIgnoreCase(fmt)) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params.computeIfAbsent(
ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
pcs.add(new PostCondition("_DotTrace", "_DotTrace", "_DotTraceFile", args[index++]));
} else if ("Tomorrow's most favorite format".equalsIgnoreCase(fmt)) {
//Add your new dumpTrace formats here!
} else {
printErrorMsg("Error: Unknown format " + fmt + " given to -dumpTrace.");
return false;
}
} else {
printErrorMsg("Error: A format and a file name for dumping traces required.");
return false;
}
} else if (args[index].equalsIgnoreCase("-postCondition"))
{
index++; // consume "-postCondition".
if (index < args.length) {
@SuppressWarnings("unchecked")
final List<PostCondition> pcs = (List<PostCondition>) params
.computeIfAbsent(ParameterizedSpecObj.POST_CONDITIONS, k -> new ArrayList<PostCondition>());
// TODO: Add input validation!
pcs.add(new PostCondition(args[index++]));
} else {
printErrorMsg("Error: Module!Operator for postCondition required.");
return false;
}
} else if (args[index].equals("-coverage"))
{
index++;
if (index < args.length)
{
try
{
TLCGlobals.coverageInterval = Integer.parseInt(args[index]) * 60 * 1000;
if (TLCGlobals.coverageInterval < 0)
{
printErrorMsg("Error: expect a nonnegative integer for -coverage option.");
return false;
}
index++;
} catch (NumberFormatException e)
{
printErrorMsg("Error: An integer for coverage report interval required." + " But encountered "
+ args[index]);
return false;
}
} else
{
printErrorMsg("Error: coverage report interval required.");
return false;
}
} else if (args[index].equals("-checkpoint"))
{
index++;
if (index < args.length)
{
try
{
TLCGlobals.chkptDuration = Integer.parseInt(args[index]) * 1000 * 60;
if (TLCGlobals.chkptDuration < 0)
{
printErrorMsg("Error: expect a nonnegative integer for -checkpoint option.");
return false;
}
index++;
} catch (Exception e)
{
printErrorMsg("Error: An integer for checkpoint interval is required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: checkpoint interval required.");
return false;
}
} else if (args[index].equals("-depth"))
{
index++;
if (index < args.length)
{
try
{
traceDepth = Integer.parseInt(args[index]);
index++;
} catch (Exception e)
{
printErrorMsg("Error: An integer for trace length required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: trace length required.");
return false;
}
} else if (args[index].equals("-seed"))
{
index++;
if (index < args.length)
{
try
{
seed = Long.parseLong(args[index]);
index++;
noSeed = false;
} catch (Exception e)
{
printErrorMsg("Error: An integer for seed required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: seed required.");
return false;
}
} else if (args[index].equals("-aril"))
{
index++;
if (index < args.length)
{
try
{
aril = Long.parseLong(args[index]);
index++;
} catch (Exception e)
{
printErrorMsg("Error: An integer for aril required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: aril required.");
return false;
}
} else if (args[index].equals("-maxSetSize"))
{
index++;
if (index < args.length)
{
try
{
int bound = Integer.parseInt(args[index]);
// make sure it's in valid range
if (!TLCGlobals.isValidSetSize(bound)) {
int maxValue = Integer.MAX_VALUE;
printErrorMsg("Error: Value in interval [0, " + maxValue + "] for maxSetSize required. But encountered " + args[index]);
return false;
}
TLCGlobals.setBound = bound;
index++;
} catch (Exception e)
{
printErrorMsg("Error: An integer for maxSetSize required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: maxSetSize required.");
return false;
}
} else if (args[index].equals("-recover"))
{
index++;
if (index < args.length)
{
fromChkpt = args[index++] + FileUtil.separator;
} else
{
printErrorMsg("Error: need to specify the metadata directory for recovery.");
return false;
}
} else if (args[index].equals("-metadir"))
{
index++;
if (index < args.length)
{
TLCGlobals.metaDir = args[index++] + FileUtil.separator;
} else
{
printErrorMsg("Error: need to specify the metadata directory.");
return false;
}
} else if (args[index].equals("-userFile"))
{
index++;
if (index < args.length)
{
try {
// Most problems will only show when TLC eventually tries
// to write to the file.
tlc2.module.TLC.OUTPUT = new BufferedWriter(new FileWriter(new File(args[index++])));
} catch (IOException e) {
printErrorMsg("Error: Failed to create user output log file.");
return false;
}
} else
{
printErrorMsg("Error: need to specify the full qualified file.");
return false;
}
} else if (args[index].equals("-workers"))
{
index++;
if (index < args.length)
{
try
{
int num = args[index].trim().toLowerCase().equals("auto")
? Runtime.getRuntime().availableProcessors()
: Integer.parseInt(args[index]);
if (num < 1)
{
printErrorMsg("Error: at least one worker required.");
return false;
}
TLCGlobals.setNumWorkers(num);
index++;
} catch (Exception e)
{
printErrorMsg("Error: worker number or 'auto' required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: expect an integer or 'auto' for -workers option.");
return false;
}
} else if (args[index].equals("-dfid"))
{
index++;
if (index < args.length)
{
try
{
TLCGlobals.DFIDMax = Integer.parseInt(args[index]);
if (TLCGlobals.DFIDMax < 0)
{
printErrorMsg("Error: expect a nonnegative integer for -dfid option.");
return false;
}
index++;
} catch (Exception e)
{
printErrorMsg("Error: expect a nonnegative integer for -dfid option. " + "But encountered "
+ args[index]);
return false;
}
} else
{
printErrorMsg("Error: expect a nonnegative integer for -dfid option.");
return false;
}
} else if (args[index].equals("-fp"))
{
index++;
if (index < args.length)
{
try
{
fpIndex = Integer.parseInt(args[index]);
if (fpIndex < 0 || fpIndex >= FP64.Polys.length)
{
printErrorMsg("Error: The number for -fp must be between 0 and " + (FP64.Polys.length - 1)
+ " (inclusive).");
return false;
}
index++;
} catch (Exception e)
{
printErrorMsg("Error: A number for -fp is required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: expect an integer for -fp option.");
return false;
}
} else if (args[index].equals("-fpmem"))
{
index++;
if (index < args.length)
{
try
{
// -fpmem can be used in two ways:
// a) to set the relative memory to be used for fingerprints (being machine independent)
// b) to set the absolute memory to be used for fingerprints
//
// In order to set memory relatively, a value in the domain [0.0, 1.0] is interpreted as a fraction.
// A value in the [2, Double.MaxValue] domain allocates memory absolutely.
//
// Independently of relative or absolute mem allocation,
// a user cannot allocate more than JVM heap space
// available. Conversely there is the lower hard limit TLC#MinFpMemSize.
double fpMemSize = Double.parseDouble(args[index]);
if (fpMemSize < 0) {
printErrorMsg("Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered " + args[index]);
return false;
} else if (fpMemSize > 1) {
// For legacy reasons we allow users to set the
// absolute amount of memory. If this is the case,
// we know the user intends to allocate all 100% of
// the absolute memory to the fpset.
ToolIO.out
.println("Using -fpmem with an abolute memory value has been deprecated. " +
"Please allocate memory for the TLC process via the JVM mechanisms " +
"and use -fpmem to set the fraction to be used for fingerprint storage.");
fpSetConfiguration.setMemory((long) fpMemSize);
fpSetConfiguration.setRatio(1.0d);
} else {
fpSetConfiguration.setRatio(fpMemSize);
}
index++;
} catch (Exception e)
{
printErrorMsg("Error: An positive integer or a fraction for fpset memory size/percentage required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: fpset memory size required.");
return false;
}
} else if (args[index].equals("-fpbits"))
{
index++;
if (index < args.length)
{
try
{
int fpBits = Integer.parseInt(args[index]);
// make sure it's in valid range
if (!FPSet.isValid(fpBits)) {
printErrorMsg("Error: Value in interval [0, 30] for fpbits required. But encountered " + args[index]);
return false;
}
fpSetConfiguration.setFpBits(fpBits);
index++;
} catch (Exception e)
{
printErrorMsg("Error: An integer for fpbits required. But encountered " + args[index]);
return false;
}
} else
{
printErrorMsg("Error: fpbits required.");
return false;
}