-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfortes
More file actions
executable file
·254 lines (222 loc) · 7.57 KB
/
fortes
File metadata and controls
executable file
·254 lines (222 loc) · 7.57 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
#!/bin/bash
#---------------------------------------------------------------------
# FORTES tool - FORTES - FORmal unit TESt generation
#---------------------------------------------------------------------
# Goal: This tool aims to create Test Cases based on claims from ESBMC
# model checker
# Author: Herbert O. Rocha E-mail: herberthb12@gmail.com
# Version: 2.1 - Year: 2012
# License: GPL V3
#---------------------------------------------------------------------
ABS_PATH_FORTES="[<??>]"
flag_ABS=`echo $ABS_PATH_FORTES | 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_FORTES"/modules/preprocessor/primary_preprocessing/arch_64/uncrustify"
else
set_arch="--32"
DIR_PROC_PRIMARY=$ABS_PATH_FORTES"/modules/preprocessor/primary_preprocessing/arch_32/uncrustify"
fi
CONFIG_CFG=$ABS_PATH_FORTES"/modules/preprocessor/primary_preprocessing/ben.cfg"
DIR_PROC_AUX=$ABS_PATH_FORTES"/modules/preprocessor/aux_preprocessing/aux_formatting.pl"
#--------------------------------------------------------------------
#--------------------------------------------------------------------
#settings for get and set claims
DIR_RESULT_CLAIMS=$ABS_PATH_FORTES"/result_claims"
DIR_ABS_CLAIMS=$ABS_PATH_FORTES"/modules/get_and_set_claims/abs_claims.pl"
DIR_ABS_CLAIMS_FUNC=$ABS_PATH_FORTES"/modules/get_and_set_claims/abs_claims_func.pl"
DIR_GET_AND_SET_CLAIMS=$ABS_PATH_FORTES"/modules/get_and_set_claims/get_and_set_claims.pl"
#--------------------------------------------------------------------
DIR_RESULT_END_CODE=$ABS_PATH_FORTES"/new_code"
#------------------------------ functions ---------------------------
#get file that will be analised
start_program()
{
#Verifying the C program
if [ -e "$1" ];
then
#preprocessing the C program that will be analysed
#$1 -> source code name; $2 function name if there is.
exec_processadorc $1 $2
else
echo "No <$1> found - Please try again"
fi
}
#./uncrustify -q -l C -c ben.cfg -f ../ccode_here/testCode.c
exec_processadorc()
{
#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")
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $1 > $rec_path
#call ESBMC to get the claims-> <location of the pre-processed code(URL)> <only the code name>
#$2 function name if there is.
call_esbmc_claims $rec_path $name_program $2
}
call_esbmc_claims()
{
if [ $# -eq 2 ];
then
#no function in arg to apply it
#generating an internal extension (.cl -> claims) from original code
#var=$2
#pattern='^.[^.]*'
#if [[ $var =~ $pattern ]];
#then
#.cl -> claims
# rec_name=${BASH_REMATCH[0]}".cl"
#fi
tmp_cl=`echo $2| grep -o "[^/]*$" | grep -o "^[^.]*"`
rec_name=$tmp_cl".cl"
#Running the ESBMC to get the claims
esbmc $set_arch --no-library --show-claims $1 > $DIR_RESULT_CLAIMS/$rec_name
#Call the function that running the abstraction method to get data from claims
#ARGS function:
# $1 -> .cl file
# $2 -> list claims;
# $3 -> code path;
# $4 -> code name;
# $5 -> path result claims
call_abs_claims "$DIR_RESULT_CLAIMS/$rec_name" "$1" "$2" "$tmp_cl" "$DIR_RESULT_CLAIMS"
else
#function in arg to apply it
#generating an internal extension (.cl -> claims) from original code
rec_name_function_abs=$3
valid_func=`cat $1 | grep -c "$rec_name_function_abs(.*)"`
if [ $valid_func -ge 1 ];
then
tmp_name=`echo $2| grep -o "[^/]*$" | grep -o "^[^.]*"`
rec_name=$tmp_name".cl"
##.cl -> claims
rec_name=$tmp_name"_func_"$rec_name_function_abs".cl"
#Running the ESBMC to get the claims
esbmc $set_arch --no-library --function $rec_name_function_abs --show-claims $1 > $DIR_RESULT_CLAIMS/$rec_name
#Call the function that running the abstraction method to get data from claims
call_abs_claims "$DIR_RESULT_CLAIMS/$rec_name" "$1" "$rec_name_function_abs" "$2"
else
echo "This name function: <$rec_name_function_abs> is not a valid function in the code!"
fi
fi
}
#Call the method that gatherig all data in the claims shown by ESBMC
call_abs_claims(){
#generating an internal extension (.abs) for abstraction from claims
rec_name_2=$4".csv"
#ABS_CLAIMS receives as input all claims
if [ $# -eq 5 ];
then
#All claims
$DIR_ABS_CLAIMS $1 > $DIR_RESULT_CLAIMS"/$rec_name_2"
get_and_set_claims "$DIR_RESULT_CLAIMS/$rec_name_2" "$2" "$3"
else
#based on function, where $3 is function name
$DIR_ABS_CLAIMS_FUNC $1 $3 > $DIR_RESULT_CLAIMS"/$rec_name_2"
get_and_set_claims "$DIR_RESULT_CLAIMS/$rec_name_2" "$2" "$4"
fi
}
get_and_set_claims(){
#$1 -> list claims; $2-> path pre-processing code; $3 -> code name
tmp_path=$(echo $2 | sed "s/pre_$3/new_$3.tmp/g")
out=`$DIR_GET_AND_SET_CLAIMS $1 $2 $tmp_path`
#if the out == 1 there are not claims
rec_out=`echo $out | grep -c "1"`
if [ $rec_out -eq 0 ];
then
#applying last formatting due to possible inclusion of new lines in the code
#call the end preprocessing
$DIR_PROC_PRIMARY -q -l C -c $CONFIG_CFG -f $tmp_path
rm $tmp_path
rm $2
else
echo "There are not claims for this functions!"
fi
}
clean(){
gt_file=$(ls $DIR_RESULT_CLAIMS/)
if [ -n "$gt_file" ];
then
rm $DIR_RESULT_CLAIMS/*
fi
}
#------------------------------ end functions -------------------------
#------------------------------ main -----------------------------
if [ $# -ge 1 ];
then
while getopts "hcf:" flag
do
case "${flag}" in
h)
received_h=1
;;
c)
received_c=1
;;
f)
received_f=1
arg_f="${OPTARG}"
;;
*)
echo "Sorry, there isn't this option!"
exit 1;
;;
esac
done
else
echo "Please provide a C program to apply - fortes <file.c> or usage fortes -h"
fi
#Checking the options
if [ ${received_h} ]
then
echo ""
echo "------------------------------ FORTES (Beta) v2 ---------------------------"
echo " .-."
echo " /v\\"
echo " // \\\\ > L I N U X - GPL <"
echo " /( )\\"
echo " ^^-^^"
echo "-----------------------------------------------------------------------------"
echo "Usage: Purpose:"
echo ""
echo "fortes [-h] Show help"
echo "fortes \"<file.c>\" Source file - Default: Based on all claims, "
echo " adopting the following ESBMC options:"
echo " esbmc --<arch> --no-library --show-claims <\$file.c>"
echo "_____________________________________________________________________________"
echo "Additonal options:"
echo ""
echo "fortes [-c] "
echo " Clean all folders (old results)"
echo "fortes [-f] \"<function_name>\" \"<file.c>\" "
echo " User can set main function name"
echo ""
echo "-----------------------------------------------------------------------------"
exit 1;
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 folders"
clean
fi
#exit 1;
elif [ ${received_f} ]
then
start_program ${!#} $arg_f
elif [ $# -ge 1 ]
then
start_program $1
fi
#------------------------------ main -----------------------------