summaryrefslogtreecommitdiff
path: root/test/Bindings
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2013-11-03 08:27:32 +0000
committerPeter Zotov <whitequark@whitequark.org>2013-11-03 08:27:32 +0000
commit9d33bf70c228a5c3b57b1d9bf86ea5949bb77293 (patch)
tree278997c0f0f345f1676962b7687ea53a7b88fc05 /test/Bindings
parent1185582dfd542883194d262c5bf92b16e1e037c2 (diff)
downloadllvm-9d33bf70c228a5c3b57b1d9bf86ea5949bb77293.tar.gz
llvm-9d33bf70c228a5c3b57b1d9bf86ea5949bb77293.tar.bz2
llvm-9d33bf70c228a5c3b57b1d9bf86ea5949bb77293.tar.xz
[OCaml] Implement Llvm_linker, bindings for the IR linker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193951 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Bindings')
-rw-r--r--test/Bindings/Ocaml/linker.ml63
1 files changed, 63 insertions, 0 deletions
diff --git a/test/Bindings/Ocaml/linker.ml b/test/Bindings/Ocaml/linker.ml
new file mode 100644
index 0000000000..9359ae9f2c
--- /dev/null
+++ b/test/Bindings/Ocaml/linker.ml
@@ -0,0 +1,63 @@
+(* RUN: rm -rf %t.builddir
+ * RUN: mkdir -p %t.builddir
+ * RUN: cp %s %t.builddir
+ * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_linker.cmxa %t.builddir/linker.ml -o %t
+ * RUN: %t
+ * XFAIL: vg_leak
+ *)
+
+(* Note: It takes several seconds for ocamlopt to link an executable with
+ libLLVMCore.a, so it's better to write a big test than a bunch of
+ little ones. *)
+
+open Llvm
+open Llvm_linker
+
+let context = global_context ()
+let void_type = Llvm.void_type context
+
+(* Tiny unit test framework - really just to help find which line is busted *)
+let print_checkpoints = false
+
+let suite name f =
+ if print_checkpoints then
+ prerr_endline (name ^ ":");
+ f ()
+
+
+(*===-- Linker -----------------------------------------------------------===*)
+
+let test_linker () =
+ let fty = function_type void_type [| |] in
+
+ let make_module name =
+ let m = create_module context name in
+ let fn = define_function ("fn_" ^ name) fty m in
+ ignore (build_ret_void (builder_at_end context (entry_block fn)));
+ m
+ in
+
+ let m1 = make_module "one"
+ and m2 = make_module "two" in
+ link_modules m1 m2 Mode.PreserveSource;
+ dispose_module m1;
+ dispose_module m2;
+
+ let m1 = make_module "one"
+ and m2 = make_module "two" in
+ link_modules m1 m2 Mode.DestroySource;
+ dispose_module m1;
+
+ let m1 = make_module "one"
+ and m2 = make_module "one" in
+ try
+ link_modules m1 m2 Mode.PreserveSource;
+ failwith "must raise"
+ with Error _ ->
+ dispose_module m1;
+ dispose_module m2
+
+(*===-- Driver ------------------------------------------------------------===*)
+
+let _ =
+ suite "linker" test_linker