Skip to content

Commit 5e479a5

Browse files
Unified wrapper script for CPROVER tools
Run the Makefile to build the tool wrapper script from tool-wrapper.inc and tool-specific includes which define tool and executable names as well as a run function, currently provided for CBMC and 2LS. tool-wrapper.inc contains a mapping from SV-COMP properties to the CPROVER property instrumentation options.
1 parent 68733a2 commit 5e479a5

File tree

6 files changed

+224
-123
lines changed

6 files changed

+224
-123
lines changed

2ls.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# tool
2+
3+
TOOL_BINARY=./2ls-binary
4+
TOOL_NAME=2LS
5+
6+
# function to run the tool
7+
8+
run()
9+
{
10+
# add property-specific options
11+
if [[ "$PROP" == "termination" ]]; then
12+
PROPERTY="$PROPERTY --termination --competition-mode"
13+
else
14+
PROPERTY="$PROPERTY --k-induction --competition-mode"
15+
fi
16+
17+
# run the tool
18+
$TOOL_BINARY --graphml-witness $LOG.witness $BIT_WIDTH $PROPERTY \
19+
--function $ENTRY $BM >> $LOG.ok 2>&1
20+
21+
# store the exit code
22+
EC=$?
23+
}

Makefile

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
11
CBMC=../cbmc
2+
2LS=../2ls
3+
YEAR=2017
24

3-
all:
5+
all: cbmc 2ls
6+
7+
cbmc: CBMC-sv-comp-$(YEAR).tar.gz
8+
9+
2ls: 2ls-sv-comp-$(YEAR).tar.gz
10+
11+
.PHONY: cbmc 2ls
12+
13+
%-wrapper: %.inc tool-wrapper.inc
14+
echo "#!/bin/bash" > $@
15+
cat $*.inc tool-wrapper.inc >> $@
16+
chmod 755 $@
17+
18+
CBMC-sv-comp-$(YEAR).tar.gz: cbmc.inc tool-wrapper.inc $(CBMC)/LICENSE $(CBMC)/src/cbmc/cbmc
419
mkdir -p tmp
5-
cp $(CBMC)/LICENSE cbmc tmp/
20+
$(MAKE) cbmc-wrapper
21+
mv cbmc-wrapper tmp/cbmc
22+
cp $(CBMC)/LICENSE tmp/
623
cp $(CBMC)/src/cbmc/cbmc tmp/cbmc-binary
7-
cd tmp; tar cfz ../CBMC-sv-comp-2017.tar.gz *; rm cbmc cbmc-binary LICENSE; cd ..; rm -R tmp
24+
cd tmp && tar cfz ../$@ * && rm cbmc cbmc-binary LICENSE
25+
rmdir tmp
26+
27+
2ls-sv-comp-$(YEAR).tar.gz: 2ls.inc tool-wrapper.inc $(2LS)/LICENSE $(2LS)/src/summarizer/2ls
28+
mkdir -p tmp
29+
$(MAKE) 2ls-wrapper
30+
mv 2ls-wrapper tmp/2ls
31+
cp $(2LS)/LICENSE tmp/
32+
cp $(2LS)/src/summarizer/2ls tmp/2ls-binary
33+
cd tmp && tar cfz ../$@ * && rm 2ls 2ls-binary LICENSE
34+
rmdir tmp

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55
`make`
66

7-
#### Wrapper script
7+
#### Build wrapper script
88

9-
`cbmc`
9+
`make` tool`-wrapper`
10+
11+
where tool is `cbmc` or `2ls`, for instance
1012

1113
#### Benchexec tool script
1214

13-
https://github.com/sosy-lab/benchexec/blob/master/benchexec/tools/cbmc.py
15+
* CBMC: https://github.com/sosy-lab/benchexec/blob/master/benchexec/tools/cbmc.py
16+
* 2LS: https://github.com/sosy-lab/benchexec/blob/master/benchexec/tools/two_ls.py
1417

1518
#### Benchexec benchmark definition
1619

