Skip to content

Commit bc2f6a2

Browse files
committed
Add tests for the bitwise operators (and, or, not, xor)
1 parent 286bbff commit bc2f6a2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
bitwise_ops.c
3+
--incremental-smt2-solver 'z3 --smt2 -in' --slice-formula
4+
\[main\.assertion\.1\] line \d+ This is going to fail for bit-opposites: FAILURE
5+
\[main\.assertion\.2\] line \d+ This is going to hold for all values != 0: SUCCESS
6+
\[main\.assertion\.3\] line \d+ This is going to fail for the same value in A and B: FAILURE
7+
\[main\.assertion\.4\] line \d+ This will fail for the the same value in A and B: FAILURE
8+
^EXIT=10$
9+
^SIGNAL=0$
10+
--
11+
--
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
int main()
2+
{
3+
int a;
4+
int b;
5+
6+
__CPROVER_assume(a != 0);
7+
8+
// This if going to be failing for values of `0000` and `1111`,
9+
// as the bitwise-& of that will produce 0, failing this assertion.
10+
__CPROVER_assert(a & b, "This is going to fail for bit-opposites");
11+
// This will always be true, because bitwise-or allows a 1 at a bit
12+
// that either A or B have set as one, and with an assumption of
13+
// a != 0, there's always going to be at least 1 bit set, allowing
14+
// the assertion below to evaluate to true.
15+
__CPROVER_assert(a | b, "This is going to hold for all values != 0");
16+
// This will fail for the same value, as an XOR of the bits will
17+
// result in `0`, resulting in the assertion failure.
18+
__CPROVER_assert(
19+
a ^ b, "This is going to fail for the same value in A and B");
20+
// This will fail for the exact same value of A and B, as
21+
// NOT(A) will flip all the bits, resulting in the equality
22+
// below to be false for the assertion.
23+
__CPROVER_assert(~a == b, "This will fail for the the same value in A and B");
24+
}

0 commit comments

Comments
 (0)