Fix the running of ocaml tests.
[oota-llvm.git] / test / Bindings / Ocaml / analysis.ml
1 (* RUN: %ocamlopt -warn-error A llvm.cmxa llvm_analysis.cmxa %s -o %t
2  * RUN: %t
3  *)
4
5 open Llvm
6 open Llvm_analysis
7
8 (* Note that this takes a moment to link, so it's best to keep the number of
9    individual tests low. *)
10
11 let context = global_context ()
12
13 let test x = if not x then exit 1 else ()
14
15 let bomb msg =
16   prerr_endline msg;
17   exit 2
18
19 let _ =
20   let fty = function_type (void_type context) [| |] in
21   let m = create_module context "valid_m" in
22   let fn = define_function "valid_fn" fty m in
23   let at_entry = builder_at_end context (entry_block fn) in
24   ignore (build_ret_void at_entry);
25   
26   
27   (* Test that valid constructs verify. *)
28   begin match verify_module m with
29     Some msg -> bomb "valid module failed verification!"
30   | None -> ()
31   end;
32   
33   if not (verify_function fn) then bomb "valid function failed verification!";
34   
35   
36   (* Test that invalid constructs do not verify.
37      A basic block can contain only one terminator instruction. *)
38   ignore (build_ret_void at_entry);
39   
40   begin match verify_module m with
41     Some msg -> ()
42   | None -> bomb "invalid module passed verification!"
43   end;
44   
45   if verify_function fn then bomb "invalid function passed verification!";
46   
47   
48   dispose_module m
49   
50   (* Don't bother to test assert_valid_{module,function}. *)