From e8bda1163f613aa33d770525166839fe4d361548 Mon Sep 17 00:00:00 2001 From: Ben Liblit Date: Tue, 25 Jul 2023 13:18:40 -0400 Subject: [PATCH] Remove more debugging output produced during testing 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. --- .../cast/js/examples/drivers/RunBuilder.java | 1 - .../com/ibm/wala/cast/js/test/TestCPA.java | 2 -- .../JSSSAPropagationCallGraphBuilder.java | 2 -- .../cast/js/test/TestArgumentSensitivity.java | 1 - .../js/test/TestSimpleCallGraphShape.java | 35 ------------------- .../js/test/TestSimplePageCallGraphShape.java | 1 - .../cast/ipa/callgraph/CAstCallGraphUtil.java | 4 +-- .../cast/util/test/TestCallGraphShape.java | 3 -- .../shrike/DynamicCallGraphTestBase.java | 6 +--- 9 files changed, 3 insertions(+), 52 deletions(-) diff --git a/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/drivers/RunBuilder.java b/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/drivers/RunBuilder.java index 0759998d41..18872bf4bd 100644 --- a/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/drivers/RunBuilder.java +++ b/cast/js/rhino/src/main/java/com/ibm/wala/cast/js/examples/drivers/RunBuilder.java @@ -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); } } diff --git a/cast/js/rhino/src/test/java/com/ibm/wala/cast/js/test/TestCPA.java b/cast/js/rhino/src/test/java/com/ibm/wala/cast/js/test/TestCPA.java index ead8d27c1a..2eae0204e3 100644 --- a/cast/js/rhino/src/test/java/com/ibm/wala/cast/js/test/TestCPA.java +++ b/cast/js/rhino/src/test/java/com/ibm/wala/cast/js/test/TestCPA.java @@ -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; @@ -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); } } diff --git a/cast/js/src/main/java/com/ibm/wala/cast/js/ipa/callgraph/JSSSAPropagationCallGraphBuilder.java b/cast/js/src/main/java/com/ibm/wala/cast/js/ipa/callgraph/JSSSAPropagationCallGraphBuilder.java index e40767f379..48240acb44 100755 --- a/cast/js/src/main/java/com/ibm/wala/cast/js/ipa/callgraph/JSSSAPropagationCallGraphBuilder.java +++ b/cast/js/src/main/java/com/ibm/wala/cast/js/ipa/callgraph/JSSSAPropagationCallGraphBuilder.java @@ -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) { diff --git a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestArgumentSensitivity.java b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestArgumentSensitivity.java index a50a92add2..f9f19fe4b4 100644 --- a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestArgumentSensitivity.java +++ b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestArgumentSensitivity.java @@ -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); diff --git a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java index 86b33b6ff5..11622c20c6 100644 --- a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java +++ b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimpleCallGraphShape.java @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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) @@ -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); } @@ -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); } @@ -1035,10 +1015,7 @@ 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 @@ -1046,10 +1023,7 @@ 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 @@ -1057,10 +1031,7 @@ 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 @@ -1068,10 +1039,7 @@ 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 = @@ -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; } } diff --git a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java index 406161d9ad..378911baca 100644 --- a/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java +++ b/cast/js/src/testFixtures/java/com/ibm/wala/cast/js/test/TestSimplePageCallGraphShape.java @@ -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); } diff --git a/cast/src/main/java/com/ibm/wala/cast/ipa/callgraph/CAstCallGraphUtil.java b/cast/src/main/java/com/ibm/wala/cast/ipa/callgraph/CAstCallGraphUtil.java index e9260f8d9d..aad7bc3d43 100644 --- a/cast/src/main/java/com/ibm/wala/cast/ipa/callgraph/CAstCallGraphUtil.java +++ b/cast/src/main/java/com/ibm/wala/cast/ipa/callgraph/CAstCallGraphUtil.java @@ -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 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 @@ -128,7 +128,7 @@ public static String getShortName(IMethod method) { public static void dumpCG( SSAContextInterpreter interp, PointerAnalysis 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; diff --git a/cast/src/testFixtures/java/com/ibm/wala/cast/util/test/TestCallGraphShape.java b/cast/src/testFixtures/java/com/ibm/wala/cast/util/test/TestCallGraphShape.java index 244ae2ea71..d399dd4250 100644 --- a/cast/src/testFixtures/java/com/ibm/wala/cast/util/test/TestCallGraphShape.java +++ b/cast/src/testFixtures/java/com/ibm/wala/cast/util/test/TestCallGraphShape.java @@ -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; } } @@ -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; } } diff --git a/core/src/testFixtures/java/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java b/core/src/testFixtures/java/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java index 1db77ff80d..8310c83e37 100644 --- a/core/src/testFixtures/java/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java +++ b/core/src/testFixtures/java/com/ibm/wala/core/tests/shrike/DynamicCallGraphTestBase.java @@ -172,9 +172,7 @@ protected void checkEdges(CallGraph staticCG, Predicate filter) "no edge for " + caller + " --> " + callee, staticCG1.getPossibleSites(caller, callee).hasNext()); Pair x = Pair.make(caller, callee); - if (edges.add(x)) { - System.err.println("found expected edge " + caller + " --> " + callee); - } + edges.add(x); }, filter); } @@ -192,8 +190,6 @@ protected void checkNodes(CallGraph staticCG, Predicate filter) boolean checkForCallee = !staticCG1.getNodes(callee).isEmpty(); if (!checkForCallee) { notFound.add(callee); - } else { - System.err.println("found expected node " + callee); } }, filter);