Skip to content

Commit 867aa28

Browse files
committed
Adds regression test to cover code contracts support
Code contracts now supports assigns clause with structs and array ranges. It also supports contracts specified across multiple source files. So, we added regression tests to cover these capabilites. Signed-off-by: Felipe R. Monteiro <[email protected]>
1 parent 3538160 commit 867aa28

File tree

49 files changed

+745
-0
lines changed

Some content is hidden

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

49 files changed

+745
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void f1(int a[], int len) __CPROVER_assigns(a[2, 5])
2+
{
3+
int b[10];
4+
a = b;
5+
int *indr = a + 2;
6+
*indr = 5;
7+
}
8+
9+
int main()
10+
{
11+
int arr[10];
12+
f1(arr, 10);
13+
14+
return 0;
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks their assigns clause behavior when it reasons (indirectly)
10+
over a freshly-allocated variable.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
int idx = 4;
4+
5+
int nextIdx() __CPROVER_assigns(idx)
6+
{
7+
idx++;
8+
return idx;
9+
}
10+
11+
void f1(int a[], int len) __CPROVER_assigns(idx, a[2, 5])
12+
{
13+
a[nextIdx()] = 5;
14+
}
15+
16+
int main()
17+
{
18+
int arr[10];
19+
f1(arr, 10);
20+
21+
assert(idx == 5);
22+
23+
return 0;
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether the instrumentation process does not duplicate function calls
10+
used as part of array-index operations, i.e., if a function call is used in
11+
the computation of the index of an array assignment, then instrumenting that
12+
statement with an assigns clause will not result in multiple function calls.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
void f1(int a[], int len) __CPROVER_assigns(a[2, 5])
2+
{
3+
int *indr;
4+
indr = a + 3;
5+
*indr = 5;
6+
}
7+
8+
int main()
9+
{
10+
int arr[10];
11+
f1(arr, 10);
12+
13+
return 0;
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned indirectly
10+
through a pointer.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
void assigns_single(int a[], int len) __CPROVER_assigns(a[8])
2+
{
3+
a[8] = 20;
4+
}
5+
6+
void assigns_upper_bound(int a[], int len) __CPROVER_assigns(a[2, 5])
7+
{
8+
a[5] = 10;
9+
}
10+
11+
void assigns_lower_bound(int a[], int len) __CPROVER_assigns(a[2, 5])
12+
{
13+
a[2] = 10;
14+
}
15+
16+
int main()
17+
{
18+
int arr[10];
19+
assigns_upper_bound(arr, 10);
20+
assigns_lower_bound(arr, 10);
21+
assigns_single(arr, 10);
22+
23+
return 0;
24+
}
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+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned at both upper
10+
and lower bounds of its assignable array range. Single-value array range
11+
assignment is checked as well.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assign_out_under(int a[], int len) __CPROVER_assigns(a[2, 5])
2+
{
3+
a[1] = 5;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assign_out_under(arr, 10);
10+
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned at an index
10+
below its lower bound.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assign_out_under(int a[], int len) __CPROVER_assigns(a[8])
2+
{
3+
a[7] = 5;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assign_out_under(arr, 10);
10+
11+
return 0;
12+
}
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=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned at an index below
10+
its allowed index and specification contains only a single cell
11+
instead of a range.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assign_out_over(int a[], int len) __CPROVER_assigns(a[2, 5])
2+
{
3+
a[6] = 5;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assign_out_over(arr, 10);
10+
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned at an index
10+
above its upper bound.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assign_out_under(int a[], int len) __CPROVER_assigns(a[8])
2+
{
3+
a[9] = 5;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assign_out_under(arr, 10);
10+
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned at an index
10+
above its allowed index.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
void assigns_in_range(int a[], int last_idx) __CPROVER_assigns(a[2, last_idx])
2+
{
3+
a[last_idx] = 6;
4+
}
5+
6+
int main()
7+
{
8+
int arr[10];
9+
assigns_in_range(arr, 9);
10+
11+
return 0;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned at the upper
10+
bounds of its assignable array range, when the range has a non-constant bound.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
void assigns_in_range(int a[], int last_idx) __CPROVER_assigns(a[2, last_idx])
2+
{
3+
last_idx++;
4+
a[last_idx] = 6;
5+
}
6+
7+
int main()
8+
{
9+
int arr[10];
10+
assigns_in_range(arr, 9);
11+
12+
return 0;
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned past the upper
10+
bound of its assignable array range, using the symbol of the upper bound,
11+
after it has been incremented. This is intended to show that the bounds
12+
are determined at the time the function is called.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
void assigns_single(int a[], int len) __CPROVER_assigns(a[7])
2+
{
3+
}
4+
5+
void assigns_range(int a[], int len) __CPROVER_assigns(a[2, 5])
6+
{
7+
}
8+
9+
void assigns_big_range(int a[], int len) __CPROVER_assigns(a[2, 7])
10+
{
11+
assigns_single(a, len);
12+
assigns_range(a, len);
13+
}
14+
15+
int main()
16+
{
17+
int arr[10];
18+
assigns_big_range(arr, 10);
19+
20+
return 0;
21+
}
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+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned through
10+
calls to functions with array assigns clauses which are compatible with
11+
that of the caller.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
void assign_25(int a[], int len) __CPROVER_assigns(a[2, 5])
2+
{
3+
}
4+
5+
void assign_37(int a[], int len) __CPROVER_assigns(a[3, 7])
6+
{
7+
assign_25(a, len);
8+
}
9+
10+
int main()
11+
{
12+
int arr[10];
13+
assign_37(arr, 10);
14+
15+
return 0;
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when a function with an array assigns target
10+
calls a function which may assign below the allowable range.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
void assigns_ptr(int *x) __CPROVER_assigns(*x)
2+
{
3+
*x = 200;
4+
}
5+
6+
void assigns_range(int a[], int len) __CPROVER_assigns(a[2, 5])
7+
{
8+
int *ptr = &(a[3]);
9+
assigns_ptr(ptr);
10+
}
11+
12+
int main()
13+
{
14+
int arr[10];
15+
assigns_range(arr, 10);
16+
17+
return 0;
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--enforce-all-contracts
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
--
9+
Checks whether verification succeeds when an array is assigned via a
10+
function call which assigns a pointer to one of its elements.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
void assigns_ptr(int *x) __CPROVER_assigns(*x)
2+
{
3+
*x = 200;
4+
}
5+
6+
void assigns_range(int a[], int len) __CPROVER_assigns(a[2, 5])
7+
{
8+
int *ptr = &(a[7]);
9+
assigns_ptr(ptr);
10+
}
11+
12+
int main()
13+
{
14+
int arr[10];
15+
assigns_range(arr, 10);
16+
17+
return 0;
18+
}
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=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
--
9+
Checks whether verification fails when an array is assigned via a
10+
function call which assigns a pointer to an element out of the
11+
allowable range.

0 commit comments

Comments
 (0)