From 17a3bec2caee6c9974d696ee617517993557b66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Mon, 8 Feb 2021 11:47:55 -0800 Subject: [PATCH] [cost] Add tests for objc differential cost analysis Reviewed By: jvillard Differential Revision: D26314704 fbshipit-source-id: e2133dd03 --- .../costs_summary.json.exp | 2 +- .../differential_of_costs_report_objc/introduced.exp | 2 ++ .../src/DiffBlock.current.m | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/infer/tests/build_systems/differential_of_costs_report_objc/costs_summary.json.exp b/infer/tests/build_systems/differential_of_costs_report_objc/costs_summary.json.exp index e486f3c0e..6aa1a7abe 100644 --- a/infer/tests/build_systems/differential_of_costs_report_objc/costs_summary.json.exp +++ b/infer/tests/build_systems/differential_of_costs_report_objc/costs_summary.json.exp @@ -1 +1 @@ -{"top":{"current":0,"previous":0},"unreachable":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":20,"previous":15},{"degree":100,"current":4,"previous":1}]} \ No newline at end of file +{"top":{"current":0,"previous":0},"unreachable":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":20,"previous":15},{"degree":100,"current":5,"previous":1},{"degree":200,"current":1,"previous":0}]} \ No newline at end of file diff --git a/infer/tests/build_systems/differential_of_costs_report_objc/introduced.exp b/infer/tests/build_systems/differential_of_costs_report_objc/introduced.exp index e69de29bb..d71ef366e 100644 --- a/infer/tests/build_systems/differential_of_costs_report_objc/introduced.exp +++ b/infer/tests/build_systems/differential_of_costs_report_objc/introduced.exp @@ -0,0 +1,2 @@ +EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffBlock.m, Handler.func_linear:, 0, [Previous Cost of func_linear: is 4 + 5 ⋅ (array->elements.length + 1) (degree is 1),{array->elements.length + 1},Loop,Updated Cost of func_linear: is 4 + 3 ⋅ array->elements.length × (array->elements.length + 1) + 8 ⋅ (array->elements.length + 1) + 3 ⋅ (array->elements.length + 1) × (array->elements.length + 1) (degree is 2),{array->elements.length + 1},Loop,{array->elements.length},Call to Handler.loop_linear:,Loop] +EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffBlock.m, objc_blockHandler.func_linear_1, 0, [Previous Cost of objc_blockHandler.func_linear_1 is 21 (degree is 0),Updated Cost of objc_blockHandler.func_linear_1 is 23 + 3 ⋅ str.length + 3 ⋅ (str.length + 1) (degree is 1),{str.length},Loop] diff --git a/infer/tests/build_systems/differential_of_costs_report_objc/src/DiffBlock.current.m b/infer/tests/build_systems/differential_of_costs_report_objc/src/DiffBlock.current.m index 925182a2c..ccd3962bd 100644 --- a/infer/tests/build_systems/differential_of_costs_report_objc/src/DiffBlock.current.m +++ b/infer/tests/build_systems/differential_of_costs_report_objc/src/DiffBlock.current.m @@ -37,11 +37,20 @@ - (void (^)(NSString*))func_linear { return ^(NSString* str) { NSLog(@"Report error : %@ \n", str); + for (int i = 0; i < str.length; i++) { + } // we get a complexity increase here for the block, but we should print it + // better }; } ++ (void)loop_linear:(NSArray*)array { + for (int i = 0; i < array.count; i++) { + } +} + - (void)func_linear:(NSArray*)array { for (id value in array) { + [Handler loop_linear:array]; } }