diff options
author | Stephen Hines <srhines@google.com> | 2014-12-01 14:51:49 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-12-02 16:08:10 -0800 |
commit | 37ed9c199ca639565f6ce88105f9e39e898d82d0 (patch) | |
tree | 8fb36d3910e3ee4c4e1b7422f4f017108efc52f5 /test/Bindings/OCaml/bitwriter.ml | |
parent | d2327b22152ced7bc46dc629fc908959e8a52d03 (diff) | |
download | external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.zip external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.gz external_llvm-37ed9c199ca639565f6ce88105f9e39e898d82d0.tar.bz2 |
Update aosp/master LLVM for rebase to r222494.
Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
Diffstat (limited to 'test/Bindings/OCaml/bitwriter.ml')
-rw-r--r-- | test/Bindings/OCaml/bitwriter.ml | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/Bindings/OCaml/bitwriter.ml b/test/Bindings/OCaml/bitwriter.ml new file mode 100644 index 0000000..7c803f6 --- /dev/null +++ b/test/Bindings/OCaml/bitwriter.ml @@ -0,0 +1,49 @@ +(* RUN: cp %s %T/bitwriter.ml + * RUN: %ocamlc -g -w -3 -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t + * RUN: %t %t.bc + * RUN: %ocamlopt -g -w -3 -warn-error A -package llvm.bitreader -package llvm.bitwriter -linkpkg %T/bitwriter.ml -o %t + * RUN: %t %t.bc + * RUN: llvm-dis < %t.bc + * XFAIL: vg_leak + *) + +(* Note that this takes a moment to link, so it's best to keep the number of + individual tests low. *) + +let context = Llvm.global_context () + +let test x = if not x then exit 1 else () + +let read_file name = + let ic = open_in_bin name in + let len = in_channel_length ic in + let buf = String.create len in + + test ((input ic buf 0 len) = len); + + close_in ic; + + buf + +let temp_bitcode ?unbuffered m = + let temp_name, temp_oc = Filename.open_temp_file ~mode:[Open_binary] "" "" in + + test (Llvm_bitwriter.output_bitcode ?unbuffered temp_oc m); + flush temp_oc; + + let temp_buf = read_file temp_name in + + close_out temp_oc; + + temp_buf + +let _ = + let m = Llvm.create_module context "ocaml_test_module" in + + test (Llvm_bitwriter.write_bitcode_file m Sys.argv.(1)); + let file_buf = read_file Sys.argv.(1) in + + test (file_buf = temp_bitcode m); + test (file_buf = temp_bitcode ~unbuffered:false m); + test (file_buf = temp_bitcode ~unbuffered:true m); + test (file_buf = Llvm.MemoryBuffer.as_string (Llvm_bitwriter.write_bitcode_to_memory_buffer m)) |