]> matita.cs.unibo.it Git - helm.git/blobdiff - 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
index 7768b6f455c40c20b823d66195791ab6c9ec6811..635b6bbd4d40533834b15d03ca789e28740bc32d 100644 (file)
@@ -23,7 +23,8 @@
  * http://helm.cs.unibo.it/
  *)
 
-let trust = false
+let trust = true
+let deadline = 30
 let conffile = "../../../matita/matita.conf.xml"
 
 let _ = CicEnvironment.set_trust (fun _ -> trust);;
@@ -46,6 +47,15 @@ let _ =
      Printf.printf "Old: %.2f (%.2f%%)\n" !old_total (perc !new_total !old_total))
 ;;
 
+let timeout = ref false;;
+
+let _ =
+ Sys.set_signal 14 (* SIGALRM *)
+  (Sys.Signal_handle (fun _ ->
+    timeout := true;
+    raise Sys.Break))
+;;
+
 let urifname =
   try
     Sys.argv.(1)
@@ -55,6 +65,8 @@ let urifname =
 
 let ic = open_in urifname
 
+exception Done;;
+
 let _ =
   try
     while true do
@@ -64,13 +76,26 @@ let _ =
         let uri,res,time =
          match Str.split (Str.regexp " ") uri with
             uri::res::time::_ -> uri, Some res, Some (float_of_string time)
+          | [uri;res] -> uri, Some res, None
           | [ uri ] -> uri, None, None
           | _ -> assert false
         in
         Printf.printf "%s " uri;
+        flush stdout;
         let uri = UriManager.uri_of_string uri in
         let before = Unix.gettimeofday () in
+        ignore (Unix.alarm deadline);
         ignore (CicTypeChecker.typecheck uri);
+        ignore (Unix.alarm 0);
+        let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
+        if memusage > 500 then
+         begin
+          prerr_endline ("MEMORIA ALLOCATA: " ^ string_of_int memusage ^ "Mb");
+          CicEnvironment.empty ();
+          Gc.compact ();
+          let memusage = (Gc.stat ()).Gc.live_words * 4 / 1024 / 1024 in
+            prerr_endline ("DOPO CicEnvironment.empty: " ^ string_of_int memusage ^ "Mb");
+         end;
         let after = Unix.gettimeofday () in
         let diff = after -. before in
         new_total := !new_total +. diff;
@@ -83,18 +108,41 @@ let _ =
       with
         | End_of_file as exn -> raise exn
         | Sys.Break ->
-           Printf.printf "\e[0;31mSKIPPED\e[0m\n";
-           flush stdout;
-           Printf.eprintf "\e[0;31mContinue with next URI? [y/_]\e[0m";
-           flush stderr;
-           (match input_line stdin with
-               "y" -> ()
-             | _ -> raise Sys.Break)
+           let rec skip_break prompt =
+            try
+             if prompt then
+              begin
+               Printf.printf "\e[0;31mSKIPPED\e[0m\n";
+               flush stdout;
+               if not !timeout then
+                begin
+                 Printf.eprintf "\e[0;31mContinue with next URI? [y/_]\e[0m";
+                 flush stderr;
+                end;
+              end;
+             if not !timeout then
+              (match input_line stdin with
+                  "y" -> ()
+                | _ -> raise Done)
+             else
+              timeout := false
+            with
+             Sys.Break -> skip_break false
+           in
+            skip_break true
+        | CicEnvironment.CircularDependency _ ->
+           Printf.printf "\e[0;31mCIRCULARDEP\e[0m\n"
         | exn ->
            Printf.printf "\e[0;31mFAIL\e[0m\n";
            flush stdout;
-           prerr_endline (Printexc.to_string exn)
+           prerr_endline
+            (match exn with
+                CicTypeChecker.TypeCheckerFailure msg ->
+                 "TypeCheckerFailure: " ^ Lazy.force msg
+              | CicTypeChecker.AssertFailure msg ->
+                 "TypeCheckerAssertion: " ^ Lazy.force msg
+              | _ -> Printexc.to_string exn)
     done
   with
      End_of_file
-   | Sys.Break -> ()
+   | Done -> ()