]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/binaries/utilities/test_library.ml
CicEnvironment is emptied when a size treshold is reached.
[helm.git] / helm / software / components / binaries / utilities / test_library.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 let trust = true
27 let deadline = 30
28 let conffile = "../../../matita/matita.conf.xml"
29
30 let _ = CicEnvironment.set_trust (fun _ -> trust);;
31 let _ = Helm_registry.load_from conffile;;
32
33 let old_total = ref 0.0
34 let new_total = ref 0.0
35
36 let separator = "=============" 
37
38 let perc newt oldt = (newt -. oldt) /. oldt *. 100.0
39
40 let _ =
41  Sys.catch_break true;
42  at_exit
43   (fun () ->
44     Printf.printf "%s\n" separator;
45     Printf.printf "Total: %.2f\n" !new_total;
46     if !old_total <> 0.0 then
47      Printf.printf "Old: %.2f (%.2f%%)\n" !old_total (perc !new_total !old_total))
48 ;;
49
50 let timeout = ref false;;
51
52 let _ =
53  Sys.set_signal 14 (* SIGALRM *)
54   (Sys.Signal_handle (fun _ ->
55     timeout := true;
56     raise Sys.Break))
57 ;;
58
59 let urifname =
60   try
61     Sys.argv.(1)
62   with Invalid_argument _ ->
63    prerr_endline "You must supply a file with the list of URIs to check";
64    exit (-1)
65
66 let ic = open_in urifname
67
68 exception Done;;
69
70 let _ =
71   try
72     while true do
73       try
74         let uri = input_line ic in
75         if uri = separator then raise End_of_file;
76         let uri,res,time =
77          match Str.split (Str.regexp " ") uri with
78             uri::res::time::_ -> uri, Some res, Some (float_of_string time)
79           | [uri;res] -> uri, Some res, None
80           | [ uri ] -> uri, None, None
81           | _ -> assert false
82         in
83         Printf.printf "%s " uri;
84         flush stdout;
85         let uri = UriManager.uri_of_string uri in
86         let before = Unix.gettimeofday () in
87         ignore (Unix.alarm deadline);
88         ignore (CicTypeChecker.typecheck uri);
89         ignore (Unix.alarm 0);
90         let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
91         if memusage > 500 then
92          begin
93           prerr_endline ("MEMORIA ALLOCATA: " ^ string_of_int memusage ^ "Mb");
94           CicEnvironment.empty ();
95           Gc.compact ();
96           let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
97             prerr_endline ("DOPO CicEnvironment.empty: " ^ string_of_int memusage ^ "Mb");
98          end;
99         let after = Unix.gettimeofday () in
100         let diff = after -. before in
101         new_total := !new_total +. diff;
102         Printf.printf "\e[0;32mOK\e[0m %.2f" diff;
103         (match time with
104            None -> Printf.printf "\n"
105          | Some time ->
106             old_total := !old_total +. time;
107              Printf.printf " %.2f%%\n" (perc diff time))
108       with
109         | End_of_file as exn -> raise exn
110         | Sys.Break ->
111            let rec skip_break prompt =
112             try
113              if prompt then
114               begin
115                Printf.printf "\e[0;31mSKIPPED\e[0m\n";
116                flush stdout;
117                if not !timeout then
118                 begin
119                  Printf.eprintf "\e[0;31mContinue with next URI? [y/_]\e[0m";
120                  flush stderr;
121                 end;
122               end;
123              if not !timeout then
124               (match input_line stdin with
125                   "y" -> ()
126                 | _ -> raise Done)
127              else
128               timeout := false
129             with
130              Sys.Break -> skip_break false
131            in
132             skip_break true
133         | CicEnvironment.CircularDependency _ ->
134            Printf.printf "\e[0;31mCIRCULARDEP\e[0m\n"
135         | exn ->
136            Printf.printf "\e[0;31mFAIL\e[0m\n";
137            flush stdout;
138            prerr_endline
139             (match exn with
140                 CicTypeChecker.TypeCheckerFailure msg ->
141                  "TypeCheckerFailure: " ^ Lazy.force msg
142               | CicTypeChecker.AssertFailure msg ->
143                  "TypeCheckerAssertion: " ^ Lazy.force msg
144               | _ -> Printexc.to_string exn)
145     done
146   with
147      End_of_file
148    | Done -> ()