Skip to content

Commit 8ae50cd

Browse files
Merge pull request #579 from peterschrammel/test-gen-support
Test-gen support
2 parents 9f6ca11 + b7d828b commit 8ae50cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1276
-281
lines changed
660 Bytes
Binary file not shown.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import org.cprover.CProver;
2+
3+
class Assume1
4+
{
5+
static void foo(int x)
6+
{
7+
CProver.assume(x>3);
8+
assert x>0;
9+
}
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Assume1.class
3+
--function Assume1.foo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
661 Bytes
Binary file not shown.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import org.cprover.CProver;
2+
3+
class Assume2
4+
{
5+
static void foo(int x)
6+
{
7+
CProver.assume(x>3);
8+
assert x>4;
9+
}
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Assume2.class
3+
--function Assume2.foo
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
684 Bytes
Binary file not shown.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import org.cprover.CProver;
2+
3+
class Assume3
4+
{
5+
public static void main(String[] args)
6+
{
7+
CProver.assume(false);
8+
assert false;
9+
}
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
Assume3.class
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
750 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public class covered1
2+
{
3+
// this is a variable
4+
int x=1;
5+
//these are two, one line off the first
6+
int y=2;
7+
int z=3;
8+
//this is part of static init
9+
static int z0=0;
10+
11+
//another non-static
12+
int a;
13+
int b;
14+
static boolean odd;
15+
16+
static
17+
{
18+
odd=(z0+1)%2==0;
19+
}
20+
21+
covered1(int a, int b)
22+
{
23+
this.a=a*b;
24+
this.b=a+b;
25+
if(this.a==a)
26+
z0++;
27+
else
28+
odd=!odd;
29+
}
30+
// at the back
31+
int z1=2;
32+
int z2=3;
33+
int z3=4;
34+
//
35+
static int z4=5;
36+
int z5=5;
37+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
CORE
2+
covered1.class
3+
--cover location --json-ui --show-properties
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
.*\"coveredLines\": \"22\",$
7+
.*\"coveredLines\": \"4,6,7,23-25,31-33,36\",$
8+
.*\"coveredLines\": \"26\",$
9+
.*\"coveredLines\": \"28\",$
10+
.*\"coveredLines\": \"28\",$
11+
.*\"coveredLines\": \"28\",$
12+
.*\"coveredLines\": \"28\",$
13+
.*\"coveredLines\": \"29\",$
14+
.*\"coveredLines\": \"9,18\",$
15+
.*\"coveredLines\": \"18\",$
16+
.*\"coveredLines\": \"18\",$
17+
.*\"coveredLines\": \"18,35\",$
18+
--
19+
^warning: ignoring

scripts/bash-autocomplete/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cbmc.sh

scripts/bash-autocomplete/Readme.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# CBMC Autocomplete Scripts for Bash
2+
This directory contains an autocomplete script for bash.
3+
## Installation
4+
1. Compile cbmc and
5+
6+
2. `cd scripts/bash-autocomplete`
7+
8+
3. `./extract-switches.sh`
9+
10+
4. Put the following at the end of you in your `~/.bashrc`, with the directories adapted to your directory structure:
11+
```bash
12+
cbmcautocomplete=~/diffblue/cbmc/scripts/bash-autocomplete/cbmc.sh
13+
if [ -f $cbmcautocomplete ]; then
14+
. $cbmcautocomplete
15+
fi
16+
```
17+
## Usage
18+
As with the usual autocomplete in bash, start typing a switch to complete it, for example:
19+
```
20+
cbmc --clas<TAB>
21+
```
22+
will complete to
23+
```
24+
cbmc --classpath
25+
```
26+
27+
## Features implemented
28+
29+
* Completing all switches
30+
* Completing values for `--cover`, `--mm` and `--arch`
31+
* When completing a name of a file to analyze, only files with supported extensions are shown.
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
_cbmc_autocomplete()
3+
{
4+
#list of all switches cbmc has. IMPORTANT: in the template file, this variable must be defined on line 5.
5+
local switches=""
6+
#word on which the cursor is
7+
local cur=${COMP_WORDS[COMP_CWORD]}
8+
#previous word (in case it is a switch with a parameter)
9+
local prev=${COMP_WORDS[COMP_CWORD-1]}
10+
11+
#check if the command before cursor is a switch that takes parameters, if yes,
12+
#offer a choice of parameters
13+
case "$prev" in
14+
--cover) #for coverage we list the options explicitly
15+
COMPREPLY=( $( compgen -W "assertion path branch location decision condition mcdc cover" -- $cur ) )
16+
return 0
17+
;;
18+
--mm) #for memory models we list the options explicitly
19+
COMPREPLY=( $( compgen -W "sc tso pso" -- $cur ) )
20+
return 0
21+
;;
22+
--arch) #for architecture we list the options explicitly
23+
COMPREPLY=( $( compgen -W "i386 x86_64" -- $cur ) )
24+
return 0
25+
;;
26+
-I|--classpath|-cp|--outfile|--existing-coverage|--graphml-cex)
27+
#a switch that takes a file parameter of which we don't know an extension
28+
#TODO probably we can do more for -I, --classpath, -cp
29+
_filedir
30+
return 0
31+
;;
32+
esac
33+
34+
#complete a switch from a standard list, if the parameter under cursor starts with a hyphen
35+
if [[ "$cur" == -* ]]; then
36+
COMPREPLY=( $( compgen -W "$switches" -- $cur ) )
37+
return 0
38+
fi
39+
40+
#if none of the above applies, offer directories and files that we can analyze
41+
_filedir "@(class|jar|cpp|cc|c\+\+|ii|cxx|c|i|gb)"
42+
}
43+
complete -F _cbmc_autocomplete cbmc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
echo "Compiling the helper file to extract the raw list of parameters from cbmc"
3+
g++ -c -MMD -MP -std=c++11 -Wall -I ../../src/ -ftrack-macro-expansion=0 -fno-diagnostics-show-caret switch_extractor_helper.c -o tmp.o 2> pragma.txt
4+
5+
retval=$?
6+
7+
#clean up compiled files, we don't need them.
8+
rm tmp.o 2> /dev/null
9+
rm tmp.d 2> /dev/null
10+
11+
#check if compilation went fine
12+
if [ $retval -ne 0 ]; then
13+
echo "Problem compiling the helper file, parameter list not extracted."
14+
exit 1;
15+
fi
16+
17+
echo "Converting the raw parameter list to the format required by autocomplete scripts"
18+
rawstring=`sed "s/^.*pragma message: \(.*\)/\1/" pragma.txt`
19+
#delete pragma file, we won't need it
20+
rm pragma.txt 2> /dev/null
21+
22+
#now the main bit, convert from raw format to a proper list of switches
23+
cleanstring=`(
24+
#extract 2-hyphen switches, such as --foo
25+
#grep for '(foo)' expressions, and then use sed to remove parantheses and put '--' at the start
26+
(echo $rawstring | grep -o "([^)]*)" | sed "s/^.\(.*\).$/--\1/") ;
27+
#extract 1-hyphen switches, such as -F
28+
#use sed to remove all (foo) expressions, then you're left with switches and ':', so grep the colons out and then use sed to include the '-'
29+
(echo $rawstring | sed "s/([^)]*)//g" | grep -o "[a-zA-Z0-9]" | sed "s/\(.*\)/-\1/")
30+
) | tr '\n' ' '`
31+
32+
#sanity check that there is only one line of output
33+
if [ `echo $cleanstring | wc -l | awk '{print $1}'` -ne 1 ]; then
34+
echo "Problem converting the parameter list to the correct format, I was expecting one line but either got 0 or >2. This is likely to be an error in this conversion script."
35+
exit 1;
36+
fi
37+
38+
#sanity check that there are no dangerous characters
39+
echo $cleanstring | grep -q "[^a-zA-Z0-9 -]"
40+
if [ $? -eq 0 ]; then
41+
echo "Problem converting the parameter list to the correct format, illegal characters detected. This is likely to be an error in this conversion script."
42+
exit 1;
43+
fi
44+
45+
echo "Injecting the parameter list to the autocomplete file."
46+
sed "5 s/.*/ local switches=\"$cleanstring\"/" cbmc.sh.template > cbmc.sh
47+
48+
rm pragma.txt 2> /dev/null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "cbmc/cbmc_parse_options.h"
2+
3+
#pragma message CBMC_OPTIONS

