Skip to content

Commit 142ff6a

Browse files
committed
Improved regression tests for invariant contract
- Moved comments from .c files to descriptions in .desc files - Added new tests to check multiple loops, nested loops, loop-local variables - Enabled and clarified a regression test that was flagged as a buggy one
1 parent aede6f9 commit 142ff6a

File tree

28 files changed

+352
-167
lines changed

28 files changed

+352
-167
lines changed

regression/contracts/invar_check_01/main.c

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

regression/contracts/invar_check_01/test.desc

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

regression/contracts/invar_check_02/test.desc

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

regression/contracts/invar_check_03/test.desc

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

regression/contracts/invar_check_04/main.c

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

regression/contracts/invar_check_04/test.desc

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

regression/contracts/invar_check_02/main.c renamed to regression/contracts/invar_check_break_fail/main.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// invar_check_02
2-
3-
// This test checks that loop invariants adequately handle continues.
4-
51
#include <assert.h>
62

73
int main()
@@ -11,17 +7,17 @@ int main()
117

128
while(r > 0)
139
__CPROVER_loop_invariant(r >= 0)
14-
{
15-
--r;
16-
if (r < 5)
17-
{
18-
continue;
19-
}
20-
else
2110
{
2211
--r;
12+
if(r <= 1)
13+
{
14+
break;
15+
}
16+
else
17+
{
18+
--r;
19+
}
2320
}
24-
}
2521

2622
assert(r == 0);
2723

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7+
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[main.assertion.1\] .* assertion r == 0: FAILURE$
9+
^VERIFICATION FAILED$
10+
--
11+
This test is expected to fail along the code path where r is an even integer
12+
before entering the loop.
13+
The program is simply incompatible with the desired property in this case --
14+
there is no loop invariant that can establish the required assertion.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
int r;
6+
__CPROVER_assume(r >= 0);
7+
8+
while(r > 0)
9+
__CPROVER_loop_invariant(r >= 0)
10+
{
11+
--r;
12+
if(r <= 1)
13+
{
14+
break;
15+
}
16+
else
17+
{
18+
--r;
19+
}
20+
}
21+
22+
assert(r == 0 || r == 1);
23+
24+
return 0;
25+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7+
^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8+
^\[main.assertion.1\] .* assertion r == 0 || r == 1: SUCCESS$
9+
^VERIFICATION SUCCESSFUL$
10+
--
11+
This test checks that conditionals and `break` are correctly handled.

0 commit comments

Comments
 (0)