2012-01-27 20:15:33 +00:00
|
|
|
package com.ibm.wala.cast.js.test;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2012-02-17 20:24:32 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
|
2012-01-27 20:15:33 +00:00
|
|
|
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.JSZeroOrOneXCFABuilder;
|
|
|
|
import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
|
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
|
|
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.cfa.ZeroXInstanceKeys;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
|
|
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
|
|
|
import com.ibm.wala.util.CancelException;
|
|
|
|
|
|
|
|
public abstract class TestArgumentSensitivity extends TestJSCallGraphShape {
|
|
|
|
|
|
|
|
protected static final Object[][] assertionsForArgs = new Object[][] {
|
|
|
|
new Object[] { ROOT, new String[] { "tests/args.js" } },
|
|
|
|
new Object[] {
|
|
|
|
"tests/args.js",
|
|
|
|
new String[] { "tests/args.js/a" } },
|
|
|
|
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/x"} },
|
2012-02-23 18:15:05 +00:00
|
|
|
new Object[] { "tests/args.js/a", new String[] { "tests/args.js/y", "tests/args.js/z", "!tests/args.js/wrong" } } };
|
2012-01-27 20:15:33 +00:00
|
|
|
|
|
|
|
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, ClassHierarchyException {
|
2012-02-17 20:24:32 +00:00
|
|
|
JavaScriptLoaderFactory loaders = JSCallGraphBuilderUtil.makeLoaders();
|
|
|
|
AnalysisScope scope = JSCallGraphBuilderUtil.makeScriptScope("tests", "args.js", loaders);
|
2012-01-27 20:15:33 +00:00
|
|
|
|
2012-02-17 20:24:32 +00:00
|
|
|
IClassHierarchy cha = JSCallGraphBuilderUtil.makeHierarchy(scope, loaders);
|
2012-01-27 20:15:33 +00:00
|
|
|
com.ibm.wala.cast.js.util.Util.checkForFrontEndErrors(cha);
|
2012-02-17 20:24:32 +00:00
|
|
|
Iterable<Entrypoint> roots = JSCallGraphBuilderUtil.makeScriptRoots(cha);
|
|
|
|
JSAnalysisOptions options = JSCallGraphBuilderUtil.makeOptions(scope, cha, roots);
|
2012-01-27 20:15:33 +00:00
|
|
|
|
2012-02-17 20:24:32 +00:00
|
|
|
AnalysisCache cache = JSCallGraphBuilderUtil.makeCache(new ArgumentSpecialization.ArgumentCountIRFactory(options.getSSAOptions()));
|
2012-01-27 20:15:33 +00:00
|
|
|
|
|
|
|
JSCFABuilder builder = new JSZeroOrOneXCFABuilder(cha, options, cache, null, null, ZeroXInstanceKeys.ALLOCATIONS, false);
|
|
|
|
builder.setContextSelector(new ArgumentSpecialization.ArgumentCountContextSelector(builder.getContextSelector()));
|
|
|
|
builder.setContextInterpreter(new ArgumentSpecialization.ArgumentSpecializationContextIntepreter(options, cache));
|
|
|
|
CallGraph CG = builder.makeCallGraph(options);
|
2012-07-03 22:55:02 +00:00
|
|
|
|
|
|
|
// CAstCallGraphUtil.AVOID_DUMP = false;
|
2012-02-17 20:24:32 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(builder.getPointerAnalysis(), CG);
|
2012-01-27 20:15:33 +00:00
|
|
|
|
|
|
|
verifyGraphAssertions(CG, assertionsForArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|