Skip to content

Commit de68b68

Browse files
committed
Add regression tests for the handling of unsigned integers.
1 parent 4808c35 commit de68b68

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

regression/cbmc-incr-smt2/bitvector-arithmetic-operators/simple_equation.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,31 @@ int main()
1616
__CPROVER_assert((a * a) / a == a, "a squared divided by a equals a");
1717
__CPROVER_assert((2 * a) / a == 2, "two times a divided by a equals two");
1818
__CPROVER_assert(a % a == 0, "a mod itself equals 0");
19+
20+
// Same round of tests, but for a type of different size
21+
long long int b;
22+
__CPROVER_assume(b < 100ll);
23+
__CPROVER_assume(b > -100ll);
24+
__CPROVER_assume(b != 0ll);
25+
26+
__CPROVER_assert(b + b == b * 2ll, "b plus b always equals two times b");
27+
__CPROVER_assert(b - b == 0ll, "b minus b always equals 0");
28+
__CPROVER_assert(b + -b == 0ll, "b plus its additive inverse equals 0");
29+
__CPROVER_assert(
30+
b - -b == 2ll * b, "b minus its additive inverse equals two times b");
31+
__CPROVER_assert((b * b) / b == b, "b squared divided by b equals b");
32+
__CPROVER_assert((2ll * b) / b == 2ll, "two times b divided by b equals two");
33+
__CPROVER_assert(b % b == 0ll, "b mod itself equals 0");
34+
35+
char c = 0x0;
36+
__CPROVER_assume(c != 0x00);
37+
38+
__CPROVER_assert(c + c == c * 0x2, "c plus c always equals two times c");
39+
__CPROVER_assert(c - c == 0x0, "c minus c always equals 0");
40+
__CPROVER_assert(c + -c == 0x0, "c plus its additive inverse equals 0");
41+
__CPROVER_assert(
42+
c - -c == 0x2 * c, "c minus its additive inverse equals two times c");
43+
__CPROVER_assert((c * c) / c == c, "c squared divided by c equals c");
44+
__CPROVER_assert((0x2 * c) / c == 0x2, "two times c divided by c equals two");
45+
__CPROVER_assert(c % c == 0x0, "c mod itself equals 0");
1946
}

regression/cbmc-incr-smt2/bitvector-arithmetic-operators/simple_equation.desc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ simple_equation.c
88
\[main\.assertion\.5\] line \d+ a squared divided by a equals a: SUCCESS
99
\[main\.assertion\.6\] line \d+ two times a divided by a equals two: SUCCESS
1010
\[main\.assertion\.7\] line \d+ a mod itself equals 0: SUCCESS
11+
\[main\.assertion\.8\] line \d+ b plus b always equals two times b: SUCCESS
12+
\[main\.assertion\.9\] line \d+ b minus b always equals 0: SUCCESS
13+
\[main\.assertion\.10\] line \d+ b plus its additive inverse equals 0: SUCCESS
14+
\[main\.assertion\.11\] line \d+ b minus its additive inverse equals two times b: SUCCESS
15+
\[main\.assertion\.12\] line \d+ b squared divided by b equals b: SUCCESS
16+
\[main\.assertion\.13\] line \d+ two times b divided by b equals two: SUCCESS
17+
\[main\.assertion\.14\] line \d+ b mod itself equals 0: SUCCESS
18+
\[main\.assertion\.15\] line \d+ c plus c always equals two times c: SUCCESS
19+
\[main\.assertion\.16\] line \d+ c minus c always equals 0: SUCCESS
20+
\[main\.assertion\.17\] line \d+ c plus its additive inverse equals 0: SUCCESS
21+
\[main\.assertion\.18\] line \d+ c minus its additive inverse equals two times c: SUCCESS
22+
\[main\.assertion\.19\] line \d+ c squared divided by c equals c: SUCCESS
23+
\[main\.assertion\.20\] line \d+ two times c divided by c equals two: SUCCESS
24+
\[main\.assertion\.21\] line \d+ c mod itself equals 0: SUCCESS
1125
^VERIFICATION SUCCESSFUL$
1226
^EXIT=0$
1327
^SIGNAL=0$
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
int main()
2+
{
3+
unsigned int a;
4+
unsigned int b = 12;
5+
__CPROVER_assume(a > 15);
6+
7+
// expected to fail by assigning a = 4294967284u in the trace
8+
// and wrapping around to 0, which results in 0 > 27.
9+
__CPROVER_assert(a + b > 27, "a plus b should be more than 27");
10+
// expected to fail by assigning a = 2147483648u in the trace
11+
// and evaluating to 2147483660 > 27, which is true.
12+
__CPROVER_assert(!(a + b > 27), "a plus b should be more than 27");
13+
14+
// Same round of tests but for unsigned long long.
15+
unsigned long long int c;
16+
unsigned long long int d = 12llu;
17+
__CPROVER_assume(c > 15llu);
18+
19+
__CPROVER_assert(c + d > 27, "c plus d should be more than 27");
20+
__CPROVER_assert(!(c + d > 27), "c plus d should be more than 27");
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
unsigned_behaviour.c
3+
--incremental-smt2-solver 'z3 --smt2 -in' --trace
4+
\[main\.assertion\.1\] line \d+ a plus b should be more than 27: FAILURE
5+
\[main\.assertion\.2\] line \d+ a plus b should be more than 27: FAILURE
6+
\[main\.assertion\.3\] line \d+ c plus d should be more than 27: FAILURE
7+
\[main\.assertion\.4\] line \d+ c plus d should be more than 27: FAILURE
8+
a=\d+(u|ul)?
9+
c=\d+(u|ul)?
10+
^VERIFICATION FAILED$
11+
^EXIT=10$
12+
^SIGNAL=0$
13+
--
14+
--
15+
This test checks for the correct behaviour of unsigned integers around
16+
boundary values.

0 commit comments

Comments
 (0)