forked from hklarner/NuSMV-a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcCmd.c
1270 lines (1079 loc) · 44.2 KB
/
mcCmd.c
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
/* ---------------------------------------------------------------------------
This file is part of the ``mc'' package of NuSMV version 2.
Copyright (C) 1998-2001 by CMU and FBK-irst.
NuSMV version 2 is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
NuSMV version 2 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
For more information on NuSMV see <http://nusmv.fbk.eu>
or email to <[email protected]>.
Please report bugs to <[email protected]>.
To contact the NuSMV development board, email to <[email protected]>.
-----------------------------------------------------------------------------*/
/*!
\author Marco Roveri
\brief Model checking commands.
This file contains all the shell command to deal with
model checking and for counterexample navigation.
*/
#if HAVE_CONFIG_H
# include "nusmv-config.h"
#endif
#include "nusmv/shell/cmd/cmd.h"
#include "nusmv/shell/bmc/bmcCmd.h"
#include "nusmv/shell/bmc/sbmc/sbmcCmd.h"
#include "nusmv/core/compile/compile.h"
#include "nusmv/core/mc/mc.h"
#include "nusmv/shell/mc/mcCmd.h"
#include "nusmv/core/bmc/bmcPkg.c"
#include "nusmv/core/utils/StreamMgr.h"
#include "nusmv/core/utils/ErrorMgr.h"
#include "nusmv/core/parser/symbols.h"
#include "nusmv/core/utils/error.h" /* for CATCH(errmgr) */
#include "nusmv/core/prop/Prop.h"
#include "nusmv/core/prop/PropDb.h"
#include "nusmv/core/prop/propPkg.h"
#include "nusmv/core/utils/utils_io.h"
#include "nusmv/core/trace/Trace.h"
#include "nusmv/core/trace/TraceMgr.h"
#include "nusmv/core/enc/enc.h"
#include "nusmv/core/utils/ucmd.h" /* for util_str2int */
#include "nusmv/core/bmc/bmcUtils.h" /* for Bmc_Utils_ConvertLoopFromString */
#include "nusmv/core/bmc/bmcBmc.h"
#include "nusmv/core/fsm/bdd/bdd.h" /* to check preconditions for EL_fwd */
int CommandCheckCtlSpec(NuSMVEnv_ptr env, int argc, char** argv);
int CommandCheckInvar(NuSMVEnv_ptr env, int argc, char** argv);
int CommandCheckCompute(NuSMVEnv_ptr env, int argc, char** argv);
int CommandCheckPslSpec(NuSMVEnv_ptr env, int argc, char** argv);
int CommandLanguageEmptiness(NuSMVEnv_ptr env, int argc, char** argv);
int CommandCompute(NuSMVEnv_ptr env, int argc, char** argv);
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static int UsageCheckCtlSpec(const NuSMVEnv_ptr env);
static int UsageCheckInvar(const NuSMVEnv_ptr env);
static int UsageCheckCompute(const NuSMVEnv_ptr env);
static int UsageCheckPslSpec(const NuSMVEnv_ptr env);
static int UsageLanguageEmptiness(const NuSMVEnv_ptr env);
static int UsageCompute(const NuSMVEnv_ptr env);
static int mc_cmd_check_compute(NuSMVEnv_ptr env, int argc, char **argv,
int (*usage_fun)(const NuSMVEnv_ptr));
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
void Mc_Init(NuSMVEnv_ptr env)
{
Cmd_CommandAdd(env, "check_ctlspec", CommandCheckCtlSpec, 0, true);
Cmd_CommandAdd(env, "check_invar", CommandCheckInvar, 0, true);
Cmd_CommandAdd(env, "check_compute", CommandCheckCompute, 0, true);
Cmd_CommandAdd(env, "check_pslspec", CommandCheckPslSpec, 0, true);
Cmd_CommandAdd(env, "_language_emptyness", CommandLanguageEmptiness, 0, true);
/* This one is deprecated */
Cmd_CommandAdd(env, "compute", CommandCompute, 0, true);
}
void Mc_End(NuSMVEnv_ptr env)
{
boolean status = true;
status = status && Cmd_CommandRemove(env, "check_ctlspec");
status = status && Cmd_CommandRemove(env, "check_invar");
status = status && Cmd_CommandRemove(env, "check_compute");
status = status && Cmd_CommandRemove(env, "check_pslspec");
status = status && Cmd_CommandRemove(env, "_language_emptyness");
/* This one is deprecated */
status = status && Cmd_CommandRemove(env, "compute");
if (!status) {
ErrorMgr_ptr err_mgr = NuSMVEnv_get_value(env, ENV_ERROR_MANAGER);
ErrorMgr_internal_error(err_mgr,
"Error while deinitializing commands in MC\n");
}
}
/*!
\command{check_ctlspec} Performs fair CTL model checking.
\command_args{[-h] [-a] [-m | -o output-file] [-n number | -p "ctl-expr [IN context]" | -P "name"]}
Performs fair CTL model checking.<p>
A <tt>ctl-expr</tt> to be checked can be specified at command line
using option <tt>-p</tt>. Alternatively, option <tt>-n</tt> or
<tt>-P</tt> can be used for checking a particular formula in the
property database. If neither <tt>-n</tt> nor <tt>-p</tt> are used,
all the SPEC formulas in the database are checked.<p>
Command options:<p>
<dl>
<dt> <tt>-a</tt>
<dd> Prints a factored form formula of the accepting states
to the file <tt>output-file</tt> specified with option -o or
to the command line, if option -m is selected.
<dt> <tt>-m</tt>
<dd> Pipes the output generated by the command in processing
<tt>SPEC</tt>s to the program specified by the
<tt>PAGER</tt> shell variable if defined, else
through the <tt>UNIX</tt> command "more".
<dt> <tt>-o output-file</tt>
<dd> Writes the output generated by the command in processing
<tt>SPEC</tt>s to the file <tt>output-file</tt>.
<dt> <tt>-p "ctl-expr [IN context]"</tt>
<dd> A CTL formula to be checked. <tt>context</tt> is the module
instance name which the variables in <tt>ctl-expr</tt> must
be evaluated in.
<dt> <tt>-n number</tt>
<dd> Checks the CTL property with index <tt>number</tt> in the property
database.
<dt> <tt>-P name</tt>
<dd> Checks the CTL property with name <tt>name</tt> in the property
database.
</dl><p>
If the <tt>ag_only_search</tt> environment variable has been set, and
the set of reachable states has already been computed, then a
specialized algorithm to check AG formulas is used instead of the
standard model checking algorithms.
*/
int CommandCheckCtlSpec(NuSMVEnv_ptr env, int argc, char** argv)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
FILE* errstream = StreamMgr_get_error_stream(streams);
FILE* outstream = StreamMgr_get_output_stream(streams);
FILE* old_outstream = outstream;
int c;
int prop_no = -1;
char* formula = NIL(char);
char* formula_name = NIL(char);
int status = 0;
int useMore = 0;
char* dbgFileName = NIL(char);
PropDb_ptr prop_db = PROP_DB(NuSMVEnv_get_value(env, ENV_PROP_DB));
OptsHandler_ptr opts = OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
util_getopt_reset();
reset_print_accepting(opts);
/* ADDED: option a */
while ((c = util_getopt(argc,argv,"hamo:n:p:P:")) != EOF) {
switch (c) {
case 'h': return UsageCheckCtlSpec(env);
/* ADDED: case for option 'a' */
case 'a':
{
set_print_accepting(opts, "print");
break;
}
case 'n':
{
if (formula != NIL(char)) return UsageCheckCtlSpec(env);
if (prop_no != -1) return UsageCheckCtlSpec(env);
if (formula_name != NIL(char)) return UsageCheckCtlSpec(env);
prop_no = PropDb_get_prop_index_from_string(prop_db,
util_optarg);
if (prop_no == -1) return 1;
break;
}
case 'P':
{
if (formula != NIL(char)) return UsageCheckCtlSpec(env);
if (prop_no != -1) return UsageCheckCtlSpec(env);
if (formula_name != NIL(char)) return UsageCheckCtlSpec(env);
formula_name = util_strsav(util_optarg);
prop_no = PropDb_prop_parse_name(prop_db,
formula_name);
if (prop_no == -1) {
StreamMgr_print_error(streams, "No property named \"%s\"\n", formula_name);
FREE(formula_name);
return 1;
}
FREE(formula_name);
break;
}
case 'p':
{
if (prop_no != -1) return UsageCheckCtlSpec(env);
if (formula != NIL(char)) return UsageCheckCtlSpec(env);
if (formula_name != NIL(char)) return UsageCheckCtlSpec(env);
formula = util_strsav(util_optarg);
break;
}
case 'o':
if (useMore == 1) return UsageCheckCtlSpec(env);
dbgFileName = util_strsav(util_optarg);
StreamMgr_print_output(streams, "Output to file: %s\n", dbgFileName);
break;
case 'm':
if (dbgFileName != NIL(char)) return UsageCheckCtlSpec(env);
useMore = 1;
break;
default: return UsageCheckCtlSpec(env);
}
}
if (argc != util_optind) return UsageCheckCtlSpec(env);
/* pre-conditions */
if (Compile_check_if_model_was_built(env, errstream, false)) return 1;
if (useMore || (char*)NULL != dbgFileName) {
if (OUTCOME_SUCCESS !=
Cmd_Misc_open_pipe_or_file(env, dbgFileName, &outstream)) {
status = 1; goto check_ctlspec_exit;
}
}
if (formula != NIL(char)) {
SymbTable_ptr st = SYMB_TABLE(NuSMVEnv_get_value(env, ENV_SYMB_TABLE));
prop_no = PropDb_prop_parse_and_add(prop_db, st,
formula, Prop_Ctl, Nil);
if (prop_no == -1) { status = 1; goto check_ctlspec_exit; }
CATCH(errmgr) {
PropDb_verify_prop_at_index(prop_db, prop_no);
}
FAIL(errmgr) {
status = 1;
}
}
else if (prop_no != -1) {
if (Prop_check_type(PropDb_get_prop_at_index(prop_db,
prop_no),
Prop_Ctl) != 0) {
status = 1;
}
else {
CATCH(errmgr) {
PropDb_verify_prop_at_index(prop_db, prop_no);
}
FAIL(errmgr) {
status = 1;
}
}
}
else {
CATCH(errmgr) {
if (opt_use_coi_size_sorting(opts)) {
FlatHierarchy_ptr hierarchy =
FLAT_HIERARCHY(NuSMVEnv_get_value(env, ENV_FLAT_HIERARCHY));
PropDb_ordered_verify_all_type(prop_db, hierarchy, Prop_Ctl);
}
else PropDb_verify_all_type(prop_db, Prop_Ctl);
}
FAIL(errmgr) {
status = 1;
}
}
check_ctlspec_exit:
if (useMore) {
FILE* reset_stream;
CmdClosePipe(outstream);
reset_stream = StreamMgr_reset_output_stream(streams);
StreamMgr_set_output_stream(streams, old_outstream);
nusmv_assert(reset_stream == outstream);
outstream = (FILE*)NULL;
}
if ((char*)NULL != dbgFileName) {
/* this closes the file stream as well */
StreamMgr_set_output_stream(streams, old_outstream);
outstream = (FILE*)NULL;
}
return status;
}
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
static int UsageCheckCtlSpec(const NuSMVEnv_ptr env)
{
StreamMgr_ptr streams = STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
/* ADDED: command line option a for printing initial states, accepting states, initial accepting states */
StreamMgr_print_error(streams, "usage: check_ctlspec [-h] [-a] [-m | -o file] [-n number | -p \"ctl-expr\" | -P \"name\"]\n");
StreamMgr_print_error(streams, " -h \t\t\tPrints the command usage.\n");
StreamMgr_print_error(streams, " -a \t\t\tPrints a factored form formula of the accepting\n");
StreamMgr_print_error(streams, " \t\t\tstates to the file output-file specified with option -o \n");
StreamMgr_print_error(streams, " \t\t\tor to the command line, if option -m is selected.\n");
StreamMgr_print_error(streams, " -m \t\t\tPipes output through the program specified\n");
StreamMgr_print_error(streams, " \t\t\tby the \"PAGER\" environment variable if defined,\n");
StreamMgr_print_error(streams, " \t\t\telse through the UNIX command \"more\".\n");
StreamMgr_print_error(streams, " -o file\t\tWrites the generated output to \"file\".\n");
StreamMgr_print_error(streams, " -n number\t\tChecks only the SPEC with the given index number.\n");
StreamMgr_print_error(streams, " -p \"ctl-expr\"\tChecks only the given CTL formula.\n");
StreamMgr_print_error(streams, " -P \"name\"\t\tChecks only the SPEC with the given name\n");
return 1;
}
/*!
\command{check_invar} Performs model checking of invariants
\command_args{[-h] [-m | -o output-file] [-s "strategy"]
[-e "heuristic"] [-t number] [-k number] [-j "heuristic"]
[-n number | -p "invar-expr [IN context]" | -P "name"]}
Performs invariant checking on the given
model. An invariant is a set of states. Checking the invariant is
the process of determining that all states reachable from the
initial states lie in the invariant.
Invariants to be verified can be provided as simple formulas
(without any temporal operators) in the input file via the
<tt>INVARSPEC</tt> keyword or directly at command line, using the option
<tt>-p</tt>.<p>
Option <tt>-n</tt> can be used for checking a particular invariant
of the model. If neither <tt>-n</tt> nor <tt>-p</tt> are
used, all the invariants are checked.<p>
During checking of invariant all the fairness conditions associated
with the model are ignored.<p>
If an invariant does not hold, a proof of failure is demonstrated.
This consists of a path starting from an initial state to a state
lying outside the invariant. This path has the property that it is the
shortest path leading to a state outside the invariant.<p>
Command options:<p>
<dl>
<dt> <tt>-m</tt>
<dd> Pipes the output generated by the program in processing
<tt>INVARSPEC</tt>s to the program specified by the
<tt>PAGER</tt> shell variable if defined, else
through the UNIX command "more".
<dt> <tt>-o output-file</tt>
<dd> Writes the output generated by the command in processing
<tt>INVARSPEC</tt>s to the file <tt>output-file</tt>.
<dt> <tt>-s <i>strategy</i></tt>
<dd> Force the analysis strategy.
<dt> <tt>-e <i>heuristic</i></tt>
<dd> Force the search heuristic for the forward-backward strategy.
<dt> <tt>-t <i>number</i></tt>
<dd> When using the mixed BDD and BMC approach specify the heuristic threshold.
<dt> <tt>-k <i>number</i></tt>
<dd> When using the mixed BDD and BMC approach specify the BMC max k.
<dt> <tt>-j <i>heuristic</i></tt>
<dd> Force the switch heuristic for the BDD-BMC strategy.
<dt> <tt>-p "invar-expr [IN context]"</tt>
<dd> The command line specified invariant formula to be verified.
<tt>context</tt> is the module instance name which the variables
in <tt>invar-expr</tt> must be evaluated in.
<dt> <tt>-P name</tt>
<dd> Checks the INVARSPEC with name <tt>name</tt> in the property
database.
</dl>
*/
int CommandCheckInvar(NuSMVEnv_ptr env, int argc, char** argv)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
const ErrorMgr_ptr errmgr =
ERROR_MGR(NuSMVEnv_get_value(env, ENV_ERROR_MANAGER));
FILE* errstream = StreamMgr_get_error_stream(streams);
FILE* outstream = StreamMgr_get_output_stream(streams);
FILE* old_outstream = outstream;
int c;
int prop_no = -1;
char* formula = NIL(char);
char* formula_name = NIL(char);
int status = 0;
int useMore = 0;
char* dbgFileName = NIL(char);
McCheckInvarOpts options;
boolean used_s, used_e, used_j, used_k, used_t;
PropDb_ptr prop_db = PROP_DB(NuSMVEnv_get_value(env, ENV_PROP_DB));
OptsHandler_ptr opts = OPTS_HANDLER(NuSMVEnv_get_value(env, ENV_OPTS_HANDLER));
Prop_ptr prop = NULL;
McCheckInvarOpts_init(&options, env);
/* 'Used' variables are initially false */
used_s = false;
used_e = false;
used_j = false;
used_k = false;
used_t = false;
util_getopt_reset();
while ((c = util_getopt(argc,argv,"hbt:k:j:e:s:mo:n:p:P:")) != EOF) {
switch (c) {
case 'h': return(UsageCheckInvar(env));
case 'n':
{
if (formula != NIL(char)) return(UsageCheckInvar(env));
if (prop_no != -1) return(UsageCheckInvar(env));
if (formula_name != NIL(char)) return UsageCheckInvar(env);
prop_no = PropDb_get_prop_index_from_string(prop_db,
util_optarg);
if (prop_no == -1) return 1;
break;
}
case 'P':
{
if (formula != NIL(char)) return UsageCheckInvar(env);
if (prop_no != -1) return UsageCheckInvar(env);
if (formula_name != NIL(char)) return UsageCheckInvar(env);
formula_name = util_strsav(util_optarg);
prop_no = PropDb_prop_parse_name(prop_db,
formula_name);
if (prop_no == -1) {
StreamMgr_print_error(streams, "No property named \"%s\"\n", formula_name);
FREE(formula_name);
return 1;
}
FREE(formula_name);
break;
}
case 'p':
{
if (prop_no != -1) return(UsageCheckInvar(env));
if (formula != NIL(char)) return(UsageCheckInvar(env));
if (formula_name != NIL(char)) return UsageCheckInvar(env);
formula = util_strsav(util_optarg);
break;
}
case 'o':
if (useMore == 1) return(UsageCheckInvar(env));
dbgFileName = util_strsav(util_optarg);
StreamMgr_print_output(streams, "Output to file: %s\n", dbgFileName);
break;
case 'm':
if (dbgFileName != NIL(char)) return(UsageCheckInvar(env));
useMore = 1;
break;
case 's':
if(used_s) {
StreamMgr_print_error(streams, "You cannot specify -s more than once!\n");
}
used_s = true;
if (0 == strcmp("forward", util_optarg)) {
options.strategy = FORWARD;
}
else if (0 == strcmp("backward", util_optarg)) {
options.strategy = BACKWARD;
}
else if (0 == strcmp("forward-backward", util_optarg)) {
options.strategy = FORWARD_BACKWARD;
}
#if NUSMV_HAVE_SAT_SOLVER
else if (0 == strcmp("bdd-bmc", util_optarg)) {
options.strategy = BDD_BMC;
}
else {
StreamMgr_print_error(streams, "Wrong strategy specified; you must choose between {'forward', 'backward', 'forward-backward', 'bdd-bmc'}.\n");
return 1;
}
#else
else {
StreamMgr_print_error(streams, "Wrong strategy specified; you must choose between {'forward', 'backward', 'forward-backward'}.\n");
return 1;
}
#endif
break;
case 'e':
if(used_e) {
StreamMgr_print_error(streams, "You cannot specify -e more than once!\n");
}
used_e = true;
if (0 == strcmp("zigzag", util_optarg)) {
options.fb_heuristic = ZIGZAG_HEURISTIC;
}
else if (0 == strcmp("smallest", util_optarg)) {
options.fb_heuristic = SMALLEST_BDD_HEURISTIC;
}
else {
StreamMgr_print_error(streams, "Wrong heuristic specified; you must choose between {'zigzag', 'smallest'}.\n");
return 1;
}
break;
case 'j':
if(used_j) {
StreamMgr_print_error(streams, "You cannot specify -j more than once!\n");
}
used_j = true;
if (0 == strcmp("steps", util_optarg)) {
options.bdd2bmc_heuristic = STEPS_HEURISTIC;
}
else if (0 == strcmp("size", util_optarg)) {
options.bdd2bmc_heuristic = SIZE_HEURISTIC;
}
else {
StreamMgr_print_error(streams, "Wrong heuristic specified; you must choose between {'steps', 'size'}.\n");
return 1;
}
break;
case 't':
{
int res;
if(used_t) {
StreamMgr_print_error(streams, "You cannot specify -t more than once!\n");
}
used_t = true;
res = sscanf(util_optarg, "%d", &(options.threshold));
if (res <= 0) {
StreamMgr_print_error(streams, "You must specify a valid number as threshold\n");
return 1;
}
break;
}
case 'k':
{
int res;
if(used_k) {
StreamMgr_print_error(streams, "You cannot specify -k more than once!\n");
}
used_k = true;
res = sscanf(util_optarg, "%d", &(options.bmc_length));
if (res <= 0) {
StreamMgr_print_error(streams, "You must specify a valid integer number as BMC k\n");
return 1;
}
break;
}
default: return(UsageCheckInvar(env));
}
}
if (argc != util_optind) return(UsageCheckInvar(env));
/* pre-conditions */
if (Compile_check_if_model_was_built(env, errstream, false)) return 1;
if ((BDD_BMC == options.strategy) && \
(Bmc_check_if_model_was_built(env, errstream, false))) return 1;
if (used_e) {
if ((FORWARD_BACKWARD != options.strategy) &&
(BDD_BMC != options.strategy)) {
StreamMgr_print_error(streams, "Unable to use an heuristic without forward-backward or bdd-bmc strategy.\n");
status = 1;
goto check_invar_exit;
}
}
if (used_j) {
if (used_s && BDD_BMC != options.strategy) {
StreamMgr_print_error(streams, "Unable to use an heuristic for bdd-bmc while not in bdd-bmc strategy!\n");
status = 1;
goto check_invar_exit;
}
}
if (used_t) {
if (used_s && BDD_BMC != options.strategy) {
StreamMgr_print_error(streams, "Unable to use an heuristic threshold for bdd-bmc while not in bdd-bmc strategy!\n");
status = 1;
goto check_invar_exit;
}
}
if (used_k) {
if (used_s && BDD_BMC != options.strategy) {
StreamMgr_print_error(streams, "Unable to set BMC k while not in bdd-bmc strategy!\n");
status = 1;
goto check_invar_exit;
}
}
if (useMore || (char*)NULL != dbgFileName) {
if (OUTCOME_SUCCESS !=
Cmd_Misc_open_pipe_or_file(env, dbgFileName, &outstream)) {
status = 1; goto check_invar_exit;
}
}
if (formula != NIL(char)) {
SymbTable_ptr st = SYMB_TABLE(NuSMVEnv_get_value(env, ENV_SYMB_TABLE));
prop_no = PropDb_prop_parse_and_add(prop_db, st,
formula, Prop_Invar, Nil);
if (prop_no == -1) { status = 1; goto check_invar_exit; }
prop = PropDb_get_prop_at_index(prop_db, prop_no);
}
else if (prop_no != -1) {
prop = PropDb_get_prop_at_index(prop_db, prop_no);
if (Prop_check_type(prop, Prop_Invar) != 0) {
status = 1;
}
}
else { /* nothing to do */ }
status = Mc_check_invar(env, prop, &options);
check_invar_exit: /* clean exit */
if (useMore) {
FILE* reset_stream;
CmdClosePipe(outstream);
reset_stream = StreamMgr_reset_output_stream(streams);
StreamMgr_set_output_stream(streams, old_outstream);
nusmv_assert(reset_stream == outstream);
outstream = (FILE*)NULL;
}
if ((char*)NULL != dbgFileName) {
/* this closes the file stream as well */
StreamMgr_set_output_stream(streams, old_outstream);
outstream = (FILE*)NULL;
}
return status;
}
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
static int UsageCheckInvar(const NuSMVEnv_ptr env)
{
StreamMgr_ptr streams = STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
#if NUSMV_HAVE_SAT_SOLVER
StreamMgr_print_error(streams, "usage: check_invar [-h] [-m| -o file] [-s strategy] [-e heuristic] [-t number] [-k number] [-j heuristic] [-n number | -p \"invar-expr\" | -P \"name\"]\n");
#else
StreamMgr_print_error(streams, "usage: check_invar [-h] [-m| -o file] [-s strategy] [-e heuristic] [-n number | -p \"invar-expr\" | -P \"name\"]\n");
#endif
StreamMgr_print_error(streams, " -h \t\t\tPrints the command usage.\n");
#if NUSMV_HAVE_SAT_SOLVER
StreamMgr_print_error(streams, " -s \t\t\tForce the analysis strategy (Overrides options). Possible values are {'forward', 'backward', 'forward-backward', 'bdd-bmc'}\n");
#else
StreamMgr_print_error(streams, " -s \t\t\tForce the analysis strategy (Overrides options). Possible values are {'forward', 'backward', 'forward-backward'}\n");
#endif
StreamMgr_print_error(streams, " -e \t\t\tForce the heuristic in case of forward-backward strategy (Overrides options). Possible values are {'zigzag', 'smallest'}\n");
#if NUSMV_HAVE_SAT_SOLVER
StreamMgr_print_error(streams, " -t \t\t\tWhen using the mixed BDD and BMC approach specify the heuristic threshold\n");
StreamMgr_print_error(streams, " -k \t\t\tWhen using the mixed BDD and BMC approach specify the BMC max k\n");
StreamMgr_print_error(streams, " -j \t\t\tSpecify the heuristic used to switch from BDD to BMC. Possible values are {'steps', 'size'}\n");
#endif
StreamMgr_print_error(streams, " -m \t\t\tPipes output through the program specified by\n");
StreamMgr_print_error(streams, " \t\t\tthe \"PAGER\" shell variable if defined,\n");
StreamMgr_print_error(streams, " \t\t\telse through the UNIX command \"more\".\n");
StreamMgr_print_error(streams, " -o file\t\tWrites the generated output to \"file\".\n");
StreamMgr_print_error(streams, " -n number\t\tchecks only the INVARSPEC with the given index number.\n");
StreamMgr_print_error(streams, " -p \"invar-expr\"\tchecks only the given invariant formula.\n");
StreamMgr_print_error(streams, " -P \"name\"\t\tchecks only the INVARSPEC with the given name.\n");
return 1;
}
/*!
\command{check_compute} Performs computation of quantitative characteristics
\command_args{[-h] [-m | -o output-file] [-n number |
-p "compute-expr [IN context]" | -P "name"]}
This command deals with the computation of
quantitative characteristics of real time systems. It is able to
compute the length of the shortest (longest) path from two given set
of states.<p>
<center><code>MAX [ alpha , beta ]</code></center><br>
<center><code>MIN [ alpha , beta ]</code></center><p>
Properties of the above form can be specified in the input file via
the keyword <code>COMPUTE</code> or directly at command line,
using option <tt>-p</tt>.<p>
Option <tt>-n</tt> can be used for computing a particular expression
in the model. If neither <tt>-n</tt> nor <tt>-p</tt> nor <tt>-P</tt>
are used, all the COMPUTE specifications are computed.<p>
Command options:<p>
<dl>
<dt> <tt>-m</tt>
<dd> Pipes the output generated by the command in processing
<tt>COMPUTE</tt>s to the program specified by the
<tt>PAGER</tt> shell variable if defined, else
through the UNIX command "more".
<dt> <tt>-o output-file</tt>
<dd> Writes the output generated by the command in processing
<tt>COMPUTE</tt>s to the file <tt>output-file</tt>.
<dt> <tt>-p "compute-expr [IN context]"</tt>
<dd> A COMPUTE formula to be checked. <tt>context</tt> is the module
instance name which the variables in <tt>compute-expr</tt> must
be evaluated in.
<dt> <tt>-n number</tt>
<dd> Computes only the property with index <tt>number</tt>
<dt> <tt>-P name</tt>
<dd> Computes only the property named <tt>name</tt>
</dl>
*/
int CommandCheckCompute(NuSMVEnv_ptr env, int argc, char** argv)
{
return mc_cmd_check_compute(env, argc, argv, UsageCheckCompute);
}
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
static int UsageCheckCompute(const NuSMVEnv_ptr env)
{
StreamMgr_ptr streams = STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
StreamMgr_print_error(streams, "usage: check_compute [-h] [-m | -o file] [-n number | -p \"compute-expr\" | -P \"name\"]\n");
StreamMgr_print_error(streams, " -h \t\t\tPrints the command usage.\n");
StreamMgr_print_error(streams, " -m \t\t\tPipes output through the program specified by\n");
StreamMgr_print_error(streams, " \t\t\tthe \"PAGER\" shell variable if defined,\n");
StreamMgr_print_error(streams, " \t\t\telse through the UNIX command \"more\".\n");
StreamMgr_print_error(streams, " -o file\t\tWrites the generated output to \"file\".\n");
StreamMgr_print_error(streams, " -n number\t\tConsiders only the compute expression with the given index number.\n");
StreamMgr_print_error(streams, " -p \"compute-expr\"\tComputes the given expression.\n");
StreamMgr_print_error(streams, " -P name\t\tConsiders only the compute expression with the given name.\n");
return 1;
}
/*!
\command{compute} Performs computation of quantitative characteristics
\command_args{}
This command is deprecated. It has been substituted by the command check_compute.
\sa check_compute
*/
int CommandCompute(NuSMVEnv_ptr env, int argc, char** argv)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
int res = mc_cmd_check_compute(env, argc, argv, UsageCompute);
StreamMgr_print_error(streams,
"\nWarning: command 'compute' is deprecated, use " \
"'check_compute' instead.\n");
return res;
}
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
static int UsageCompute(const NuSMVEnv_ptr env)
{
StreamMgr_ptr streams = STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
StreamMgr_print_error(streams, "usage: compute [-h] [-m | -o file] [-n number | -p \"compute-expr\" | -P \"name\"]\n");
StreamMgr_print_error(streams, " -h \t\t\tPrints the command usage.\n");
StreamMgr_print_error(streams, " -m \t\t\tPipes output through the program specified by\n");
StreamMgr_print_error(streams, " \t\t\tthe \"PAGER\" shell variable if defined,\n");
StreamMgr_print_error(streams, " \t\t\telse through the UNIX command \"more\".\n");
StreamMgr_print_error(streams, " -o file\t\tWrites the generated output to \"file\".\n");
StreamMgr_print_error(streams, " -n number\t\tConsiders only the compute expression with the given index number.\n");
StreamMgr_print_error(streams, " -p \"compute-expr\"\tComputes the given expression.\n");
StreamMgr_print_error(streams, " -P name\t\tConsiders only the compute expression with the given name.\n");
return 1;
}
/*!
\command{check_pslspec} Performs fair PSL model checking.
\command_args{[-h] [-m | -o output-file] [-n number | -p "psl-expr [IN context]" | -P "name"]}
Performs fair PSL model checking.<p>
A <tt>psl-expr</tt> to be checked can be specified at command line
using option <tt>-p</tt>. Alternatively, option <tt>-n</tt> can be used
for checking a particular formula in the property database. If
neither <tt>-n</tt> nor <tt>-p</tt> are used, all the PSLSPEC formulas in
the database are checked.<p>
Command options:<p>
<dl>
<dt> <tt>-m</tt>
<dd> Pipes the output generated by the command in processing
<tt>SPEC</tt>s to the program specified by the
<tt>PAGER</tt> shell variable if defined, else
through the <tt>UNIX</tt> command "more".
<dt> <tt>-o output-file</tt>
<dd> Writes the output generated by the command in processing
<tt>PSLSPEC</tt>s to the file <tt>output-file</tt>.
<dt> <tt>-p "psl-expr [IN context]"</tt>
<dd> A PSL formula to be checked. <tt>context</tt> is the module
instance name which the variables in <tt>ctl-expr</tt> must
be evaluated in.
<dt> <tt>-n number</tt>
<dd> Checks the PSL property with index <tt>number</tt> in the property
database.
<dt> <tt>-P name</tt>
<dd> Checks the PSL property named <tt>name</tt> in the property
database.
</dl><p>
*/
int CommandCheckPslSpec(NuSMVEnv_ptr env, int argc, char** argv)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
PropDb_ptr const prop_db = PROP_DB(NuSMVEnv_get_value(env, ENV_PROP_DB));
FILE* errstream = StreamMgr_get_error_stream(streams);
FILE* outstream = StreamMgr_get_output_stream(streams);
int c;
int prop_no = -1;
char* formula = NIL(char);
char* formula_name = NIL(char);
int status = 0;
int useMore = 0;
char* dbgFileName = NIL(char);
FILE* old_outstream = NIL(FILE);
util_getopt_reset();
while ((c = util_getopt(argc, argv, "hmo:n:p:P:")) != EOF) {
switch (c) {
case 'h': return UsageCheckPslSpec(env);
case 'n':
{
if (formula != NIL(char)) return UsageCheckPslSpec(env);
if (prop_no != -1) return UsageCheckPslSpec(env);
if (formula_name != NIL(char)) return UsageCheckPslSpec(env);
prop_no = PropDb_get_prop_index_from_string(prop_db,
util_optarg);
if (prop_no == -1) return 1;
break;
}
case 'P':
{
if (formula != NIL(char)) return UsageCheckPslSpec(env);
if (prop_no != -1) return UsageCheckPslSpec(env);
if (formula_name != NIL(char)) return UsageCheckPslSpec(env);
formula_name = util_strsav(util_optarg);
prop_no = PropDb_prop_parse_name(prop_db,
formula_name);
if (prop_no == -1) {
StreamMgr_print_error(streams, "No property named \"%s\"\n", formula_name);
FREE(formula_name);
return 1;
}
FREE(formula_name);
break;
}
case 'p':
{
if (prop_no != -1) return UsageCheckPslSpec(env);
if (formula != NIL(char)) return UsageCheckPslSpec(env);
if (formula_name != NIL(char)) return UsageCheckPslSpec(env);
formula = util_strsav(util_optarg);
break;
}
case 'o':
if (useMore == 1) return UsageCheckPslSpec(env);
dbgFileName = util_strsav(util_optarg);
StreamMgr_print_output(streams, "Output to file: %s\n", dbgFileName);
break;
case 'm':
if (dbgFileName != NIL(char)) return UsageCheckPslSpec(env);
useMore = 1;
break;
default: return UsageCheckPslSpec(env);
}
}
if (argc != util_optind) return UsageCheckPslSpec(env);
/* ---------------------------------------------------------------------- */
/* Checking compilation status */
if (Compile_check_if_encoding_was_built(env, errstream)) return 1;
/* Model construction is delayed until property is being checked,
according to the specific technique that is being used. */
if (useMore) {
old_outstream = outstream;
outstream = CmdOpenPipe(env, useMore);
if (outstream==(FILE*) NULL) {outstream=old_outstream; return 1;}
/* StreamMgr_set_output_stream(streams, outstream); */
}
if (dbgFileName != NIL(char)) {
old_outstream = outstream;
outstream = CmdOpenFile(env, dbgFileName);
if (outstream==(FILE*) NULL) {outstream = old_outstream; return 1;}
/* StreamMgr_set_output_stream(streams, outstream); */
}
if (formula != NIL(char)) {
SymbTable_ptr st = SYMB_TABLE(NuSMVEnv_get_value(env, ENV_SYMB_TABLE));
prop_no = PropDb_prop_parse_and_add(prop_db, st,
formula, Prop_Psl, Nil);
if (prop_no == -1) { status = 1; goto check_psl_exit; }
}
status = Mc_check_psl_spec(env, prop_no);
check_psl_exit:
if (useMore) {
CmdClosePipe(outstream);
/* StreamMgr_set_output_stream(streams, old_outstream); */
outstream = old_outstream;
}
if (dbgFileName != NIL(char)) {
CmdCloseFile(outstream);
/* StreamMgr_set_output_stream(streams, old_outstream); */
outstream = old_outstream;
}
return status;
}