1 (* RUN: rm -rf %t.builddir 2 * RUN: mkdir -p %t.builddir 3 * RUN: cp %s %t.builddir 4 * RUN: %ocamlopt -warn-error A llvm.cmxa llvm_linker.cmxa %t.builddir/linker.ml -o %t 5 * RUN: %t 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 13 open Llvm 14 open Llvm_linker 15 16 let context = global_context () 17 let void_type = Llvm.void_type context 18 19 (* Tiny unit test framework - really just to help find which line is busted *) 20 let print_checkpoints = false 21 22 let suite name f = 23 if print_checkpoints then 24 prerr_endline (name ^ ":"); 25 f () 26 27 28 (*===-- Linker -----------------------------------------------------------===*) 29 30 let test_linker () = 31 let fty = function_type void_type [| |] in 32 33 let make_module name = 34 let m = create_module context name in 35 let fn = define_function ("fn_" ^ name) fty m in 36 ignore (build_ret_void (builder_at_end context (entry_block fn))); 37 m 38 in 39 40 let m1 = make_module "one" 41 and m2 = make_module "two" in 42 link_modules m1 m2 Mode.PreserveSource; 43 dispose_module m1; 44 dispose_module m2; 45 46 let m1 = make_module "one" 47 and m2 = make_module "two" in 48 link_modules m1 m2 Mode.DestroySource; 49 dispose_module m1; 50 51 let m1 = make_module "one" 52 and m2 = make_module "one" in 53 try 54 link_modules m1 m2 Mode.PreserveSource; 55 failwith "must raise" 56 with Error _ -> 57 dispose_module m1; 58 dispose_module m2 59 60 (*===-- Driver ------------------------------------------------------------===*) 61 62 let _ = 63 suite "linker" test_linker 64