src/Makefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,12 @@ libzip-build:
108108
@echo "Building libzip"
109109
@(cd ../libzip; BASE=`pwd`; ./configure --with-zlib=$(BASE)/zlib ; make)
110110

111-
.PHONY: minisat2-download glucose-download zlib-download libzip-download libzip-build
111+
cprover-jar-build:
112+
@echo "Building org.cprover.jar"
113+
@(cd java_bytecode/library/; \
114+
mkdir -p target; \
115+
javac -d target/ `find src/ -name "*.java"`; \
116+
cd target; jar cf org.cprover.jar `find . -name "*.class"`; \
117+
mv org.cprover.jar ../../../)
118+
119+
.PHONY: minisat2-download glucose-download zlib-download libzip-download libzip-build cprover-jar-build

src/goto-instrument/cover.cpp

+49-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ Date: May 2016
1010

1111
#include <algorithm>
1212
#include <iterator>
13+
#include <unordered_set>
1314

15+
#include <util/format_number_range.h>
1416
#include <util/prefix.h>
17+
#include <util/string2int.h>
1518

1619
#include "cover.h"
1720

@@ -28,14 +31,38 @@ class basic_blockst
2831
if(next_is_target || it->is_target())
2932
block_count++;
3033

34+
const irep_idt &line=it->source_location.get_line();
35+
if(!line.empty())
36+
block_line_cover_map[block_count]
37+
.insert(unsafe_string2unsigned(id2string(line)));
38+
3139
block_map[it]=block_count;
3240

