Skip to content

Commit b4c3a12

Browse files
authored
Merge pull request #6329 from NlightNFotis/assertions_before_assume
`--cover assume`: Add assert statements before assume to check for coverage of assume statements
2 parents f0ab57e + f869882 commit b4c3a12

File tree

18 files changed

+175
-2
lines changed

18 files changed

+175
-2
lines changed

doc/cprover-manual/modeling-assumptions.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,37 @@ int main() {
7171
This code fails, as there is a choice of x and y which results in a counterexample
7272
(any choice in which x and y are different).
7373

74+
## Coverage
75+
76+
You can ask CBMC to give coverage information regarding `__CPROVER_assume` statements.
77+
This is useful when you need, for example, to check which assume statements may have
78+
led to an emptying of the search state space, resulting in `assert` statements being
79+
vaccuously passed.
80+
81+
To use that invoke CBMC with the `--cover assume` option. For example, for a file:
82+
83+
```c
84+
#include <assert.h>
85+
86+
int main()
87+
{
88+
int x;
89+
__CPROVER_assume(x > 0);
90+
__CPROVER_assume(x < 0);
91+
assert(0 == 1);
92+
}
93+
```
94+
95+
CBMC invoked with `cbmc --cover assume test.c` will report:
96+
97+
```sh
98+
[main.1] file assume_assert.c line 6 function main assert(false) before assume(x > 0): SATISFIED
99+
[main.2] file assume_assert.c line 6 function main assert(false) after assume(x > 0): SATISFIED
100+
[main.3] file assume_assert.c line 7 function main assert(false) before assume(x < 0): SATISFIED
101+
[main.4] file assume_assert.c line 7 function main assert(false) after assume(x < 0): FAILED
102+
```
103+
104+
When an `assert(false)` statement before the assume has the property status `SATISFIED`,
105+
but is followed by an `assert(false)` statement *after* the assume statement that has status
106+
`FAILED`, this is an indication that this specific assume statement (on the line reported)
107+
is one that is emptying the search space for model checking.

doc/cprover-manual/test-suite.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ The table below summarizes the coverage criteria that CBMC supports.
213213
Criterion |Definition
214214
----------|----------
215215
assertion |For every assertion, generate a test that reaches it
216+
assume |For every assume, generate tests before and after the assume statement to indicate coverage before and after it
216217
location |For every location, generate a test that reaches it
217218
branch |Generate a test for every branch outcome
218219
decision |Generate a test for both outcomes of every Boolean expression that is not an operand of a propositional connective

jbmc/src/jbmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ OBJ += ../$(CPROVER_DIR)/src/ansi-c/ansi-c$(LIBEXT) \
2424
../$(CPROVER_DIR)/src/goto-instrument/cover$(OBJEXT) \
2525
../$(CPROVER_DIR)/src/goto-instrument/cover_basic_blocks$(OBJEXT) \
2626
../$(CPROVER_DIR)/src/goto-instrument/cover_filter$(OBJEXT) \
27+
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_assume$(OBJEXT) \
2728
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_branch$(OBJEXT) \
2829
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_condition$(OBJEXT) \
2930
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_decision$(OBJEXT) \

jbmc/src/jdiff/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ OBJ += ../$(CPROVER_DIR)/src/ansi-c/ansi-c$(LIBEXT) \
1818
../$(CPROVER_DIR)/src/goto-instrument/cover$(OBJEXT) \
1919
../$(CPROVER_DIR)/src/goto-instrument/cover_basic_blocks$(OBJEXT) \
2020
../$(CPROVER_DIR)/src/goto-instrument/cover_filter$(OBJEXT) \
21+
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_assume$(OBJEXT) \
2122
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_branch$(OBJEXT) \
2223
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_condition$(OBJEXT) \
2324
../$(CPROVER_DIR)/src/goto-instrument/cover_instrument_decision$(OBJEXT) \

jbmc/unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ CPROVER_LIBS =../src/java_bytecode/java_bytecode$(LIBEXT) \
105105
$(CPROVER_DIR)/src/goto-instrument/cover$(OBJEXT) \
106106
$(CPROVER_DIR)/src/goto-instrument/cover_basic_blocks$(OBJEXT) \
107107
$(CPROVER_DIR)/src/goto-instrument/cover_filter$(OBJEXT) \
108+
$(CPROVER_DIR)/src/goto-instrument/cover_instrument_assume$(OBJEXT) \
108109
$(CPROVER_DIR)/src/goto-instrument/cover_instrument_branch$(OBJEXT) \
109110
$(CPROVER_DIR)/src/goto-instrument/cover_instrument_condition$(OBJEXT) \
110111
$(CPROVER_DIR)/src/goto-instrument/cover_instrument_decision$(OBJEXT) \
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
int x;
6+
__CPROVER_assume(x > 0);
7+
__CPROVER_assume(x < 0);
8+
assert(0 == 1);
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
assume_assert.c
3+
--cover assume
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.coverage.1\] file assume_assert.c line \d function main assert\(false\) before assume\(x > 0\): SATISFIED$
7+
^\[main.coverage.2\] file assume_assert.c line \d function main assert\(false\) after assume\(x > 0\): SATISFIED$
8+
^\[main.coverage.3\] file assume_assert.c line \d function main assert\(false\) before assume\(x < 0\): SATISFIED$
9+
^\[main.coverage.4\] file assume_assert.c line \d function main assert\(false\) after assume\(x < 0\): FAILED$
10+
--
11+
^warning: ignoring
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
int a;
6+
7+
if(a > 0)
8+
{
9+
assert(a > 0);
10+
}
11+
else if(a < 0)
12+
{
13+
__CPROVER_assume(a >= 0);
14+
assert(a < 0);
15+
}
16+
else
17+
{
18+
assert(a == 0);
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
assume_assert.c
3+
--cover assume
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.coverage.1\] file assume_assert.c line \d+ function main assert\(false\) before assume\(a >= 0\): SATISFIED$
7+
^\[main.coverage.2\] file assume_assert.c line \d+ function main assert\(false\) after assume\(a >= 0\): FAILED$
8+
--
9+
^warning: ignoring

src/cbmc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
2626
../goto-instrument/cover$(OBJEXT) \
2727
../goto-instrument/cover_basic_blocks$(OBJEXT) \
2828
../goto-instrument/cover_filter$(OBJEXT) \
29+
../goto-instrument/cover_instrument_assume$(OBJEXT) \
2930
../goto-instrument/cover_instrument_branch$(OBJEXT) \
3031
../goto-instrument/cover_instrument_condition$(OBJEXT) \
3132
../goto-instrument/cover_instrument_decision$(OBJEXT) \

0 commit comments

Comments
 (0)