Customize tests output via InferPrint's command-line

Summary:
All intermediate `.exp` files used for tests can be generated with custom info, based on what is needed for the tests purposes.
This customisation happens via command-line argument `--issues-fields`.

Reviewed By: cristianoc, jvillard

Differential Revision: D4628062

fbshipit-source-id: feaa382
master
Martino Luca 8 years ago committed by Facebook Github Bot
parent fbaa1988b3
commit 3eecb243e6

@ -511,26 +511,48 @@ let module IssuesJson = {
};
};
let pp_tests_of_report fmt report => {
open Jsonbug_t;
let pp_trace_elem fmt {description} => F.fprintf fmt "%s" description;
let pp_trace fmt trace =>
if Config.print_traces_in_tests {
let pp_custom_of_report fmt report fields => {
let pp_custom_of_issue fmt issue => {
open Jsonbug_t;
let comma_separator index =>
if (index > 0) {
", "
} else {
""
};
let pp_trace fmt trace comma => {
let pp_trace_elem fmt {description} => F.fprintf fmt "%s" description;
let trace_without_empty_descs =
List.filter f::(fun {description} => description != "") trace;
F.fprintf fmt ", [%a]" (Pp.comma_seq pp_trace_elem) trace_without_empty_descs
F.fprintf fmt "%s[%a]" comma (Pp.comma_seq pp_trace_elem) trace_without_empty_descs
};
let pp_row jsonbug =>
F.fprintf
fmt
"%s, %s, %d, %s%a@."
jsonbug.file
jsonbug.procedure
(jsonbug.line - jsonbug.procedure_start_line)
jsonbug.bug_type
pp_trace
jsonbug.bug_trace;
List.iter f::pp_row report
let pp_field index field =>
switch field {
| `Issue_field_bug_class => Format.fprintf fmt "%s%s" (comma_separator index) issue.bug_class
| `Issue_field_kind => Format.fprintf fmt "%s%s" (comma_separator index) issue.kind
| `Issue_field_bug_type => Format.fprintf fmt "%s%s" (comma_separator index) issue.bug_type
| `Issue_field_qualifier => Format.fprintf fmt "%s%s" (comma_separator index) issue.qualifier
| `Issue_field_severity => Format.fprintf fmt "%s%s" (comma_separator index) issue.severity
| `Issue_field_visibility =>
Format.fprintf fmt "%s%s" (comma_separator index) issue.visibility
| `Issue_field_line => Format.fprintf fmt "%s%d" (comma_separator index) issue.line
| `Issue_field_column => Format.fprintf fmt "%s%d" (comma_separator index) issue.column
| `Issue_field_procedure => Format.fprintf fmt "%s%s" (comma_separator index) issue.procedure
| `Issue_field_procedure_id =>
Format.fprintf fmt "%s%s" (comma_separator index) issue.procedure_id
| `Issue_field_procedure_start_line =>
Format.fprintf fmt "%s%d" (comma_separator index) issue.procedure_start_line
| `Issue_field_file => Format.fprintf fmt "%s%s" (comma_separator index) issue.file
| `Issue_field_bug_trace => pp_trace fmt issue.bug_trace (comma_separator index)
| `Issue_field_key => Format.fprintf fmt "%s%d" (comma_separator index) issue.key
| `Issue_field_hash => Format.fprintf fmt "%s%d" (comma_separator index) issue.hash
| `Issue_field_line_offset =>
Format.fprintf fmt "%s%d" (comma_separator index) (issue.line - issue.procedure_start_line)
};
List.iteri f::pp_field fields;
Format.fprintf fmt "@."
};
List.iter f::(pp_custom_of_issue fmt) report
};
let tests_jsonbug_compare bug1 bug2 =>
@ -1091,7 +1113,7 @@ let pp_json_report_by_report_kind formats_by_report_kind fname =>
let pp_json_issues format_list report => {
let pp_json_issue (format_kind, outf: Utils.outfile) =>
switch format_kind {
| Tests => pp_tests_of_report outf.fmt report
| Tests => pp_custom_of_report outf.fmt report Config.issues_fields
| Text => pp_text_of_report outf.fmt report
| Json => failwith "Printing issues from json does not support json output"
| Csv => failwith "Printing issues from json does not support csv output"

@ -75,6 +75,24 @@ let ml_bucket_symbols = [
("unknown_origin", `MLeak_unknown);
]
let issues_fields_symbols = [
("bug_class", `Issue_field_bug_class);
("kind", `Issue_field_kind);
("bug_type", `Issue_field_bug_type);
("qualifier", `Issue_field_qualifier);
("severity", `Issue_field_severity);
("visibility", `Issue_field_visibility);
("line", `Issue_field_line);
("column", `Issue_field_column);
("procedure", `Issue_field_procedure);
("procedure_id", `Issue_field_procedure_id);
("procedure_start_line", `Issue_field_procedure_start_line);
("file", `Issue_field_file);
("bug_trace", `Issue_field_bug_trace);
("key", `Issue_field_key);
("hash", `Issue_field_hash);
("line_offset", `Issue_field_line_offset);
]
type os_type = Unix | Win32 | Cygwin
@ -929,6 +947,19 @@ and iphoneos_target_sdk_version =
CLOpt.mk_string_opt ~long:"iphoneos-target-sdk-version" ~parse_mode:CLOpt.(Infer [Clang])
"Specify the target SDK version to use for iphoneos"
and issues_fields =
CLOpt.mk_symbol_seq ~long:"issues-fields"
~parse_mode:CLOpt.(Infer [Print])
~default:[
`Issue_field_file;
`Issue_field_procedure;
`Issue_field_line_offset;
`Issue_field_bug_type;
`Issue_field_bug_trace;
]
~symbols:issues_fields_symbols ~eq:PVariant.(=)
"Fields to emit with --issues-tests"
and iterations =
CLOpt.mk_int ~deprecated:["iterations"] ~long:"iterations" ~default:1
~meta:"int"
@ -1062,11 +1093,6 @@ and print_builtins =
CLOpt.mk_bool ~deprecated:["print_builtins"] ~long:"print-builtins"
"Print the builtin functions and exit"
and print_traces_in_tests =
CLOpt.mk_bool ~long:"print-traces-in-tests" ~default:true
~parse_mode:CLOpt.(Infer [Print])
"Include symbolic traces summaries in the output of --issues-tests"
and print_using_diff =
CLOpt.mk_bool ~deprecated_no:["noprintdiff"] ~long:"print-using-diff" ~default:true
"Highlight the difference w.r.t. the previous prop when printing symbolic execution debug info"
@ -1528,6 +1554,7 @@ and headers = !headers
and icfg_dotty_outfile = !icfg_dotty_outfile
and infer_cache = !infer_cache
and iphoneos_target_sdk_version = !iphoneos_target_sdk_version
and issues_fields = !issues_fields
and iterations = !iterations
and java_jar_compiler = !java_jar_compiler
and javac_classes_out = !javac_classes_out
@ -1560,7 +1587,6 @@ and pmd_xml = !pmd_xml
and precondition_stats = !precondition_stats
and print_logs = !print_logs
and print_builtins = !print_builtins
and print_traces_in_tests = !print_traces_in_tests
and print_types = !print_types
and print_using_diff = !print_using_diff
and procs_csv = !procs_csv

@ -40,6 +40,24 @@ val ml_bucket_symbols :
(string * [ `MLeak_all | `MLeak_arc | `MLeak_cf | `MLeak_cpp | `MLeak_no_arc | `MLeak_unknown ])
list
val issues_fields_symbols :
(string * [`Issue_field_bug_class
| `Issue_field_kind
| `Issue_field_bug_type
| `Issue_field_qualifier
| `Issue_field_severity
| `Issue_field_visibility
| `Issue_field_line
| `Issue_field_column
| `Issue_field_procedure
| `Issue_field_procedure_id
| `Issue_field_procedure_start_line
| `Issue_field_file
| `Issue_field_bug_trace
| `Issue_field_key
| `Issue_field_hash
| `Issue_field_line_offset]) list
type os_type = Unix | Win32 | Cygwin
@ -218,6 +236,22 @@ val headers : bool
val icfg_dotty_outfile : string option
val infer_cache : string option
val iphoneos_target_sdk_version : string option
val issues_fields : [`Issue_field_bug_class
| `Issue_field_kind
| `Issue_field_bug_type
| `Issue_field_qualifier
| `Issue_field_severity
| `Issue_field_visibility
| `Issue_field_line
| `Issue_field_column
| `Issue_field_procedure
| `Issue_field_procedure_id
| `Issue_field_procedure_start_line
| `Issue_field_file
| `Issue_field_bug_trace
| `Issue_field_key
| `Issue_field_hash
| `Issue_field_line_offset] list
val iterations : int
val java_jar_compiler : string option
val javac_classes_out : string
@ -245,7 +279,6 @@ val pmd_xml : bool
val precondition_stats : bool
val print_logs : bool
val print_builtins : bool
val print_traces_in_tests : bool
val print_types : bool
val print_using_diff : bool
val procs_csv : string option

@ -12,7 +12,7 @@ CLANG_OPTIONS = -c
INFER_OPTIONS = --report-custom-error --developer-mode --no-filtering --debug-exceptions --project-root $(TESTS_DIR)
# we need to disable traces in C tests because assertions/assertion_failure.c has different traces
# on Linux and OSX because of different implementations of assert() on each platform
INFERPRINT_OPTIONS = --no-print-traces-in-tests --issues-tests
INFERPRINT_OPTIONS = --issues-fields "file,procedure,line_offset,bug_type" --issues-tests
SOURCES = \
$(wildcard */*.c) \

@ -9,7 +9,7 @@ TESTS_DIR = ../../..
ANALYZER = infer
INFER_OPTIONS = --android-harness --no-filtering --debug-exceptions
INFERPRINT_OPTIONS = --no-print-traces-in-tests --issues-tests
INFERPRINT_OPTIONS = --issues-fields "file,procedure,line_offset,bug_type" --issues-tests
SOURCES = \
BasicHarnessActivity.java \

Loading…
Cancel
Save