clean ups

This commit is contained in:
Julian Dolby 2013-08-29 10:16:38 -04:00
parent 58e4c392f6
commit 0799bffc84
6 changed files with 26 additions and 84 deletions

View File

@ -4,7 +4,6 @@ Bundle-Name: WALA JavaScript Test Plug-in
Bundle-SymbolicName: com.ibm.wala.cast.js.test;singleton:=true
Bundle-Version: 1.3.4.qualifier
Bundle-ClassPath: test.jar
Bundle-Activator: com.ibm.wala.cast.js.test.JavaScriptTestPlugin
Bundle-Vendor: IBM
Require-Bundle: com.ibm.wala.cast.js,
com.ibm.wala.cast,

View File

@ -18,6 +18,7 @@ import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.ArgumentSpecialization;
import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSZeroOrOneXCFABuilder;
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.ipa.callgraph.AnalysisCache;
@ -41,15 +42,15 @@ public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } };
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException, WalaException {
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders(null);
JavaScriptLoaderFactory loaders = JSCallGraphUtil.makeLoaders(null);
AnalysisScope scope = JSCallGraphBuilderUtil.makeScriptScope("tests", "args.js", loaders);
IClassHierarchy cha = JSCallGraphBuilderUtil.makeHierarchy(scope, loaders);
IClassHierarchy cha = JSCallGraphUtil.makeHierarchy(scope, loaders);
com.ibm.wala.cast.js.util.Util.checkForFrontEndErrors(cha);
Iterable<Entrypoint> roots = JSCallGraphBuilderUtil.makeScriptRoots(cha);
JSAnalysisOptions options = JSCallGraphBuilderUtil.makeOptions(scope, cha, roots);
Iterable<Entrypoint> roots = JSCallGraphUtil.makeScriptRoots(cha);
JSAnalysisOptions options = JSCallGraphUtil.makeOptions(scope, cha, roots);
AnalysisCache cache = JSCallGraphBuilderUtil.makeCache(new ArgumentSpecialization.ArgumentCountIRFactory(options.getSSAOptions()));
AnalysisCache cache = CAstCallGraphUtil.makeCache(new ArgumentSpecialization.ArgumentCountIRFactory(options.getSSAOptions()));
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, false);
builder.setContextSelector(new ArgumentSpecialization.ArgumentCountContextSelector(builder.getContextSelector()));

View File

