[OCaml] [autoconf] Migrate to ocamlfind.
[oota-llvm.git] / test / Bindings / Ocaml / linker.ml
1 (* RUN: cp %s %T/linker.ml
2  * RUN: %ocamlcomp -warn-error A -package llvm.linker -linkpkg %T/linker.ml -o %t
3  * RUN: %t
4  * XFAIL: vg_leak
5  *)
6
7 (* Note: It takes several seconds for ocamlopt to link an executable with
8          libLLVMCore.a, so it's better to write a big test than a bunch of
9          little ones. *)
10
11 open Llvm
12 open Llvm_linker
13
14 let context = global_context ()
15 let void_type = Llvm.void_type context
16
17 (* Tiny unit test framework - really just to help find which line is busted *)
18 let print_checkpoints = false
19
20 let suite name f =
21   if print_checkpoints then
22     prerr_endline (name ^ ":");
23   f ()
24
25
26 (*===-- Linker -----------------------------------------------------------===*)
27
28 let test_linker () =
29   let fty = function_type void_type [| |] in
30
31   let make_module name =
32     let m = create_module context name in
33     let fn = define_function ("fn_" ^ name) fty m in
34     ignore (build_ret_void (builder_at_end context (entry_block fn)));
35     m
36   in
37
38   let m1 = make_module "one"
39   and m2 = make_module "two" in
40   link_modules m1 m2 Mode.PreserveSource;
41   dispose_module m1;
42   dispose_module m2;
43
44   let m1 = make_module "one"
45   and m2 = make_module "two" in
46   link_modules m1 m2 Mode.DestroySource;
47   dispose_module m1;
48
49   let m1 = make_module "one"
50   and m2 = make_module "one" in
51   try
52     link_modules m1 m2 Mode.PreserveSource;
53     failwith "must raise"
54   with Error _ ->
55     dispose_module m1;
56     dispose_module m2
57
58 (*===-- Driver ------------------------------------------------------------===*)
59
60 let _ =
61   suite "linker" test_linker