X-Git-Url: http://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/3a31414346dd7d7e8baa4cb8b804a2d5e1797962..7f339edd551eefcd6c99f379ce91c27df997cfe3:/testing.ml diff --git a/testing.ml b/testing.ml index 0192b10..5856a06 100644 --- a/testing.ml +++ b/testing.ml @@ -1,5 +1,7 @@ (* - * 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 @@ -22,6 +24,7 @@ *) +# 0 "./testing.ml" open Common open Sexplib @@ -52,8 +55,7 @@ let testone prefix x compare_with_expected_flag = | 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 @@ -81,7 +83,7 @@ let testone prefix x compare_with_expected_flag = * (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 @@ -101,7 +103,7 @@ let testall ?(expected_score_file="tests/SCORE_expected.sexp") () = 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 () -> @@ -237,11 +239,24 @@ let testall ?(expected_score_file="tests/SCORE_expected.sexp") () = 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 @@ -259,7 +274,7 @@ let t_to_s = function 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 *) @@ -382,11 +397,11 @@ let test_regression_okfailed () = 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" @@ -483,7 +498,7 @@ let test_parse_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))