17-
https://github.com/sosy-lab/sv-comp/blob/master/benchmark-defs/cbmc.xml
20+
* CBMC: https://github.com/sosy-lab/sv-comp/blob/master/benchmark-defs/cbmc.xml
21+
* 2LS: https://github.com/sosy-lab/sv-comp/blob/master/benchmark-defs/2ls.xml
1822

1923
#### License
2024

cbmc

Lines changed: 0 additions & 116 deletions
This file was deleted.

cbmc.inc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# tool
2+
3+
TOOL_BINARY=./cbmc-binary
4+
TOOL_NAME=CBMC
5+
6+
# function to run the tool
7+
8+
run()
9+
{
10+
timeout 850 bash -c ' \
11+
\
12+
ulimit -v 15000000 ; \
13+
\
14+
EC=42 ; \
15+
for c in 2 6 12 17 21 40 200 400 1025 2049 268435456 ; do \
16+
echo "Unwind: $c" > $LOG.latest ; \
17+
./cbmc-binary --graphml-witness $LOG.witness --unwind $c --stop-on-fail $BIT_WIDTH $PROPERTY --function $ENTRY $BM >> $LOG.latest 2>&1 ; \
18+
ec=$? ; \
19+
if [ $ec -eq 0 ] ; then \
20+
if ! tail -n 10 $LOG.latest | grep -q "^VERIFICATION SUCCESSFUL$" ; then ec=1 ; fi ; \
21+
fi ; \
22+
if [ $ec -eq 10 ] ; then \
23+
if ! tail -n 10 $LOG.latest | grep -q "^VERIFICATION FAILED$" ; then ec=1 ; fi ; \
24+
fi ; \
25+
\
26+
case $ec in \
27+
0) EC=0 ; mv $LOG.latest $LOG.ok ; echo "EC=$EC" >> $LOG.ok ;; \
28+
10) EC=10 ; mv $LOG.latest $LOG.ok ; echo "EC=$EC" >> $LOG.ok ; break ;; \
29+
*) if [ $EC -ne 0 ] ; then EC=$ec ; mv $LOG.latest $LOG.ok ; fi ; echo "EC=$EC" >> $LOG.ok ; break ;; \
30+
esac ; \
31+
\
32+
done \
33+
'
34+
}

