[cost] Add differential test for unreachable cost issue type

Summary: Also, fix some leftover meaningless logging, enable all cost issue types on diff testing so that we can see the unreachable cost issues

Reviewed By: skcho

Differential Revision: D23784563

fbshipit-source-id: 1b4a2b582
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 6c8fc85e22
commit ee5ccfeb9b

@ -58,9 +58,7 @@ let compute_upperbound_map node_cfg inferbo_invariant_map control_invariant_map
| Unreachable -> | Unreachable ->
let node_loc = NodeCFG.Node.loc node in let node_loc = NodeCFG.Node.loc node in
L.debug Analysis Medium L.debug Analysis Medium
"@\n\ "@\n[COST ANALYSIS INTERNAL WARNING:] This location is unreachable \n" ;
[COST ANALYSIS INTERNAL WARNING:] No 'env' found. This location is \
unreachable returning cost 0 \n" ;
BasicCost.of_unreachable node_loc BasicCost.of_unreachable node_loc
| ExcRaised -> | ExcRaised ->
BasicCost.one () BasicCost.one ()

@ -19,10 +19,10 @@ $(CURRENT_REPORT):
$(QUIET)$(COPY) src/DiffExample.java.current src/DiffExample.java $(QUIET)$(COPY) src/DiffExample.java.current src/DiffExample.java
$(QUIET)$(COPY) src/DiffExampleUIThread.java.current src/DiffExampleUIThread.java $(QUIET)$(COPY) src/DiffExampleUIThread.java.current src/DiffExampleUIThread.java
$(QUIET)$(call silent_on_success,Testing Cost Differential: current,\ $(QUIET)$(call silent_on_success,Testing Cost Differential: current,\
$(INFER_BIN) --enable-issue-type INFINITE_EXECUTION_TIME --cost-only -o $(CURRENT_DIR) -- $(JAVAC) -cp $(CLASSPATH) src/*.java) $(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- $(JAVAC) -cp $(CLASSPATH) src/*.java)
$(PREVIOUS_REPORT): $(PREVIOUS_REPORT):
$(QUIET)$(COPY) src/DiffExample.java.previous src/DiffExample.java $(QUIET)$(COPY) src/DiffExample.java.previous src/DiffExample.java
$(QUIET)$(COPY) src/DiffExampleUIThread.java.previous src/DiffExampleUIThread.java $(QUIET)$(COPY) src/DiffExampleUIThread.java.previous src/DiffExampleUIThread.java
$(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\ $(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\
$(INFER_BIN) --debug --enable-issue-type INFINITE_EXECUTION_TIME --cost-only -o $(PREVIOUS_DIR) -- $(JAVAC) -cp $(CLASSPATH) src/*.java) $(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- $(JAVAC) -cp $(CLASSPATH) src/*.java)

@ -1 +1 @@
{"top":{"current":2,"previous":1},"unreachable":{"current":0,"previous":0},"zero":{"current":0,"previous":0},"degrees":[{"degree":0,"current":19,"previous":16},{"degree":100,"current":2,"previous":3},{"degree":101,"current":2,"previous":0},{"degree":200,"current":1,"previous":2}]} {"top":{"current":2,"previous":1},"unreachable":{"current":1,"previous":0},"zero":{"current":1,"previous":0},"degrees":[{"degree":0,"current":20,"previous":18},{"degree":100,"current":2,"previous":3},{"degree":101,"current":2,"previous":0},{"degree":200,"current":1,"previous":2}]}

@ -1,4 +1,5 @@
INFINITE_EXECUTION_TIME, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop] INFINITE_EXECUTION_TIME, no_bucket, src/DiffExample.java, DiffExample.f1(int):void, 0, [Unbounded loop,Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Previous Cost of f4 is 5 (degree is 0),Updated Cost of f4 is 6 + 5 ⋅ k (degree is 1),{k},Loop] EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f4(int):int, 0, [Previous Cost of f4 is 5 (degree is 0),Updated Cost of f4 is 6 + 5 ⋅ k (degree is 1),{k},Loop]
EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Previous Cost of f5 is 9 + 5 ⋅ n (degree is 1),{n},Call to int DiffExample.f1(int),Loop,Updated Cost of f5 is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort] EXECUTION_TIME_COMPLEXITY_INCREASE, no_bucket, src/DiffExample.java, DiffExample.f5(java.util.ArrayList):void, 0, [Previous Cost of f5 is 9 + 5 ⋅ n (degree is 1),{n},Call to int DiffExample.f1(int),Loop,Updated Cost of f5 is 2 + list.length × log(list.length) (degree is 1 + 1⋅log),{list.length},Modeled call to Collections.sort,{list.length},Modeled call to Collections.sort]
EXECUTION_TIME_UNREACHABLE_AT_EXIT, no_bucket, src/DiffExample.java, DiffExample.f8():void, 0, [Unreachable node]
EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f2(int):void, 0, [Previous Cost of f2 is 3 (degree is 0),Updated Cost of f2 is 5 + 5 ⋅ x (degree is 1),{x},Loop] EXECUTION_TIME_COMPLEXITY_INCREASE_UI_THREAD, no_bucket, src/DiffExampleUIThread.java, DiffExampleUIThread.f2(int):void, 0, [Previous Cost of f2 is 3 (degree is 0),Updated Cost of f2 is 5 + 5 ⋅ x (degree is 1),{x},Loop]

@ -6,9 +6,9 @@
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import com.google.common.base.Preconditions;
// This class has the following costs: // This class has the following costs:
// 1 bottom (zero), 2 constant, 1 linear, 1 top
// constructor: constant // constructor: constant
// private access$000 method for accessing f8 // private access$000 method for accessing f8
// f1: top // f1: top
@ -18,7 +18,8 @@ import java.util.ArrayList;
// f5: n log n // f5: n log n
// f6: n log n // f6: n log n
// f7: top by call to f1 // f7: top by call to f1
// f8: quadratic // f8: unreachable
// f9: quadratic
public class DiffExample { public class DiffExample {
@ -28,7 +29,7 @@ public class DiffExample {
@Override @Override
public String toString() { public String toString() {
f8(z); f9(z);
return super.toString(); return super.toString();
} }
}; };
@ -74,8 +75,14 @@ public class DiffExample {
f1(k); f1(k);
} }
private void f8() {
int x = 0;
Preconditions.checkArgument(false);
}
// cost: quadratic // cost: quadratic
private static void f8(int k) { private static void f9(int k) {
for (int i = 0; i < k; i++) { for (int i = 0; i < k; i++) {
f4(k); f4(k);
} }

@ -8,7 +8,6 @@
import java.util.ArrayList; import java.util.ArrayList;
// This class has the following costs: // This class has the following costs:
// 2 constant, 1 linear, 1 quadratic
// constructor: constant // constructor: constant
// private access$000 method for accessing f4 // private access$000 method for accessing f4
// f1: linear // f1: linear
@ -67,4 +66,9 @@ public class DiffExample {
i++; i++;
} }
} }
private void f8() {
int x = 0;
}
} }

@ -18,9 +18,9 @@ $(CURRENT_REPORT) $(PREVIOUS_REPORT): $(OBJC_DEPS)
$(CURRENT_REPORT): $(CURRENT_REPORT):
$(QUIET)$(COPY) src/DiffBlock.m.current src/DiffBlock.m $(QUIET)$(COPY) src/DiffBlock.m.current src/DiffBlock.m
$(QUIET)$(call silent_on_success,Testing Cost Differential: current,\ $(QUIET)$(call silent_on_success,Testing Cost Differential: current,\
$(INFER_BIN) --enable-issue-type INFINITE_EXECUTION_TIME --cost-only -o $(CURRENT_DIR) -- clang $(CLANG_OPTIONS) src/*.m) $(INFER_BIN) --no-filtering --cost-only -o $(CURRENT_DIR) -- clang $(CLANG_OPTIONS) src/*.m)
$(PREVIOUS_REPORT): $(PREVIOUS_REPORT):
$(QUIET)$(COPY) src/DiffBlock.m.previous src/DiffBlock.m $(QUIET)$(COPY) src/DiffBlock.m.previous src/DiffBlock.m
$(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\ $(QUIET)$(call silent_on_success,Testing Cost Differential: previous,\
$(INFER_BIN) --debug --enable-issue-type INFINITE_EXECUTION_TIME --cost-only -o $(PREVIOUS_DIR) -- clang $(CLANG_OPTIONS) src/*.m) $(INFER_BIN) --debug --no-filtering --cost-only -o $(PREVIOUS_DIR) -- clang $(CLANG_OPTIONS) src/*.m)

Loading…
Cancel
Save