3341
if(!it->source_location.is_nil() &&
3442
source_location_map.find(block_count)==source_location_map.end())
3543
source_location_map[block_count]=it->source_location;
3644

3745
next_is_target=
46+
#if 0
47+
// Disabled for being too messy
3848
it->is_goto() || it->is_function_call() || it->is_assume();
49+
#else
50+
it->is_goto() || it->is_function_call();
51+
#endif
52+
}
53+
54+
// create list of covered lines as CSV string and set as property of source
55+
// location of basic block, compress to ranges if applicable
56+
format_number_ranget format_lines;
57+
for(const auto &cover_set : block_line_cover_map)
58+
{
59+
assert(!cover_set.second.empty());
60+
std::vector<unsigned>
61+
line_list{cover_set.second.begin(), cover_set.second.end()};
62+
63+
std::string covered_lines=format_lines(line_list);
64+
source_location_map[cover_set.first]
65+
.set_basic_block_covered_lines(covered_lines);
3966
}
4067
}
4168

@@ -47,6 +74,11 @@ class basic_blockst
4774
typedef std::map<unsigned, source_locationt> source_location_mapt;
4875
source_location_mapt source_location_map;
4976

77+
// map block numbers to set of line numbers
78+
typedef std::map<unsigned, std::unordered_set<unsigned> >
79+
block_line_cover_mapt;
80+
block_line_cover_mapt block_line_cover_map;
81+
5082
inline unsigned operator[](goto_programt::const_targett t)
5183
{
5284
return block_map[t];
@@ -414,7 +446,7 @@ std::set<exprt> collect_mcdc_controlling_nested(
414446
const std::set<exprt> &decisions)
415447
{
416448
// To obtain the 1st-level controlling conditions
417-
std::set<exprt> controlling = collect_mcdc_controlling(decisions);
449+
std::set<exprt> controlling=collect_mcdc_controlling(decisions);
418450

419451
std::set<exprt> result;
420452
// For each controlling condition, to check if it contains
@@ -627,7 +659,7 @@ void remove_repetition(std::set<exprt> &exprs)
627659
**/
628660
for(auto &y : new_exprs)
629661
{
630-
bool iden = true;
662+
bool iden=true;
631663
for(auto &c : conditions)
632664
{
633665
std::set<signed> signs1=sign_of_expr(c, x);
@@ -669,7 +701,7 @@ void remove_repetition(std::set<exprt> &exprs)
669701
}
670702

671703
// update the original ''exprs''
672-
exprs = new_exprs;
704+
exprs=new_exprs;
673705
}
674706

675707
/*******************************************************************\
@@ -838,7 +870,8 @@ bool is_mcdc_pair(
838870

839871
if(diff_count==1)
840872
return true;
841-
else return false;
873+
else
874+
return false;
842875
}
843876

844877
/*******************************************************************\
@@ -963,7 +996,8 @@ void minimize_mcdc_controlling(
963996
{
964997
controlling=new_controlling;
965998
}
966-
else break;
999+
else
1000+
break;
9671001
}
9681002
}
9691003

@@ -1297,9 +1331,12 @@ void instrument_cover_goals(
12971331
const std::set<exprt> decisions=collect_decisions(i_it);
12981332

12991333
std::set<exprt> both;
1300-
std::set_union(conditions.begin(), conditions.end(),
1301-
decisions.begin(), decisions.end(),
1302-
inserter(both, both.end()));
1334+
std::set_union(
1335+
conditions.begin(),
1336+
conditions.end(),
1337+
decisions.begin(),
1338+
decisions.end(),
1339+
inserter(both, both.end()));
13031340

13041341
const source_locationt source_location=i_it->source_location;
13051342

@@ -1397,6 +1434,9 @@ void instrument_cover_goals(
13971434
f_it->first=="__CPROVER_initialize")
13981435
continue;
13991436

1400-
instrument_cover_goals(symbol_table, f_it->second.body, criterion);
1437+
instrument_cover_goals(
1438+
symbol_table,
1439+
f_it->second.body,
1440+
criterion);
14011441
}
14021442
}

0 commit comments

Comments
 (0)