-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathezproofc
More file actions
executable file
·492 lines (407 loc) · 13.8 KB
/
ezproofc
File metadata and controls
executable file
·492 lines (407 loc) · 13.8 KB
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
#!/bin/bash
#
#---------------------------------------------------------------------
# EZPROOFC tool
#---------------------------------------------------------------------
# Goal: This tool aims to automate the method proposed aims to automate
# the collection and manipulation of counterexamples in order
# to instantiate a C program for proving the root cause of the
# identified error. Such method may be seen as a complementary
# technique for the verification performed by Bounded Model
# Checkers
#
# Author: Herbert O. Rocha - E-mail: herberthb12@gmail.com
# Version: 4 - Year: 2012
# License: GPL
#---------------------------------------------------------------------
ABS_PATH_EZPROOFC="[<??>]"
flag_ABS=`echo $ABS_PATH_EZPROOFC | grep -c "\[<??>\]"`
if [ $flag_ABS -eq 1 ];
then
echo "Sorry, you need to run the config.sh script first. See REAME file."
exit 1;
fi
#--------------------------------------------------------------------
#settings preprocessor and arch flag
get_arch=`arch`
set_arch=0
if [ $get_arch == "x86_64" ];
then
set_arch="--64"
DIR_PROC_PRIMARY=$ABS_PATH_EZPROOFC"/modules/preprocessor/primary_preprocessing/arch_64/uncrustify"
else
set_arch="--32"
DIR_PROC_PRIMARY=$ABS_PATH_EZPROOFC"/modules/preprocessor/primary_preprocessing/arch_32/uncrustify"
fi
CONFIG_CFG=$ABS_PATH_EZPROOFC"/modules/preprocessor/primary_preprocessing/ben.cfg"
DIR_PROC_AUX=$ABS_PATH_EZPROOFC"/modules/preprocessor/aux_preprocessing/aux_formatting.pl"
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#Settings for Abstraction and Isnstanciation
DIR_ABS_AND_INST=$ABS_PATH_EZPROOFC"/modules/instanciation/"
DIR_RESULT_NEW_CODE=$ABS_PATH_EZPROOFC"/result_instrument.out"
#
DIR_RESULT_ABS=$DIR_ABS_AND_INST"result_abstration.dir"
PATH_ABS_P_DIR=$DIR_ABS_AND_INST"result_abs_property.p"
PROG_ABSTRATION=$DIR_ABS_AND_INST"abs_CE_v10_IN.pl"
PROG_INSTRUMENT=$DIR_ABS_AND_INST"go_instrument_v2_IN.pl"
PROG_ABSTRATION_ASSUME=$DIR_ABS_AND_INST"abs_CE_to_assume.pl"
PROG_SIMPLE_WRT=$DIR_ABS_AND_INST"go_instrument_simple_wrt.pl"
PROG_INSERT_PROPERTY=$DIR_ABS_AND_INST"go_insert_property.pl"
# For Verification
DIR_VERIFICATION=$ABS_PATH_EZPROOFC"/modules/verification/"
NAME_PROG_VERIFICATION=$DIR_VERIFICATION"checkAllClaims.sh"
#--------------------------------------------------------------------
#====================================================================
#------------------------------ functions ---------------------------
#Run verification for all claims in the code and then it applies the
#EZProofC Method
run_ezproofc_check_ALL()
{
#Verifying the C program
if [ -e "$1" ];
then
if [ $# -gt 1 ];
then
echo "Not implemented yet, sorry :( - Try ezproofc -h"
else
#preprocessing the C program that will be analysed
exec_processadorc $1
#remove old results
if [ -d "$DIR_RESULT_NEW_CODE" ]; then
rm -r $DIR_RESULT_NEW_CODE
fi
if [ -d "$DIR_RESULT_ABS" ]; then
rm -r $DIR_RESULT_ABS
fi
if [ -d "$PATH_ABS_P_DIR" ]; then
rm -r $PATH_ABS_P_DIR
fi
CHECK_out_verification=$(ls $DIR_VERIFICATION | wc -l)
if [ $CHECK_out_verification -gt 1 ]; then
rm -r $DIR_VERIFICATION*.dir
fi
#Start verification
inic_checkClaims_All
fi
else
echo "No <file.c> found - Please try again, or try ezproofc -h"
fi
}
#======================================================================
# option -e <file.c> <counterexample.tmp> || --addassert
#STATUS: OKAY
run_ezproofc_with_CE(){
#check if there are valid pathes for files
if [ -e "$1" ] && [ -e "$2" ];
then
if [ $# -gt 2 ];
then
# Check $3 option
chk_op3=`echo $3 | grep -c "addassert"`
chk_op_assume=`echo $3 | grep -c "nassume"`
if [ $chk_op3 -eq 1 ];
then
# Using option --addassert
$PROG_ABSTRATION $1 $2 $3
$PROG_INSTRUMENT $1 $DIR_RESULT_ABS
$PROG_INSERT_PROPERTY
#get name for new code
CE_name=`echo $2 | grep -o "[^\/]*$" | grep -o "^[^.]*"`
new_name_file=`ls $DIR_RESULT_NEW_CODE"/"$CE_name"/"*.c`
#last pre-process
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $new_name_file
#remove temporary files
if [ -d "$DIR_RESULT_NEW_CODE" ]; then
rm -r $DIR_RESULT_NEW_CODE
fi
if [ -d "$DIR_RESULT_ABS" ]; then
rm -r $DIR_RESULT_ABS
fi
if [ -d "$PATH_ABS_P_DIR" ]; then
rm -r $PATH_ABS_P_DIR
fi
elif [ $chk_op_assume -eq 1 ]
then
# Using option --nassume [OKAY]
$PROG_ABSTRATION_ASSUME $1 $2
$PROG_SIMPLE_WRT $1 $DIR_RESULT_ABS
#get name for new code
CE_name=`echo $2 | grep -o "[^\/]*$" | grep -o "^[^.]*"`
#echo $CE_name
new_name_file=`ls $DIR_RESULT_NEW_CODE"/"$CE_name"/"*.c`
#last pre-process
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $new_name_file
#remove temporary files
if [ -d "$DIR_RESULT_NEW_CODE" ]; then
rm -r $DIR_RESULT_NEW_CODE
fi
if [ -d "$DIR_RESULT_ABS" ]; then
rm -r $DIR_RESULT_ABS
fi
if [ -d "$PATH_ABS_P_DIR" ]; then
rm -r $PATH_ABS_P_DIR
fi
else
echo "Sorry, no <$3> option found, check out ezproofc -h"
fi
else
$PROG_ABSTRATION $1 $2
$PROG_INSTRUMENT $1 $DIR_RESULT_ABS
#get name for new code
CE_name=`echo $2 | grep -o "[^\/]*$" | grep -o "^[^.]*"`
new_name_file=`ls $DIR_RESULT_NEW_CODE"/"$CE_name"/"*.c`
#last pre-process
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $new_name_file
#remove temporary files
if [ -d "$DIR_RESULT_NEW_CODE" ]; then
rm -r $DIR_RESULT_NEW_CODE
fi
if [ -d "$DIR_RESULT_ABS" ]; then
rm -r $DIR_RESULT_ABS
fi
fi
else
echo "No <$1> or <$2> found - Please try again"
fi
}
#====================================================================
#--------------------------auxiliary functions ------------------------
#./uncrustify -q -l C -c ben.cfg -f ../ccode_here/testCode.c
exec_processadorc()
{
file_tmp="file_tmp.tmp"
file2_tmp="2file_tmp.tmp"
#verifying if there is a directory in the path' code
name_program=$(echo $1 | grep -o "[^/]*$")
rec_file="pre_$name_program"
rec_path=$(echo $1 | sed "s/$name_program/$rec_file/g")
#global var
FILE_PREPROCESSOR=$rec_path
#Apply preprocessor
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $1 > $file_tmp
#Apply aux preprocessor
$DIR_PROC_AUX $file_tmp > $file2_tmp
#Re-apply preprocessor
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $file2_tmp > $rec_path
rm $file_tmp
rm $file2_tmp
}
#-----------------------------
#Verify all claims in the C program
inic_checkClaims_All()
{
file=$FILE_PREPROCESSOR
echo "-> Start Verification with ESBMC"
$NAME_PROG_VERIFICATION $file
echo "-> Selecting files with counterexample to the next step"
#seleção dos files.tmp que contem contra-exemplo e instrumentacao
name_file=`echo $FILE_PREPROCESSOR | grep -o "[^/]*$" | grep -o "^[^.]*"`
DIR_CE=$(ls -1 $DIR_VERIFICATION*.dir | sort )
for file_in_dir in $DIR_CE
do
result_tmp=`cat $DIR_VERIFICATION$name_file"_result.dir"/$file_in_dir | grep "VERIFICATION FAILED"`
if [ -n "$result_tmp" ];
then
#checking if the CE has some properties with UPPER and LOWER bound
know_CE_UL=`cat $DIR_VERIFICATION$name_file"_result.dir"/$file_in_dir | grep -c "upper bound"`
#We got a upper bound
if [ $know_CE_UL -eq 1 ];
then
#incializa o processo de abstração dos dados do contra-exemplo
#add --addassert
inc_abs_instrument $DIR_VERIFICATION$name_file"_result.dir"/$file_in_dir 1
#inicializa o processo de instrumentação e criação dos novos códigos
inc_now_instrument 1
else
#incializa o processo de abstração dos dados do contra-exemplo
inc_abs_instrument $DIR_VERIFICATION$name_file"_result.dir"/$file_in_dir
#inicializa o processo de instrumentação e criação dos novos códigos
inc_now_instrument
fi
fi
done
echo "________________________________________________________"
echo "=> The results are in: "
echo $DIR_RESULT_NEW_CODE
}
inc_abs_instrument()
{
echo "-> Starting the abstration of data from counterexamples"
#---------------
# FROM: check_ALL
# $1 -> counterexample.tmp
# $2 -> 1 == --addassert
# check how many args for input modules
# ./$PROG_ABSTRATION <code.c> <counterexample.tmp> [1 == --addassert]
if [ $# -gt 1 ];
then
$PROG_ABSTRATION $FILE_PREPROCESSOR $1 --addassert
else
$PROG_ABSTRATION $FILE_PREPROCESSOR $1
fi
}
inc_now_instrument()
{
echo "-> Starting the instantiation of new C source code"
#---------------
# FROM: check_ALL
# $1 -> counterexample.tmp
# $2 -> 1 to insert an assertion
if [ $# -ge 1 ] ;
then
$PROG_INSTRUMENT $FILE_PREPROCESSOR $DIR_RESULT_ABS
$PROG_INSERT_PROPERTY
else
$PROG_INSTRUMENT $FILE_PREPROCESSOR $DIR_RESULT_ABS
fi
}
run_uncrustify_pre(){
tmp_file="file_tmp.tmp"
tmp_file2="2file_tmp.tmp"
#Apply preprocessor
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $1 > $tmp_file
#Apply aux preprocessor
$DIR_PROC_AUX $tmp_file > $tmp_file2
#Re-apply preprocessor
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $tmp_file2
rm $tmp_file
rm $tmp_file2
}
clean_old(){
#remove old results
if [ -d "$DIR_RESULT_NEW_CODE" ]; then
rm -r $DIR_RESULT_NEW_CODE
fi
if [ -d "$DIR_RESULT_ABS" ]; then
rm -r $DIR_RESULT_ABS
fi
if [ -d "$PATH_ABS_P_DIR" ]; then
rm -r $PATH_ABS_P_DIR
fi
CHECK_out_verification=$(ls $DIR_VERIFICATION | wc -l)
if [ $CHECK_out_verification -gt 1 ]; then
rm -r $DIR_VERIFICATION*.dir
fi
}
#------------------------------ end functions -------------------------
#====================================================================
#====================================================================
#------------------------------- main --------------------------------
#Checking the options
if [ $# -ge 1 ];
then
while getopts "he:::p:c" flag
do
case "${flag}" in
h)
received_h=1
;;
e)
received_e=1
#path C Program
arg_1="${2}"
#path Counterexample
arg_2="${3}"
#option for abstraction
arg_3="${4}"
;;
p)
received_p=1
#path C Program
arg_1="${2}"
;;
c)
received_c=1
;;
*)
echo "Sorry, wrong usage try again or ezproofc -h!"
exit 1;
;;
esac
done
else
echo "Please provide a C program to verify - ezproofc <file.c> or usage ezproofc -h"
fi
#===========================================================
#==> Apply options
if [ ${received_h} ]
then
clear
echo ""
echo "----------------------------- EZPROOFC v3 ---------------------------"
echo "======================================================================"
echo " .-."
echo " /v\\"
echo " // \\\\ > L I N U X - GPL<"
echo " /( )\\"
echo " ^^-^^"
echo "======================================================================"
echo "----------------------------------------------------------------------"
echo "Usage: Purpose:"
echo ""
echo "ezproofc [-h] Show help"
echo "______________________________________________________________________"
echo "ezproofc file.c Source file - Default: Apply verification"
echo " for all claims, adopting the following ESBMC"
echo " options:"
echo " $ esbmc --arch --no-library --claim <n> --unwind <bound> <\$file.c>"
echo " Warning: Bounds for verification Timeout = 3600s and UpperBound = 100"
echo "______________________________________________________________________"
echo "Additonal options:"
echo ""
echo "ezproofc [-e] <file.c> <counterexample_file.tmp> "
echo " -> Apply EZProofC in the counterexample based on the code"
echo " WARNING: Program C should be already preprocessed!!"
echo ""
echo "ezproofc [-e] <file.c> <counterexample_file.tmp> --addassert"
echo " -> Apply EZProofC in the counterexample based on the code"
echo " -> And to apply an assertion using the violated property"
echo " WARNING: Program C should be already preprocessed!!"
echo ""
echo ">>> NEW"
echo "ezproofc [-e] <file.c> <counterexample_file.tmp> --nassume"
echo " -> Apply EZProofC in the counterexample based on the code"
echo " -> and then it inserts an ESBMC assume that has been gathered"
echo " WARNING: Program C should be already preprocessed!!"
echo ""
echo "ezproofc [-p] <file.c>"
echo " -> Apply preprocessing code"
echo ""
echo "ezproofc [-c]"
echo " -> Clean old results"
echo "----------------------------------------------------------------------"
echo "======================================================================"
exit 1;
elif [ ${received_e} ]
then
run_ezproofc_with_CE $arg_1 $arg_2 $arg_3
exit 1; #finsh here
elif [ ${received_p} ]
then
run_uncrustify_pre $arg_1
exit 1; #finsh here
elif [ ${received_c} ]
then
echo "Do you want to clean all folders (old results)? Type y (yes) or n (No), followed by [ENTER]:"
read choose
if [ $choose = "y" ];
then
echo "> Cleaning all old results folders..."
clean_old
echo "> Status: OKAY"
fi
exit 1; #finsh here
else
clear
#check if the option was correct
if [ $# -gt 1 ];
then
echo "Sorry, wrong usage try again or ezproofc -h!"
exit 1
fi
run_ezproofc_check_ALL $1
exit 1; #finsh here
fi
#-----------------------------end main ------------------------------
#====================================================================