Skip to content

Commit ab68848

Browse files
author
Daniel Kroening
committed
tests for smt2_solver
1 parent 246472f commit ab68848

File tree

8 files changed

+166
-0
lines changed

8 files changed

+166
-0
lines changed

regression/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ DIRS = cbmc \
1111
strings-smoke-tests \
1212
cbmc-cover \
1313
goto-instrument-typedef \
14+
smt2_solver \
1415
strings \
1516
invariants \
1617
goto-diff \

regression/smt2_solver/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
default: tests.log
2+
3+
test:
4+
@../test.pl -p -c ../../../src/solvers/smt2_solver
5+
6+
tests.log: ../test.pl
7+
@../test.pl -p -c ../../../src/solvers/smt2_solver
8+
9+
show:
10+
@for dir in *; do \
11+
if [ -d "$$dir" ]; then \
12+
vim -o "$$dir/*.c" "$$dir/*.out"; \
13+
fi; \
14+
done;
15+
16+
clean:
17+
find -name '*.out' -execdir $(RM) '{}' \;
18+
$(RM) tests.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(set-logic QF_BV)
2+
3+
; From https://rise4fun.com/z3/tutorialcontent/guide
4+
5+
; Basic Bitvector Arithmetic
6+
(define-fun b01 () Bool (= (bvadd #x07 #x03) #x0a)) ; addition
7+
(define-fun b02 () Bool (= (bvsub #x07 #x03) #x04)) ; subtraction
8+
(define-fun b03 () Bool (= (bvneg #x07) #xf9)) ; unary minus
9+
(define-fun b04 () Bool (= (bvmul #x07 #x03) #x15)) ; multiplication
10+
(define-fun b05 () Bool (= (bvurem #x07 #x03) #x01)) ; unsigned remainder
11+
(define-fun b06 () Bool (= (bvsrem #x07 #x03) #x01)) ; signed remainder
12+
(define-fun b07 () Bool (= (bvsmod #x07 #x03) #x01)) ; signed modulo
13+
(define-fun b08 () Bool (= (bvshl #x07 #x03) #x38)) ; shift left
14+
(define-fun b09 () Bool (= (bvlshr #xf0 #x03) #x1e)) ; unsigned (logical) shift right
15+
(define-fun b10 () Bool (= (bvashr #xf0 #x03) #xfe)) ; signed (arithmetical) shift right#x0a
16+
17+
; Bitwise Operations
18+
19+
(define-fun w1 () Bool (= (bvor #x6 #x3) #x7)) ; bitwise or
20+
(define-fun w2 () Bool (= (bvand #x6 #x3) #x2)) ; bitwise and
21+
(define-fun w3 () Bool (= (bvnot #x6) #x9)) ; bitwise not
22+
(define-fun w4 () Bool (= (bvnand #x6 #x3) #xd)) ; bitwise nand
23+
(define-fun w5 () Bool (= (bvnor #x6 #x3) #x8)) ; bitwise nor
24+
(define-fun w6 () Bool (= (bvxnor #x6 #x3) #xa)) ; bitwise xnor
25+
26+
; We can prove a bitwise version of deMorgan's law
27+
28+
(declare-const x (_ BitVec 64))
29+
(declare-const y (_ BitVec 64))
30+
(define-fun d01 () Bool (= (bvand (bvnot x) (bvnot y)) (bvnot (bvor x y))))
31+
32+
; There is a fast way to check that fixed size numbers are powers of two
33+
34+
(define-fun is-power-of-two ((x (_ BitVec 4))) Bool
35+
(= #x0 (bvand x (bvsub x #x1))))
36+
(declare-const a (_ BitVec 4))
37+
(define-fun power-test () Bool
38+
(= (is-power-of-two a)
39+
(or (= a #x0)
40+
(= a #x1)
41+
(= a #x2)
42+
(= a #x4)
43+
(= a #x8))))
44+
45+
; Predicates over Bitvectors
46+
47+
(define-fun p1 () Bool (= (bvule #x0a #xf0) true)) ; unsigned less or equal
48+
(define-fun p2 () Bool (= (bvult #x0a #xf0) true)) ; unsigned less than
49+
(define-fun p3 () Bool (= (bvuge #x0a #xf0) false)) ; unsigned greater or equal
50+
(define-fun p4 () Bool (= (bvugt #x0a #xf0) false)) ; unsigned greater than
51+
(define-fun p5 () Bool (= (bvsle #x0a #xf0) false)) ; signed less or equal
52+
(define-fun p6 () Bool (= (bvslt #x0a #xf0) false)) ; signed less than
53+
(define-fun p7 () Bool (= (bvsge #x0a #xf0) true)) ; signed greater or equal
54+
(define-fun p8 () Bool (= (bvsgt #x0a #xf0) true)) ; signed greater than
55+
56+
; all must be true
57+
58+
(assert (not (and
59+
b01 b02 b03 b04 b05 b06 b07 b08 b09 b10
60+
d01
61+
power-test
62+
p1 p2 p3 p4 p5 p6 p7 p8)))
63+
64+
(check-sat)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
basic-bv1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(set-logic QF_BV)
2+
3+
; try 'let' on bitvectors
4+
5+
(define-fun x () (_ BitVec 4) #x0)
6+
7+
; very simple
8+
(define-fun let0 () Bool (= (let ((x #x0)) #x1) #x1))
9+
10+
; let hides the function 'x'
11+
(define-fun let1 () Bool (= (let ((x #x1)) x) #x1))
12+
13+
; the binding isn't visible immediately
14+
(define-fun let2 () Bool (= (let ((x x)) x) #x0))
15+
16+
; parallel let
17+
(define-fun let3 () Bool (= (let ((x #x1) (y x)) y) #x0))
18+
19+
; limited scope
20+
(define-fun let4 () Bool (and (= (let ((x #x1)) x) #x1) (= x #x0)))
21+
22+
; all must be true
23+
24+
(assert (not (and
25+
let0
26+
let1
27+
let2
28+
let3
29+
let4
30+
)))
31+
32+
(check-sat)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
let-with-bv1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--

regression/smt2_solver/let1/let1.smt2

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(set-logic QF_BV)
2+
3+
(define-fun x () Bool false)
4+
5+
; very simple
6+
(define-fun let0 () Bool (let ((x false)) true))
7+
8+
; let hides the function 'x'
9+
(define-fun let1 () Bool (let ((x true)) x))
10+
11+
; the binding isn't visible immediately
12+
(define-fun let2 () Bool (not (let ((x x)) x)))
13+
14+
; parallel let
15+
(define-fun let3 () Bool (let ((x true) (y x)) (not y)))
16+
17+
; limited scope
18+
(define-fun let4 () Bool (and (let ((x true)) x) (not x)))
19+
20+
; all must be true
21+
22+
(assert (not (and
23+
let0
24+
let1
25+
let2
26+
let3
27+
let4
28+
)))
29+
30+
(check-sat)

regression/smt2_solver/let1/test.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
let1.smt2
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^unsat$
7+
--

0 commit comments

Comments
 (0)