-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdReach.sh
executable file
·150 lines (137 loc) · 3.59 KB
/
dReach.sh
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
#!/bin/bash
SCRIPTPATH=`dirname $(readlink -f $0)`
BMC=${SCRIPTPATH}/tools/bmc/bmc.sh
BMC_OCAML=${SCRIPTPATH}/tools/bmc/main.native
DREAL=${SCRIPTPATH}/dReal
PRECISION=0.1
DREAL_OPTION="--visualize"
TIMEOUT_UTIL=${SCRIPTPATH}/timeout3
#################################################################
# USAGE
#################################################################
usage()
{
cat << EOF
usage: $0 options <*.drh>
dReach: Reachability Analysis for Nonlinear Hybrid Systems
OPTIONS:
-p precision (\delta) value for dReal (default: 0.001)
-i use infix parser in BMC (default: use prefix)
-l lower bound for the unrolling (default: 0)
-s step for the unrolling (default: 1)
-u upper bound for the unrolling (required)
-t timeout in second (required)
-h Show this message
-v Verbose
EOF
}
#################################################################
# Parse Option
#################################################################
TIMEOUT=
PRECISION=0.001
LB=0
BMC_PARSER=
UB=
STEP=1
VERBOSE=
while getopts "hl:u:p:s:t:vi" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
t)
TIMEOUT=$OPTARG
;;
l)
LB=$OPTARG
;;
u)
UB=$OPTARG
;;
s)
STEP=$OPTARG
;;
p)
PRECISION=$OPTARG
;;
v)
VERBOSE=1
;;
i)
BMC_PARSER="-i"
;;
\?)
usage
exit
;;
esac
done
#################################################################
# Check BMC & DREAL
#################################################################
if [ ! -e $BMC ]
then
echo "BMC is not found at $BMC"
echo "Please edit $0 to specify the correct location of BMC tool"
exit 1
fi
if [ ! -e $BMC_OCAML ]
then
echo "BMC(Ocaml) is not found at $BMC_OCAML"
echo "Please edit $0 to specify the correct location of BMC tool"
exit 1
fi
if [ ! -e $DREAL ]
then
echo "dReal is not found at $DREAL"
echo "Please edit $0 to specify the correct location of dReal tool"
exit 1
fi
$TIMEOUT_UTIL > /dev/null 2>&1
if [ $? -eq 127 ]
then
echo "timeout is not found"
echo "Please install one (such as timeout, gtimeout, or timeout3)."
exit 1
fi
shift $(($OPTIND - 1))
if [[ -z $TIMEOUT || -z $UB || -z $1 || ! -e $1 || ! ${1: -4} == ".drh" ]]
then
usage
exit 1
fi
function log_output {
echo `date`: "$1"
}
BASE=${1%.drh}
DRH=$BASE.drh
echo "PRECISION=$PRECISION"
echo "LB=$LB UB=$UB TIMEOUT=$TIMEOUT"
echo "DRH=$DRH"
for (( K=$LB; K<=$UB; K=$K + $STEP ))
do
echo "=================================== K = $K ==========================================================================="
SMT2=${BASE}_$K.smt2
RESULT=${BASE}_$K.smt2.result
log_output "Unroll $DRH => $SMT2:"
echo "$BMC -k $K $BMC_PARSER $DRH > $SMT2"
$BMC -k $K $BMC_PARSER $DRH > $SMT2 || { log_output "BMC ERROR"; exit 77; }
log_output "Run dReal --precision=$PRECISION $DREAL_OPTION $SMT2"
$TIMEOUT_UTIL -t ${TIMEOUT} $DREAL --precision=$PRECISION $DREAL_OPTION $SMT2 > $RESULT || { log_output "dReal T/O"; exit 77; }
if [[ "`cat $RESULT`" == "sat" ]]
then
log_output "Result: sat"
fi
if [[ "`cat $RESULT`" == "unsat" ]]
then
log_output "Result: unsat"
fi
if [[ "`cat $RESULT`" == "unknown" ]]
then
log_output "Timed-out"
exit 77
fi
done