[TD] Change JSON format for test-determinator

Reviewed By: mbouaziz

Differential Revision: D8806257

fbshipit-source-id: e1b5c65
master
Martino Luca 6 years ago committed by Facebook Github Bot
parent 06a04ca9f5
commit ae9ee41f78

@ -19,7 +19,7 @@ INFER_MAIN = infer
#### Checkers declarations ####
INFER_ATDGEN_STUB_BASES = atd/jsonbug atd/runstate atd/stacktree atd/java_method_decl atd/perf_profiler
INFER_ATDGEN_STUB_BASES = atd/jsonbug atd/runstate atd/stacktree atd/java_method_decl atd/perf_profiler atd/java_profiler_samples
INFER_ATDGEN_TYPES = j t
INFER_ATDGEN_STUB_ATDS = $(INFER_ATDGEN_STUB_BASES:.atd)
INFER_ATDGEN_SUFFIXES = $(foreach atd_t,$(INFER_ATDGEN_TYPES),_$(atd_t).ml _$(atd_t).mli)

@ -0,0 +1,12 @@
type sampled_method = {
classname <json name="class"> : string;
methodname <json name="method"> : string;
signature : string;
}
type java_profiler_sample = {
test : string;
methods : sampled_method list;
}
type java_profiler_samples = java_profiler_sample list

@ -284,41 +284,27 @@ type labeled_profiler_sample = string * ProfilerSample.t [@@deriving compare]
let equal_labeled_profiler_sample = [%compare.equal : labeled_profiler_sample]
let from_json j ~use_signature =
let parse_profiler_result label result =
let methods =
match result with
| `Assoc [_; _; _; _; ("methods", `List j); _; _] ->
j
| _ ->
L.(die UserError "Unexpected JSON input for the collection of methods")
in
let rec parse_json j acc =
match j with
| `Assoc
[ ("class", `String classname)
; _
; ("method", `String methodname)
; ("signature", `String signature)
; _ ]
:: tl ->
let signature = if use_signature then signature else JNI.void_method_with_no_arguments in
let procname = create_procname ~classname ~methodname ~signature in
parse_json tl (procname :: acc)
| [] ->
acc
| _ ->
L.(die UserError "Unexpected JSON input for the description of a single method")
let from_java_profiler_samples j ~use_signature =
let process_methods methods =
ProfilerSample.of_list
(List.map
~f:(fun {Java_profiler_samples_t.classname; methodname; signature} ->
let signature =
if use_signature then signature else JNI.void_method_with_no_arguments
in
(label, ProfilerSample.of_list (parse_json methods []))
create_procname ~classname ~methodname ~signature )
methods)
in
match j with
| `Assoc pr ->
List.map ~f:(fun (label, result) -> parse_profiler_result label result) pr
| _ ->
L.(die UserError "Unexpected JSON input for the list of profiler results")
List.map j ~f:(fun {Java_profiler_samples_t.test; methods} -> (test, process_methods methods))
let from_json_string str ~use_signature =
from_java_profiler_samples
(Java_profiler_samples_j.java_profiler_samples_of_string str)
~use_signature
let from_json_string str ~use_signature = from_json (Yojson.Basic.from_string str) ~use_signature
let from_json_file file ~use_signature = from_json (Yojson.Basic.from_file file) ~use_signature
let from_json_file file ~use_signature =
from_java_profiler_samples
(Ag_util.Json.from_file Java_profiler_samples_j.read_java_profiler_samples file)
~use_signature

@ -164,22 +164,18 @@ let test_from_json_string_with_valid_input =
~cmp:(List.equal ~equal:JavaProfilerSamples.equal_labeled_profiler_sample)
expected found
in
let input1 =
"{\"label1\": {\"field1\": {}, \"field2\": {}, \"field3\": {}, \"field4\": {}, \"methods\": \
[], \"field6\": {},\"field7\": {}}}"
in
let input1 = "[{\"test\": \"label1\",\"methods\": []}]" in
let expected1 = [("label1", JavaProfilerSamples.ProfilerSample.of_list [])] in
let input2 =
Printf.sprintf
"{\"label1\": {\"field1\": {}, \"field2\": {}, \"field3\": {}, \"field4\": {}, \"methods\": \
[{\"class\": \"ggg.hhh.Iii\", \"boo\": \"\", \"method\": \"<clinit>\", \"signature\": \
\"(Ljava/lang/String;[IJ)V\", \"wat\": \"\"},{\"class\": \"lll.mmm.Nnn\", \"boo\": \"\", \
\"method\": \"<init>\", \"signature\": \"(Ljava/lang/String;[IJ)V\", \"wat\": \"\"}], \
\"field6\": {},\"field7\": {}},\"label2\": {\"field1\": {}, \"field2\": {}, \"field3\": \
{}, \"field4\": {}, \"methods\": [{\"class\": \"aaa.bbb.Ccc\", \"boo\": \"\", \"method\": \
\"methodOne\", \"signature\": \"%s\", \"wat\": \"\"},{\"class\": \"ddd.eee.Fff\", \"boo\": \
\"\", \"method\": \"methodTwo\", \"signature\": \"(Ljava/lang/String;[IJ)[[C\", \"wat\": \
\"\"}], \"field6\": {},\"field7\": {}}}"
"[{\"foo\":{},\"test\": \"label1\",\"methods\": [{\"class\": \"ggg.hhh.Iii\", \"boo\": \
\"\", \"method\": \"<clinit>\", \"signature\": \"(Ljava/lang/String;[IJ)V\",\"wat\": \
\"\"},{\"class\": \"lll.mmm.Nnn\",\"boo\": \"\",\"method\": \"<init>\",\"signature\": \
\"(Ljava/lang/String;[IJ)V\",\"wat\": \"\"}]},{\"boo\":\"aaa\",\"test\": \
\"label2\",\"methods\": [{\"class\": \"aaa.bbb.Ccc\",\"boo\": \"\",\"method\": \
\"methodOne\",\"signature\": \"%s\",\"wat\": \"\"},{\"class\": \"ddd.eee.Fff\",\"boo\": \
\"\",\"method\": \"methodTwo\",\"signature\": \"(Ljava/lang/String;[IJ)[[C\",\"wat\": \
\"\"}]}]"
JavaProfilerSamples.JNI.void_method_with_no_arguments
in
let expected2 =
@ -264,14 +260,18 @@ let test_from_json_string_with_invalid_input =
in
[ ( "test_from_json_string_1"
, "{\"whatever\": {}, \"methods\": []}"
, Logging.InferUserError "Unexpected JSON input for the collection of methods" )
, Yojson.Json_error
"Line 1, bytes 0-31:\nExpected '[' but found '{\"whatever\": {}, \"methods\": []}'" )
; ( "test_from_json_string_2"
, Printf.sprintf
"{\"whatever\": {}, \"methods\": [{\"class\": \"aaa.bbb.Ccc\", \"boo\": \"\", \"method\": \
\"methodOne\", \"signature\": \"%s\"}], \"foo\": {}}"
JavaProfilerSamples.JNI.void_method_with_no_arguments
, Logging.InferUserError "Unexpected JSON input for the collection of methods" )
; ("test_from_json_string_3", "(", Yojson.Json_error "Line 1, bytes 0-1:\nInvalid token '('") ]
, Yojson.Json_error
"Line 1, bytes 0-33:\nExpected '[' but found '{\"whatever\": {}, \"methods\": [{\"cl'" )
; ( "test_from_json_string_3"
, "("
, Yojson.Json_error "Line 1, bytes 0-1:\nExpected '[' but found '('" ) ]
|> List.map ~f:(fun (name, test_input, expected_exception) ->
name >:: create_test test_input expected_exception )

@ -4,6 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class MyFavouriteClassTwo {
void methodOne() {}

@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
class MyFavouriteClassTwo {
void methodOne() {}

@ -4,6 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class MyFavouriteClassTwo {
void methodOne() {}

@ -1,9 +1,8 @@
{
"label1": {
[
{
"field1": {},
"test": "label1",
"field2": {},
"field3": {},
"field4": {},
"methods": [
{
"class": "MyFavouriteClassTwo",
@ -20,13 +19,13 @@
"src_file": ""
}
],
"field6": {},
"field7": {}
"field3": {}
},
"label2": {
{
"field1": {},
"field2": {},
"field3": {},
"test": "label2",
"field4": {},
"methods": [
{
@ -44,7 +43,7 @@
"src_file": ""
}
],
"field6": {},
"field7": {}
}
"field5": {},
"field6": {}
}
]
Loading…
Cancel
Save