Skip to content

Instantly share code, notes, and snippets.

@rvantonder
Created November 25, 2014 15:47
Show Gist options
  • Save rvantonder/57ba69365a6d4d1653c7 to your computer and use it in GitHub Desktop.
Save rvantonder/57ba69365a6d4d1653c7 to your computer and use it in GitHub Desktop.
diff --git a/lib_test/bap_image/test_image.ml b/lib_test/bap_image/test_image.ml
index 665b48c..f69914b 100644
--- a/lib_test/bap_image/test_image.ml
+++ b/lib_test/bap_image/test_image.ml
@@ -136,6 +136,29 @@ let assert_cont ~word_size img =
(a1 <> a2 ==> Addr.is_zero diff) in
a2) |> return
+let empty_table = Bap_table.empty
+
+let create_mem ?(addr_size=W32) ?(start_addr=0x00) ?(size=0x08) () =
+ let addr = create_addr W32 start_addr in
+ let contents = Bigstring.init size ~f:(fun i -> char_of_int (i+0x61)) in
+ ok_exn (Bap_memory.create LittleEndian addr contents)
+
+let table =
+ let mem = create_mem () in
+ ok_exn (Bap_table.add empty_table mem "Memory Tag")
+
+let test_table_len ctxt =
+ assert_equal 0 (Bap_table.length empty_table)
+
+let test_table_len2 ctxt =
+ assert_equal 1 (Bap_table.length table)
+
+let test_find ctxt =
+ let mem_to_find = create_mem () in
+ Bap_table.find table mem_to_find |> function
+ | Some x -> assert_equal "Memory Tag" x
+ | _ -> assert_failure "Wrong"
+
let suite = "Image" >::: [
"to_list:0-15/bytes_32LE" >:: to_list ~word_size:`r8 "0-15_32LE"
~expect:(List.init 16 ~f:ident);
@@ -266,4 +289,8 @@ let suite = "Image" >::: [
let printer = Addr.to_string in
assert_equal ~printer Addr.(mn ++ 0x336) mx;
return ());
+
+ "table_length" >:: test_table_len;
+ "table_length2" >:: test_table_len2;
+ "test_find" >:: test_find;
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment