Skip to content

Commit eae9473

Browse files
committed
Improved regression tests for invariant contract
- Moved comments from the source .c files to test case description in .desc files - Added several new tests to check multiple loops, nested loops, loop-local index variables etc. - Enabled one more regression test that was flagged as a buggy one
1 parent d20bbe1 commit eae9473

File tree

26 files changed

+249
-104
lines changed

26 files changed

+249
-104
lines changed

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/test.desc

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

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
// invar_check_04
2-
3-
// This test checks the handling of break by loop invariants.
4-
// This test is expected to fail along the code path where r is even before
5-
// entering the loop.
6-
71
#include <assert.h>
82

93
int main()
104
{
115
int r;
126
__CPROVER_assume(r >= 0);
137

14-
while(r>0)
8+
while(r > 0)
159
__CPROVER_loop_invariant(r >= 0)
1610
{
1711
--r;
@@ -24,6 +18,7 @@ int main()
2418
--r;
2519
}
2620
}
21+
2722
assert(r == 0);
2823

2924
return 0;
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
This test checks that conditionals and `break` are correctly handled.

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

Lines changed: 0 additions & 4 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()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
This test checks that conditionals and `continue` are correctly handled.

0 commit comments

Comments
 (0)