@ -17,6 +17,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.html.JSSourceExtractor;
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
@ -37,7 +38,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
URL url = getClass().getClassLoader().getResource("pages/page3.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
}
@Test public void testPage3WithHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
@ -45,7 +46,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
}
@Ignore("This test now blows up due to proper handling of the || construct, used in extend(). Should handle this eventually.")
@ -54,7 +55,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
addHackedForInLoopSensitivity(builder);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
}
/*
@ -87,7 +88,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
@Test public void testBadForInWithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin);
}
@ -106,7 +107,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForBadForin);
verifyGraphAssertions(CG, assertionsForBadForinHackPrecision);
}
@ -131,7 +132,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
@Test public void testbadforin2WithoutHack() throws IOException, IllegalArgumentException, CancelException, WalaException {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2);
}
@ -150,7 +151,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin2.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForbadforin2);
verifyGraphAssertions(CG, assertionsForbadforin2HackPrecision);
}
@ -159,7 +160,7 @@ public abstract class TestForInLoopHack extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "badforin3.js");
addHackedForInLoopSensitivity(B);
CallGraph CG = B.makeCallGraph(B.getOptions());
JSCallGraphBuilderUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
}

View File

@ -12,14 +12,16 @@ package com.ibm.wala.cast.js.test;
import java.util.Collection;
import com.ibm.wala.cast.js.ipa.callgraph.JSCallGraphUtil;
import com.ibm.wala.cast.test.TestCallGraphShape;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
public abstract class TestJSCallGraphShape extends TestCallGraphShape {
@Override
protected Collection getNodes(CallGraph CG, String functionIdentifier) {
return JSCallGraphBuilderUtil.getNodes(CG, functionIdentifier);
protected Collection<CGNode> getNodes(CallGraph CG, String functionIdentifier) {
return JSCallGraphUtil.getNodes(CG, functionIdentifier);
}
}

View File

@ -11,39 +11,24 @@
package com.ibm.wala.cast.js.test;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import junit.framework.Assert;
import org.junit.Ignore;
import org.junit.Test;
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.ipa.callgraph.PropertyNameContextSelector;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
import com.ibm.wala.ipa.callgraph.propagation.LocalPointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
import com.ibm.wala.ssa.SSAInstruction;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.collections.IVector;
import com.ibm.wala.util.collections.Iterator2Collection;
import com.ibm.wala.util.collections.Pair;
import com.ibm.wala.util.collections.SparseVector;
import com.ibm.wala.util.intset.IntSetAction;
import com.ibm.wala.util.intset.OrdinalSet;
public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
@ -163,7 +148,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForForin);
}
@ -255,7 +240,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
B.getOptions().setTraceStringConstants(true);
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForStringPrims);
}
@ -466,7 +451,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForReturnThis);
}
@ -561,7 +546,7 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js");
CallGraph CG = B.makeCallGraph(B.getOptions());
// JSCallGraphUtil.AVOID_DUMP = false;
JSCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForDispatch);
}
@ -713,51 +698,4 @@ public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
// verifyGraphAssertions(CG, assertionsForDateProperty);
}
protected IVector<Set<Pair<CGNode, Integer>>> computeIkIdToVns(PointerAnalysis pa) {
// Created by reversing the points to mapping for local pointer keys.
// Instead of mapping (local) pointer keys to instance keys (with id), we
// map instance keys to VnInContext (which carry the same information as
// local pointer keys)
final IVector<Set<Pair<CGNode, Integer>>> ret = new SparseVector<Set<Pair<CGNode, Integer>>>();
for (PointerKey pk : pa.getPointerKeys()) {
if (pk instanceof LocalPointerKey) {
final LocalPointerKey lpk = (LocalPointerKey) pk;
// we filter out local pointer keys that have no uses.
// NOTE: do to some weird behavior, we get pointer keys with vns that
// don't exist, so we have to filter those before asking about uses.
if (lpk.getNode().getDU().getDef(lpk.getValueNumber()) != null) {
Iterator<SSAInstruction> uses = lpk.getNode().getDU().getUses(lpk.getValueNumber());
if (uses.hasNext()) {
OrdinalSet<InstanceKey> pointsToSet = pa.getPointsToSet(pk);
if (pointsToSet == null || pointsToSet.getBackingSet() == null)
continue;
pointsToSet.getBackingSet().foreach(new IntSetAction() {
@Override
public void act(int ikId) {
Set<Pair<CGNode, Integer>> s = ret.get(ikId);
if (s == null) {
s = HashSetFactory.make();
ret.set(ikId, s);
}
s.add(Pair.make(lpk.getNode(), lpk.getValueNumber()));
}
});
} else {
int i = 0;
i++;
}
} else {
int i = 0;
i++;
}
}
}
return ret;
}
}

View File

@ -16,6 +16,7 @@ import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
import com.ibm.wala.cast.js.html.IHtmlParser;
import com.ibm.wala.cast.js.html.IHtmlParserFactory;
import com.ibm.wala.cast.js.html.WebUtil;
@ -269,7 +270,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
// JSCallGraphBuilderUtil.AVOID_DUMP = false;
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
verifySourceAssertions(CG, sourceAssertionsForList);
}
@ -291,7 +292,7 @@ public abstract class TestSimplePageCallGraphShape extends TestJSCallGraphShape
URL url = getClass().getClassLoader().getResource("pages/windowx.html");
JSCFABuilder builder = JSCallGraphBuilderUtil.makeHTMLCGBuilder(url);
CallGraph CG = builder.makeCallGraph(builder.getOptions());
JSCallGraphBuilderUtil.dumpCG(builder.getPointerAnalysis(), CG);
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
verifyGraphAssertions(CG, assertionsForWindowx);
}