Skip to content

Commit 1885f01

Browse files
committed
Added tests and more types
1 parent ec3df76 commit 1885f01

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

wp/plugin/lib/equality.ml

+10-7
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ let compare_lbl (lbl1 : label) (lbl2 : label) (map : varToVarMap) : varToVarMap
148148
(* Compares two things:
149149
- jmp1 and jmp2 match in structure
150150
- jmp1 and jmp2 match in all Exp.ts contained within *)
151-
let compare_jmp jmp1 jmp2 map =
151+
let compare_jmp (jmp1 : jmp term) (jmp2 : jmp term) (map : varToVarMap) :
152+
varToVarMap option =
152153
match Jmp.kind jmp1, Jmp.kind jmp2 with
153154
| Goto label1, Goto label2 -> compare_lbl label1 label2 map
154155
| Call call1, Call call2 ->
@@ -167,7 +168,8 @@ let compare_jmp jmp1 jmp2 map =
167168
| _, _ -> None
168169

169170
(* There should be no phi terms. Fail if there are. *)
170-
let compare_phis phis1 phis2 map =
171+
let compare_phis (phis1 : (phi term) list) (phis2 : (phi term) list)
172+
(map : varToVarMap) : varToVarMap option =
171173
if List.length phis1 > 0 || List.length phis2 > 0 then None
172174
else Some map
173175

@@ -184,7 +186,8 @@ let compare_defs (defs1 : (def term) list)
184186
| Some map -> compare_def d1 d2 map)
185187

186188
(* Check that all jmps in a list match in expression and structure but not TID. *)
187-
let compare_jmps jmps1 jmps2 map =
189+
let compare_jmps (jmps1 : (jmp term) list) (jmps2 : (jmp term) list)
190+
(map : varToVarMap) : varToVarMap option =
188191
match List.zip jmps1 jmps2 with
189192
| Core_kernel.List.Or_unequal_lengths.Unequal_lengths -> None
190193
| Core_kernel.List.Or_unequal_lengths.Ok z ->
@@ -252,8 +255,8 @@ let compare_blocks (sub1: Sub.t) (sub2 : Sub.t) :
252255
BFS.fold evaluator (blk_map, blk_varmap) cfg1
253256

254257
(* Compare a label.t with tid comparisons only *)
255-
let compare_lbl_tid_only (graph Tid.t TidMap.t) (lbl1 : Label.t)
256-
(lbl2 : Label.t) : bool=
258+
let compare_lbl_tid_only (graph : Tid.t TidMap.t) (lbl1 : Label.t)
259+
(lbl2 : Label.t) : bool =
257260
match lbl1, lbl2 with
258261
| Direct tid1, Direct tid2 ->
259262
let tid_mapped = TidMap.find_exn graph tid1 in
@@ -263,7 +266,7 @@ let compare_lbl_tid_only (graph Tid.t TidMap.t) (lbl1 : Label.t)
263266

264267

265268
(* Compare a jmp with tid comparisons only *)
266-
let compare_jmp_tid_only (graph Tid.t TidMap.t) (jmp1 : jmp_t) (jmp2 : jmp_t) =
269+
let compare_jmp_tid_only (graph : Tid.t TidMap.t) (jmp1 : jmp term) (jmp2 : jmp term) =
267270
match Jmp.kind jmp1, Jmp.kind jmp2 with
268271
| Goto label1, Goto label2 -> compare_lbl_tid_only graph label1 label2
269272
| Call call1, Call call2 ->
@@ -285,7 +288,7 @@ let compare_jmp_tid_only (graph Tid.t TidMap.t) (jmp1 : jmp_t) (jmp2 : jmp_t) =
285288

286289
(* Check that the two blocks has matching TIDs in jumps. *)
287290
let compare_blk_tid_only (graph : Tid.t TidMap.t)
288-
(blk1 : blk term) (blk2 : blk term) bool =
291+
(blk1 : blk term) (blk2 : blk term) : bool =
289292
let jmps1 = Term.enum jmp_t blk1 |> Sequence.to_list in
290293
let jmps2 = Term.enum jmp_t blk2 |> Sequence.to_list in
291294
match List.zip jmps1 jmps2 with

wp/plugin/tests/test_wp.ml

+4
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ let suite = [
289289
"Debruijn: 16 bit" >: test_plugin "debruijn" unsat ~script:"run_wp_16bit.sh";
290290
"Debruijn: 32 bit" >: test_plugin "debruijn" unsat ~script:"run_wp_32bit.sh";
291291

292+
"Syntactic Equality: unequal" >: test_plugin "syntax_equality" sat ~script:"run_wp_sat.sh";
293+
"Syntactic Equality: equal 1" >: test_plugin "syntax_equality" unsat ~script:"run_wp_unsat_1.sh";
294+
"Syntactic Equality: equal 2" >: test_plugin "syntax_equality" unsat ~script:"run_wp_unsat_2.sh";
295+
292296
"NQueens solver 4x4" >: test_plugin "nqueens" sat
293297
~expected_regs:[[("RDI", "0x0000000000002814")]; [("RDI", "0x0000000000004182")]];
294298

wp/resources/sample_binaries/syntax_equality/main_1.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
int deref(int *num_1) {
22
int num_2 = 12;
3-
int num_3 = 122;
43
if(*num_1 > num_2){
5-
return -1;
4+
return -2;
65
}
76
return 0;
87
}

wp/resources/sample_binaries/syntax_equality/main_2.c

-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
int yeet(int *num_1) {
2-
int num_2 = 12;
3-
int num_4 = 12;
4-
if(*num_1 > num_2){
5-
return -1;
6-
}
7-
return 0;
8-
}
9-
101
int deref(int *num_1) {
112
int num_2 = 12;
12-
int num_4 = 122;
133
if(*num_1 > num_2){
144
return -1;
155
}

wp/resources/sample_binaries/syntax_equality/run_wp.sh

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This tests that main_1 and main_2 are not syntactically equal to each other
2+
3+
# Should return SAT
4+
5+
set -x
6+
7+
run_unsat () {
8+
bap wp \
9+
--func=deref \
10+
--num-unroll=0 \
11+
--no-byteweight \
12+
--mem-offset \
13+
--syntax-equality \
14+
--compare-post-reg-values=R12,R13,R14,R15,RBX,RSP,RBP,RAX \
15+
-- main_1 main_2
16+
}
17+
18+
run_unsat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This tests that main_2 is syntactically equal to itself
2+
3+
# Should return UNSAT
4+
5+
set -x
6+
7+
run_unsat () {
8+
bap wp \
9+
--func=deref \
10+
--num-unroll=0 \
11+
--no-byteweight \
12+
--mem-offset \
13+
--syntax-equality \
14+
-- main_1 main_1
15+
}
16+
17+
run_unsat
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This tests that main_2 is syntactically equal to itself
2+
3+
# Should return UNSAT
4+
5+
set -x
6+
7+
run_unsat () {
8+
bap wp \
9+
--func=deref \
10+
--num-unroll=0 \
11+
--no-byteweight \
12+
--mem-offset \
13+
--syntax-equality \
14+
-- main_2 main_2
15+
}
16+
17+
run_unsat

0 commit comments

Comments
 (0)