(*
- * Copyright 2010, INRIA, University of Copenhagen
+ * Copyright 2012, INRIA
+ * Julia Lawall, Gilles Muller
+ * Copyright 2010-2011, INRIA, University of Copenhagen
* Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
* Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
* Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
*)
+# 0 "./testing.ml"
open Common
-open Sexplib
(*****************************************************************************)
(* Test framework *)
| Some (Some outfile) ->
if List.length res > 1
then pr2 ("note that not just " ^ cfile ^ " was involved");
-
- let tmpfile = "/tmp/"^Common.basename cfile in
+ let tmpfile = sprintf "%s/%s" Filename.temp_dir_name (Common.basename cfile) in
pr2 (sprintf "One file modified. Result is here: %s" tmpfile);
Common.command2 ("mv "^outfile^" "^tmpfile);
tmpfile
| Some None ->
pr2 "no modification on the input file";
cfile
- | None -> raise Impossible
+ | None -> raise (Impossible 163)
in
if compare_with_expected_flag
then
* (via -testall). Fortunately such bugs are rare.
*
*)
-let testall ?(expected_score_file="tests/SCORE_expected.sexp") () =
+let testall expected_score_file update_score_file =
let score = empty_score () in
begin
expected_result_files +> List.iter (fun res ->
let x =
- if res =~ "\\(.*\\).res" then matched1 res else raise Impossible in
+ if res =~ "\\(.*\\).res" then matched1 res else raise (Impossible 164) in
let base = if x =~ "\\(.*\\)_ver[0-9]+" then matched1 x else x in
let cfile = "tests/" ^ x ^ ".c" in
let cocci_file = "tests/" ^ base ^ ".cocci" in
let expected = "tests/" ^ res in
- let timeout_testall = 30 in
+ let timeout_testall = 60 in
try (
Common.timeout_function timeout_testall (fun () ->
pr2 "regression testing information";
pr2 "--------------------------------";
- (* now default argument of testall:
- let expected_score_file = "tests/SCORE_expected.sexp" in
- *)
let expected_score_file_orig = "tests/SCORE_expected_orig.sexp" in
let best_of_both_file = "tests/SCORE_best_of_both.sexp" in
let actual_score_file = "tests/SCORE_actual.sexp" in
let (expected_score : score) =
if Sys.file_exists expected_score_file
then
+ Common.load_score expected_score_file ()
+ (*
let sexp = Sexp.load_sexp expected_score_file in
Sexp_common.score_of_sexp sexp
+ *)
else
if Sys.file_exists expected_score_file_orig
then begin
pr2 (spf "use expected orig file (%s)" expected_score_file_orig);
Common.command2 (spf "cp %s %s" expected_score_file_orig
expected_score_file);
- let sexp = Sexp.load_sexp expected_score_file in
+ (*
+ let sexp = Sexp.load_sexp expected_score_file in
Sexp_common.score_of_sexp sexp
+ *)
+ Common.load_score expected_score_file ()
end
else
empty_score()
let new_bestscore = Common.regression_testing_vs score expected_score in
-
+ (*
let xs = Common.hash_to_list score in
let sexp = Sexp_common.sexp_of_score_list xs in
let s_score = Sexp.to_string_hum sexp in
Common.write_file ~file:(actual_score_file) s_score;
+ *)
+ Common.save_score score actual_score_file;
+ (*
let xs2 = Common.hash_to_list new_bestscore in
let sexp2 = Sexp_common.sexp_of_score_list xs2 in
let s_score2 = Sexp.to_string_hum sexp2 in
Common.write_file ~file:(best_of_both_file) s_score2;
+ *)
+ Common.save_score new_bestscore best_of_both_file;
Common.print_total_score score;
else begin
pr2 "Current score is greater than expected :)";
pr2 (spf "(was expecting %d but got %d)" expected_good good);
- pr2 "Generating new expected score file and saving old one";
- Common.command2_y_or_no_exit_if_no
- (spf "mv %s %s" expected_score_file (expected_score_file ^ ".save"));
- Common.command2_y_or_no_exit_if_no
- (spf "mv %s %s" best_of_both_file expected_score_file);
+ if update_score_file then
+ begin
+ pr2 "Generating new expected score file and saving old one";
+ Common.command2_y_or_no_exit_if_no
+ (spf "mv %s %s" expected_score_file (expected_score_file ^ ".save"));
+ Common.command2_y_or_no_exit_if_no
+ (spf "mv %s %s" best_of_both_file expected_score_file);
+ end;
+
+ (* when there are sufficient number of tests, abort if a substantial
+ * amount of tests fail, which would indicate a broken build.
+ *)
+ if total > 40 && good < (total * 3) / 4
+ then begin
+ pr2 "Still, less 75% the tests passed. Returning a nonzero exist status.";
+ raise (UnixExit 1);
+ end;
+
raise (UnixExit 0);
end
let delete_previous_result_files infile =
[Ok;SpatchOK;Failed] +> List.iter (fun kind ->
- Common.command2 ("rm -f " ^ infile ^ t_to_s kind)
+ Common.remove_file (infile ^ t_to_s kind)
)
(* quite similar to compare_with_expected below *)
let newscore = Common.empty_score () in
let oks =
- Common.cmd_to_list ("find -name \"*.ok\"")
+ Common.cmd_to_list ("find . -name \"*.ok\"")
++
- Common.cmd_to_list ("find -name \"*.spatch_ok\"")
+ Common.cmd_to_list ("find . -name \"*.spatch_ok\"")
in
- let failed = Common.cmd_to_list ("find -name \"*.failed\"") in
+ let failed = Common.cmd_to_list ("find . -name \"*.failed\"") in
if null (oks ++ failed)
then failwith "no ok/failed file, you certainly did a make clean"
(*****************************************************************************)
let test_parse_cocci file =
- Flag_parsing_cocci.show_SP := true;
if not (file =~ ".*\\.cocci")
then pr2 "warning: seems not a .cocci file";
(if !Flag.scanner = Flag.Glimpse then "glimpse" else "google");
(match query with
None -> pr "No query"
- | Some x -> pr (String.concat " ||\n" x))
+ | Some x -> pr (String.concat "\nor on glimpse failure\n" x))