Skip to content

Commit

Permalink
Remove more debugging output produced during testing
Browse files Browse the repository at this point in the history
Also, turn
`com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil.AVOID_DUMP` into a
thread-local flag.  We should be able to turn it on or off without
potential interference from different threads (e.g., during concurrent
test execution) that have conflicting opinions.
  • Loading branch information
liblit committed Jul 25, 2023
1 parent a05945e commit e8bda11
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public TranslatorToCAst make(CAst ast, ModuleEntry M) {

System.err.println(CG.getClassHierarchy());

CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
import com.ibm.wala.cast.js.util.JSCallGraphBuilderUtil;
import com.ibm.wala.ipa.callgraph.CallGraph;
Expand All @@ -37,7 +36,6 @@ public void testCPA()
JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "cpa.js");
builder.setContextSelector(new CPAContextSelector(builder.getContextSelector()));
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,6 @@ public byte evaluate(PointsToSetVariable lhs, final PointsToSetVariable[] rhs) {
}
}
}

System.err.println(instruction);
}

if (op == CAstBinaryOp.STRICT_EQ || op == CAstBinaryOp.STRICT_NE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void testArgs()
new ArgumentSpecialization.ArgumentSpecializationContextIntepreter(options, cache));
CallGraph CG = builder.makeCallGraph(options);

CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);

verifyGraphAssertions(CG, assertionsForArgs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ public void testForin()
throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForForin);
}
Expand Down Expand Up @@ -321,11 +320,8 @@ public void testTry()
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "try.js");
CallGraph CG = B.makeCallGraph(B.getOptions());

boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(
(SSAContextInterpreter) B.getContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x;

verifyGraphAssertions(CG, assertionsForTry);
}
Expand Down Expand Up @@ -382,7 +378,6 @@ public void testStringPrims()
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js");
B.getOptions().setTraceStringConstants(true);
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForStringPrims);
}
Expand Down Expand Up @@ -642,7 +637,6 @@ public void testReturnThis()
SSAPropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForReturnThis);
}
Expand Down Expand Up @@ -764,7 +758,6 @@ public void testDispatch()
SSAPropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDispatch);
}
Expand All @@ -781,7 +774,6 @@ public void testDispatchSameTarget()
PropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch_same_target.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
// JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDispatchSameTarget);
}
Expand Down Expand Up @@ -840,7 +832,6 @@ public void testArrayIndexConv2()
b.setContextSelector(
new PropertyNameContextSelector(b.getAnalysisCache(), b.getContextSelector()));
CallGraph cg = b.makeCallGraph(b.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
// JSCallGraphUtil.dumpCG(b.getPointerAnalysis(), cg);
verifyGraphAssertions(cg, assertionsForArrayIndexConv2);
}
Expand All @@ -857,7 +848,6 @@ public void testDateAsProperty()
PropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "date-property.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
// JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDateProperty);
}
Expand All @@ -873,7 +863,6 @@ public void testDeadCode()
throws IllegalArgumentException, IOException, CancelException, WalaException {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dead.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
// JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDeadCode);
}
Expand Down Expand Up @@ -925,10 +914,7 @@ public void testTryFinallyCrash()
throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "try-finally-crash.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}

@Test(expected = CallGraphBuilderCancelException.class)
Expand Down Expand Up @@ -968,10 +954,7 @@ public void testLoops()
SSAPropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "loops.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForLoops);
}

Expand All @@ -997,10 +980,7 @@ public void testPrimitiveStrings()
SSAPropagationCallGraphBuilder B =
JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "primitive_strings.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean x = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = x;
verifyGraphAssertions(CG, assertionsForPrimitiveStrings);
}

Expand Down Expand Up @@ -1035,43 +1015,31 @@ public void testThrowCrash()
throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badthrow.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}

@Test
public void testNrWrapperCrash()
throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "nrwrapper.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}

@Test
public void testFinallyCrash()
throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "finallycrash.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}

@Test
public void testForInExpr()
throws IllegalArgumentException, IOException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "for_in_expr.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}

private static final Object[][] assertionsForComplexFinally =
Expand All @@ -1097,9 +1065,6 @@ public void testComplexFinally()
CallGraph CG = B.makeCallGraph(B.getOptions());
verifyGraphAssertions(CG, assertionsForComplexFinally);

boolean save = CAstCallGraphUtil.AVOID_DUMP;
CAstCallGraphUtil.AVOID_DUMP = true;
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
CAstCallGraphUtil.AVOID_DUMP = save;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ public void testList() throws IllegalArgumentException, CancelException, WalaExc
URL url = getClass().getClassLoader().getResource("pages/list.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
// JSCallGraphBuilderUtil.AVOID_DUMP = false;
CAstCallGraphUtil.dumpCG(builder.getCFAContextInterpreter(), builder.getPointerAnalysis(), CG);
verifySourceAssertions(CG, sourceAssertionsForList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class CAstCallGraphUtil {

/** flag to prevent dumping of verbose call graph / pointer analysis output */
public static boolean AVOID_DUMP = true;
public static final ThreadLocal<Boolean> AVOID_DUMP = ThreadLocal.withInitial(() -> true);

public static SourceFileModule makeSourceModule(URL script, String dir, String name) {
// DO NOT use File.separator here, since this name is matched against
Expand Down Expand Up @@ -128,7 +128,7 @@ public static String getShortName(IMethod method) {

public static void dumpCG(
SSAContextInterpreter interp, PointerAnalysis<? extends InstanceKey> PA, CallGraph CG) {
if (AVOID_DUMP) return;
if (AVOID_DUMP.get()) return;
for (CGNode N : CG) {
System.err.print("callees of node " + getShortName(N) + " : [");
boolean fst = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public void verifySourceAssertions(CallGraph CG, Object[][] assertionData) {
if (pos.getFirstLine() >= (Integer) assertionDatum[2]
&& (pos.getLastLine() != -1 ? pos.getLastLine() : pos.getFirstLine())
<= (Integer) assertionDatum[3]) {
System.err.println(
"found " + inst + " of " + M + " at expected position " + pos);
continue insts;
}
}
Expand Down Expand Up @@ -166,7 +164,6 @@ protected void verifyGraphAssertions(CallGraph CG, Object[][] assertionData) {
System.err.println(("found unexpected " + src + " --> " + dst + " at " + sr));
assert false : "found edge " + assertionDatum[0] + " ---> " + targetName;
} else {
System.err.println(("found expected " + src + " --> " + dst + " at " + sr));
continue check_target;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ protected void checkEdges(CallGraph staticCG, Predicate<MethodReference> filter)
"no edge for " + caller + " --> " + callee,
staticCG1.getPossibleSites(caller, callee).hasNext());
Pair<CGNode, CGNode> x = Pair.make(caller, callee);
if (edges.add(x)) {
System.err.println("found expected edge " + caller + " --> " + callee);
}
edges.add(x);
},
filter);
}
Expand All @@ -192,8 +190,6 @@ protected void checkNodes(CallGraph staticCG, Predicate<MethodReference> filter)
boolean checkForCallee = !staticCG1.getNodes(callee).isEmpty();
if (!checkForCallee) {
notFound.add(callee);
} else {
System.err.println("found expected node " + callee);
}
},
filter);
Expand Down

0 comments on commit e8bda11

Please sign in to comment.