tool-wrapper.inc

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
2+
# main tool wrapper script
3+
# run "make <tool>-wrapper" to generate the wrapper script
4+
5+
# map properties to tool options
6+
7+
declare -A OPTIONS
8+
OPTIONS["label"]="--error-label"
9+
OPTIONS["unreach_call"]=""
10+
OPTIONS["termination"]=""
11+
OPTIONS["overflow"]="--signed-overflow-check"
12+
OPTIONS["memsafety"]="--pointer-check --memory-leak-check --bounds-check"
13+
14+
parse_property_file()
15+
{
16+
local fn=$1
17+
18+
cat $fn | sed 's/[[:space:]]//g' | perl -n -e '
19+
if(/^CHECK\(init\((\S+)\(\)\),LTL\((\S+)\)\)$/) {
20+
print "ENTRY=$1\n";
21+
print "PROP=\"label\"\nLABEL=\"$1\"\n" if($2 =~ /^G!label\((\S+)\)$/);
22+
print "PROP=\"unreach_call\"\n" if($2 =~ /^G!call\(__VERIFIER_error\(\)\)$/);
23+
print "PROP=\"memsafety\"\n" if($2 =~ /^Gvalid-(free|deref|memtrack)$/);
24+
print "PROP=\"overflow\"\n" if($2 =~ /^G!overflow$/);
25+
print "PROP=\"termination\"\n" if($2 =~ /^Fend$/);
26+
}'
27+
}
28+
29+
parse_result()
30+
{
31+
if tail -n 50 $LOG.ok | grep -q "^[[:space:]]*__CPROVER_memory_leak == NULL$"\
32+
; then
33+
echo 'FALSE(valid-memtrack)'
34+
elif tail -n 50 $LOG.ok | grep -q "^[[:space:]]*dereference failure:" ; then
35+
echo 'FALSE(valid-deref)'
36+
elif tail -n 50 $LOG.ok | grep -q "^[[:space:]]*double free$" ; then
37+
echo 'FALSE(valid-free)'
38+
elif tail -n 50 $LOG.ok | grep -q "^[[:space:]]*free argument has offset zero\
39+
$" ; then
40+
echo 'FALSE(valid-free)'
41+
elif tail -n 50 $LOG.ok | grep -q "^[[:space:]]*arithmetic overflow on signed\
42+
" ; then
43+
echo 'FALSE(no-overflow)'
44+
elif [[ "$PROP" == "termination" ]]; then
45+
echo 'FALSE(termination)'
46+
else
47+
echo FALSE
48+
fi
49+
}
50+
51+
process_graphml()
52+
{
53+
if [ -f $LOG.witness ]; then
54+
if [ $1 -eq 0 ]; then
55+
TYPE="correctness_witness"
56+
else
57+
TYPE="violation_witness"
58+
fi
59+
cat $LOG.witness | perl -p -e "s/(<graph edgedefault=\"directed\">)/\$1\\E
60+
<data key=\"witness-type\">$(echo $TYPE)<\/data>
61+
<data key=\"producer\">$(echo $TOOL_NAME)<\/data>
62+
<data key=\"specification\">$(<$PROP_FILE)<\/data>
63+
<data key=\"programfile\">$(echo $BM | sed 's8/8\\/8g')<\/data>
64+
<data key=\"programhash\">$(sha1sum $BM | awk '{print $1}')<\/data>
65+
<data key=\"architecture\">${BIT_WIDTH##--}bit<\/data>\\Q/"
66+
fi
67+
}
68+
69+
BIT_WIDTH="--64"
70+
BM=""
71+
PROP_FILE=""
72+
WITNESS_FILE=""
73+
74+
while [ -n "$1" ] ; do
75+
case "$1" in
76+
--32|--64) BIT_WIDTH="$1" ; shift 1 ;;
77+
--propertyfile) PROP_FILE="$2" ; shift 2 ;;
78+
--graphml-witness) WITNESS_FILE="$2" ; shift 2 ;;
79+
--version) $TOOL_BINARY --version ; exit 0 ;;
80+
*) BM="$1" ; shift 1 ;;
81+
esac
82+
done
83+
84+
if [ -z "$BM" ] || [ -z "$PROP_FILE" ] ; then
85+
echo "Missing benchmark or property file"
86+
exit 1
87+
fi
88+
89+
if [ ! -s "$BM" ] || [ ! -s "$PROP_FILE" ] ; then
90+
echo "Empty benchmark or property file"
91+
exit 1
92+
fi
93+
94+
eval `parse_property_file $PROP_FILE`
95+
96+
if [[ "$PROP" == "" ]]; then
97+
echo "Unrecognized property specification"
98+
exit 1
99+
elif [[ "$PROP" == "label" ]]; then
100+
PROPERTY="${OPTIONS[$PROP]} $LABEL"
101+
else
102+
PROPERTY=${OPTIONS[$PROP]}
103+
fi
104+
105+
export ENTRY
106+
export PROPERTY
107+
export BIT_WIDTH
108+
export BM
109+
export PROP
110+
111+
export LOG=`mktemp -t ${TOOL_NAME}-log.XXXXXX`
112+
trap "rm -f $LOG $LOG.latest $LOG.ok $LOG.witness" EXIT
113+
114+
run
115+
116+
if [ ! -s $LOG.ok ] ; then
117+
exit 1
118+
fi
119+
120+
eval `tail -n 1 $LOG.ok`
121+
cat $LOG.ok
122+
case $EC in
123+
0) if [[ "$WITNESS_FILE" != "" ]]; then process_graphml $EC > $WITNESS_FILE; \
124+
fi; echo "TRUE" ;;
125+
10) if [[ "$WITNESS_FILE" != "" ]]; then process_graphml $EC > $WITNESS_FILE;\
126+
fi; parse_result ;;
127+
*) echo "UNKNOWN" ;;
128+
esac
129+
exit $EC

0 commit comments

Comments
 (0)