Add poc files

This commit is contained in:
Joey Yakimowich-Payne 2018-05-26 10:55:38 +09:00
commit fa600b98f7
220 changed files with 45679 additions and 0 deletions

View file

@ -0,0 +1,127 @@
(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)
open Common
(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)
(*
* Thin layer generator wrapper around the Coverage_tests_php.lines_coverage
* data, which itself is generated by running many unit tests with a
* tracer, xdebug or hphpi-tracer, on.
*
* We generate either a layer with red/green colors or one with
* heat-based colors for finer-grained visualization.
*)
(*****************************************************************************)
(* Types *)
(*****************************************************************************)
(*****************************************************************************)
(* Helper *)
(*****************************************************************************)
(*****************************************************************************)
(* Main entry point *)
(*****************************************************************************)
let gen_red_green_layer lines_coverage =
{ Layer_code.
title = "Test coverage (red/green)";
description = "Use information from xdebug";
files = lines_coverage +> List.map (fun (file, lines_cover) ->
let covered = lines_cover.Coverage_code.covered_sites in
let all = lines_cover.Coverage_code.all_sites in
let not_covered = Common2.minus_set all covered in
let percent =
try
Common2.pourcent_good_bad
(List.length covered) (List.length not_covered)
with Division_by_zero -> 0
in
file,
{ Layer_code.
micro_level =
(covered +> List.map (fun line -> line, "ok")) @
(not_covered +> List.map (fun line -> line, "bad"))
;
macro_level = [
(match percent with
| 0 -> "no_info"
| n when n < 50 -> "bad"
| _ -> "ok"
),
1.
];
}
);
kinds = Layer_code.red_green_properties;
}
(* mostly a copy paste of gen_red_green_layer *)
let gen_heatmap_layer lines_coverage =
{ Layer_code.
title = "Test coverage (heatmap)";
description = "Use information from xdebug";
files = lines_coverage +> List.map (fun (file, lines_cover) ->
let covered = lines_cover.Coverage_code.covered_sites in
let all = lines_cover.Coverage_code.all_sites in
let not_covered = Common2.minus_set all covered in
let percent =
try
Common2.pourcent_good_bad
(List.length covered) (List.length not_covered)
with Division_by_zero -> 0
in
file,
{ Layer_code.
micro_level =
(covered +> List.map (fun line -> line, "ok")) @
(not_covered +> List.map (fun line -> line, "bad"))
;
macro_level = [
(let percent_round = (percent / 10) * 10 in
spf "cover %d%%" percent_round
),
1.
];
}
);
kinds = Layer_code.heat_map_properties;
}
(*****************************************************************************)
(* Actions *)
(*****************************************************************************)
let actions () = [
"-gen_red_green_coverage_layer", " <json> <output>",
Common.mk_action_2_arg (fun jsonfile output ->
let cover = Coverage_code.load_lines_coverage jsonfile in
let layer = gen_red_green_layer cover in
Layer_code.save_layer layer output
);
"-gen_heatmap_coverage_layer", " <json> <output>",
Common.mk_action_2_arg (fun jsonfile output ->
let cover = Coverage_code.load_lines_coverage jsonfile in
let layer = gen_heatmap_layer cover in
Layer_code.save_layer layer output
);
]