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