2007-02-02 17:28:04 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2006 IBM Corporation.
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* IBM Corporation - initial API and implementation
|
|
|
|
*****************************************************************************/
|
|
|
|
package com.ibm.wala.cast.js.test;
|
|
|
|
|
2007-07-11 21:08:26 +00:00
|
|
|
import java.io.IOException;
|
2012-01-06 21:21:26 +00:00
|
|
|
import java.util.List;
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2014-10-15 07:01:38 +00:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Ignore;
|
2009-07-27 23:21:22 +00:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2013-06-10 13:02:12 +00:00
|
|
|
import com.ibm.wala.cast.ipa.callgraph.CAstCallGraphUtil;
|
2012-03-01 02:45:51 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.JSCFABuilder;
|
2013-06-03 17:44:06 +00:00
|
|
|
import com.ibm.wala.cast.js.ipa.callgraph.PropertyNameContextSelector;
|
2010-11-05 00:36:44 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
2007-07-11 21:08:26 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
2013-04-09 22:47:22 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
|
2007-07-11 21:08:26 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
|
2013-04-09 22:47:22 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
|
2009-06-22 15:06:12 +00:00
|
|
|
import com.ibm.wala.util.CancelException;
|
2014-02-09 02:37:39 +00:00
|
|
|
import com.ibm.wala.util.NullProgressMonitor;
|
|
|
|
import com.ibm.wala.util.ProgressMaster;
|
2013-04-09 22:47:22 +00:00
|
|
|
import com.ibm.wala.util.WalaException;
|
2012-01-06 21:21:26 +00:00
|
|
|
import com.ibm.wala.util.collections.Iterator2Collection;
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2009-07-27 23:21:22 +00:00
|
|
|
public abstract class TestSimpleCallGraphShape extends TestJSCallGraphShape {
|
2007-02-02 17:28:04 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
justThisTest(TestSimpleCallGraphShape.class);
|
|
|
|
}
|
|
|
|
|
2012-01-27 20:15:33 +00:00
|
|
|
protected static final Object[][] assertionsForArgs = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "args.js" } },
|
2012-01-27 20:15:33 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"args.js",
|
|
|
|
new String[] { "args.js/a" } },
|
|
|
|
new Object[] { "args.js/a", new String[] { "args.js/x", "args.js/y" } } };
|
2012-01-27 20:15:33 +00:00
|
|
|
|
2013-04-09 22:47:22 +00:00
|
|
|
@Test public void testArgs() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:24:32 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "args.js");
|
2012-01-27 20:15:33 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForArgs);
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:28:04 +00:00
|
|
|
protected static final Object[][] assertionsForSimple = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "simple.js" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"simple.js",
|
|
|
|
new String[] { "simple.js/bad", "simple.js/silly", "simple.js/fib", "simple.js/stranger",
|
|
|
|
"simple.js/trivial", "simple.js/rubbish", "simple.js/weirder" } },
|
|
|
|
new Object[] { "simple.js/trivial", new String[] { "simple.js/trivial/inc" } },
|
|
|
|
new Object[] { "simple.js/rubbish",
|
|
|
|
new String[] { "simple.js/weirder", "simple.js/stranger", "simple.js/rubbish" } },
|
|
|
|
new Object[] { "simple.js/fib", new String[] { "simple.js/fib" } },
|
|
|
|
new Object[] { "simple.js/weirder", new String[] { "prologue.js/Math_abs" } } };
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testSimple() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "simple.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForSimple);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForObjects = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "objects.js" } },
|
|
|
|
new Object[] { "objects.js",
|
|
|
|
new String[] { "objects.js/objects_are_fun", "objects.js/other", "objects.js/something" } },
|
|
|
|
new Object[] { "objects.js/other",
|
|
|
|
new String[] { "objects.js/something", "objects.js/objects_are_fun/nothing" } },
|
|
|
|
new Object[] { "objects.js/objects_are_fun", new String[] { "objects.js/other", "objects.js/whatever" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testObjects() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "objects.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForObjects);
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:44:06 +00:00
|
|
|
private static final Object[][] cfgAssertionsForInherit = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[]{"ctor:inherit.js/objectMasquerading/Rectangle",
|
2014-07-08 18:44:06 +00:00
|
|
|
new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}}
|
|
|
|
},
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[]{"ctor:inherit.js/sharedClassObject/Rectangle",
|
2014-07-08 18:44:06 +00:00
|
|
|
new int[][]{{1,7},{2},{3,7},{4,7},{5,6},{7},{7}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-02-02 17:28:04 +00:00
|
|
|
private static final Object[][] assertionsForInherit = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "inherit.js" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"inherit.js",
|
|
|
|
new String[] { "inherit.js/objectMasquerading", "inherit.js/objectMasquerading/Rectangle/area",
|
|
|
|
"inherit.js/Polygon/shape", "inherit.js/sharedClassObject",
|
|
|
|
"inherit.js/sharedClassObject/Rectangle/area" } },
|
2014-07-08 18:44:06 +00:00
|
|
|
new Object[]{
|
2017-02-03 01:33:27 +00:00
|
|
|
"inherit.js/objectMasquerading",
|
|
|
|
new String[]{"ctor:inherit.js/objectMasquerading/Rectangle"}},
|
2014-07-08 18:44:06 +00:00
|
|
|
new Object[]{
|
2017-02-03 01:33:27 +00:00
|
|
|
"ctor:inherit.js/objectMasquerading/Rectangle" ,
|
|
|
|
new String[]{"inherit.js/objectMasquerading/Rectangle"}},
|
|
|
|
new Object[]{"inherit.js/objectMasquerading/Rectangle",
|
|
|
|
new String[]{"inherit.js/Polygon"}},
|
2014-07-08 18:44:06 +00:00
|
|
|
new Object[]{
|
2017-02-03 01:33:27 +00:00
|
|
|
"inherit.js/sharedClassObject",
|
|
|
|
new String[]{"ctor:inherit.js/sharedClassObject/Rectangle"}},
|
|
|
|
new Object[]{"ctor:inherit.js/sharedClassObject/Rectangle",
|
|
|
|
new String[]{"inherit.js/sharedClassObject/Rectangle"}}
|
2007-02-02 17:28:04 +00:00
|
|
|
};
|
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testInherit() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "inherit.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForInherit);
|
2014-07-08 18:44:06 +00:00
|
|
|
verifyCFGAssertions(CG, cfgAssertionsForInherit);
|
2007-02-02 17:28:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
private static final Object[][] assertionsForNewfn = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "newfn.js" } },
|
|
|
|
new Object[] { "newfn.js",
|
2012-01-06 21:21:26 +00:00
|
|
|
new String[] { "suffix:ctor$1/_fromctor", "suffix:ctor$2/_fromctor", "suffix:ctor$3/_fromctor" } } };
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testNewfn() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "newfn.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForNewfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForControlflow = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "control-flow.js" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"control-flow.js",
|
|
|
|
new String[] { "control-flow.js/testSwitch", "control-flow.js/testDoWhile",
|
|
|
|
"control-flow.js/testWhile", "control-flow.js/testFor", "control-flow.js/testReturn" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "control-flow.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForControlflow);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForMoreControlflow = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "more-control-flow.js" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"more-control-flow.js",
|
|
|
|
new String[] { "more-control-flow.js/testSwitch", "more-control-flow.js/testIfConvertedSwitch",
|
|
|
|
"more-control-flow.js/testDoWhile", "more-control-flow.js/testWhile",
|
|
|
|
"more-control-flow.js/testFor", "more-control-flow.js/testReturn" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testMoreControlflow() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "more-control-flow.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForMoreControlflow);
|
|
|
|
}
|
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
private static final Object[][] assertionsForForin = new Object[][] { new Object[] { ROOT, new String[] { "forin.js" } },
|
|
|
|
new Object[] { "forin.js", new String[] { "forin.js/testForIn" } },
|
|
|
|
new Object[] { "forin.js/testForIn", new String[] { "forin.js/testForIn1", "forin.js/testForIn2" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testForin() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-03-01 02:45:51 +00:00
|
|
|
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "forin.js");
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2012-07-03 22:55:02 +00:00
|
|
|
// JSCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForForin);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForSimpleLexical = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "simple-lexical.js" } },
|
|
|
|
new Object[] { "simple-lexical.js", new String[] { "simple-lexical.js/outer" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"simple-lexical.js/outer",
|
|
|
|
new String[] { "simple-lexical.js/outer/indirect", "simple-lexical.js/outer/inner",
|
|
|
|
"simple-lexical.js/outer/inner2", "simple-lexical.js/outer/inner3" } },
|
|
|
|
new Object[] { "simple-lexical.js/outer/inner2",
|
|
|
|
new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } },
|
|
|
|
new Object[] { "simple-lexical.js/outer/indirect",
|
|
|
|
new String[] { "simple-lexical.js/outer/inner", "simple-lexical.js/outer/inner3" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testSimpleLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "simple-lexical.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForSimpleLexical);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:36:10 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testRecursiveLexical() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-01-06 21:36:10 +00:00
|
|
|
// just checking that we have a sufficient bailout to ensure termination
|
2012-02-17 20:21:59 +00:00
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "recursive_lexical.js");
|
2012-01-06 21:36:10 +00:00
|
|
|
}
|
2012-01-06 21:43:58 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForLexicalMultiple = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "lexical_multiple_calls.js" } },
|
2012-01-06 21:43:58 +00:00
|
|
|
new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable1" } },
|
|
|
|
new Object[] { "suffix:lexical_multiple_calls.js", new String[] { "suffix:reachable2" } }};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testLexicalMultiple() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical_multiple_calls.js");
|
2012-01-06 21:43:58 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForLexicalMultiple);
|
|
|
|
}
|
2012-01-06 21:36:10 +00:00
|
|
|
|
2012-01-06 21:43:58 +00:00
|
|
|
|
2007-02-02 17:28:04 +00:00
|
|
|
private static final Object[][] assertionsForTry = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "try.js" } },
|
|
|
|
new Object[] { "try.js",
|
|
|
|
new String[] { "try.js/tryCatch", "try.js/tryFinally", "try.js/tryCatchFinally" } },
|
|
|
|
new Object[] { "try.js/tryCatch",
|
|
|
|
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
|
|
|
|
new Object[] { "try.js/tryFinally",
|
|
|
|
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/two" } },
|
|
|
|
new Object[] { "try.js/tryCatchFinally",
|
|
|
|
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
|
|
|
|
new Object[] { "try.js/tryCatchTwice",
|
|
|
|
new String[] { "try.js/targetOne", "try.js/targetTwo", "try.js/three", "try.js/two" } },
|
|
|
|
new Object[] { "try.js/testRet",
|
|
|
|
new String[] { "try.js/three", "try.js/two" } }
|
2014-10-15 07:01:38 +00:00
|
|
|
};
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testTry() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2014-10-15 07:01:38 +00:00
|
|
|
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "try.js");
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
/*
|
|
|
|
boolean x = CAstCallGraphUtil.AVOID_DUMP;
|
|
|
|
CAstCallGraphUtil.AVOID_DUMP = false;
|
|
|
|
CAstCallGraphUtil.dumpCG(B.getPointerAnalysis(), CG);
|
|
|
|
CAstCallGraphUtil.AVOID_DUMP = x;
|
|
|
|
*/
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForTry);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForStringOp = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "string-op.js" } },
|
|
|
|
new Object[] { "string-op.js", new String[] { "string-op.js/getOp", "string-op.js/plusNum" } } };
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testStringOp() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-op.js");
|
2008-02-13 22:34:36 +00:00
|
|
|
B.getOptions().setTraceStringConstants(true);
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForStringOp);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForUpward = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "upward.js" } },
|
2008-02-13 22:34:36 +00:00
|
|
|
new Object[] {
|
2017-02-03 01:33:27 +00:00
|
|
|
"upward.js",
|
|
|
|
new String[] { "upward.js/Obj/setit", "upward.js/Obj/getit", "upward.js/tester1",
|
|
|
|
"upward.js/tester2" } } };
|
2008-02-13 22:34:36 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testUpward() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "upward.js");
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForUpward);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForStringPrims = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "string-prims.js" } },
|
|
|
|
new Object[] { "string-prims.js", new String[] { "prologue.js/String_prototype_split", "prologue.js/String_prototype_toUpperCase" } } };
|
2007-02-02 17:28:04 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testStringPrims() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "string-prims.js");
|
2008-02-13 22:34:36 +00:00
|
|
|
B.getOptions().setTraceStringConstants(true);
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2012-07-03 22:55:02 +00:00
|
|
|
// JSCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2007-02-02 17:28:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForStringPrims);
|
|
|
|
}
|
2012-01-06 21:21:26 +00:00
|
|
|
|
2017-02-03 01:33:27 +00:00
|
|
|
private static final Object[][] assertionsForNested = new Object[][] { new Object[] { ROOT, new String[] { "nested.js" } },
|
|
|
|
new Object[] { "nested.js", new String[] { "nested.js/f", "nested.js/f/ff", "nested.js/f/ff/fff" } } };
|
2012-01-06 21:21:26 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testNested() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "nested.js");
|
2008-12-02 14:09:49 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
verifyGraphAssertions(CG, assertionsForNested);
|
|
|
|
}
|
2008-12-16 14:54:09 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
private static final Object[][] assertionsForInstanceof = new Object[][] { new Object[] { ROOT,
|
2017-02-03 01:33:27 +00:00
|
|
|
new String[] { "instanceof.js" } } };
|
2012-01-06 21:21:26 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testInstanceof() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "instanceof.js");
|
2008-12-16 14:54:09 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
verifyGraphAssertions(CG, assertionsForInstanceof);
|
|
|
|
}
|
2009-01-30 16:33:22 +00:00
|
|
|
|
|
|
|
/*
|
2012-01-06 21:21:26 +00:00
|
|
|
* private static final Object[][] assertionsForWith = new Object[][] { new
|
2017-02-03 01:33:27 +00:00
|
|
|
* Object[] { ROOT, new String[] { "with.js" } } };
|
2012-01-06 21:21:26 +00:00
|
|
|
*
|
|
|
|
* @Test public void testWith() throws IOException, IllegalArgumentException,
|
|
|
|
* CancelException { PropagationCallGraphBuilder B =
|
|
|
|
* Util.makeScriptCGBuilder("tests", "with.js"); CallGraph CG =
|
|
|
|
* B.makeCallGraph(B.getOptions()); verifyGraphAssertions(CG,
|
|
|
|
* assertionsForWith); }
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testCrash1() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "crash1.js");
|
2009-01-19 15:12:39 +00:00
|
|
|
verifyGraphAssertions(CG, null);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testCrash2() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "crash2.js");
|
2009-01-30 16:33:22 +00:00
|
|
|
verifyGraphAssertions(CG, null);
|
|
|
|
}
|
2012-01-06 21:21:26 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testLexicalCtor() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical-ctor.js");
|
2011-05-05 03:52:26 +00:00
|
|
|
verifyGraphAssertions(CG, null);
|
|
|
|
}
|
2009-01-30 16:33:22 +00:00
|
|
|
|
2009-02-02 20:46:51 +00:00
|
|
|
private static final Object[][] assertionsForMultivar = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "multivar.js" } },
|
|
|
|
new Object[] { "multivar.js", new String[] { "multivar.js/a", "multivar.js/bf", "multivar.js/c" } } };
|
2009-02-02 20:46:51 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testMultivar() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "multivar.js");
|
2009-02-02 20:46:51 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForMultivar);
|
|
|
|
}
|
|
|
|
|
2010-10-02 19:30:03 +00:00
|
|
|
private static final Object[][] assertionsForPrototypeContamination = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "prototype_contamination_bug.js" } },
|
2012-01-06 21:21:26 +00:00
|
|
|
new Object[] { "suffix:test1", new String[] { "suffix:foo_of_A" } },
|
|
|
|
new Object[] { "suffix:test2", new String[] { "suffix:foo_of_B" } } };
|
2010-10-02 19:30:03 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testProtoypeContamination() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "prototype_contamination_bug.js");
|
2010-10-02 19:30:03 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForPrototypeContamination);
|
|
|
|
verifyNoEdges(CG, "suffix:test1", "suffix:foo_of_B");
|
|
|
|
verifyNoEdges(CG, "suffix:test2", "suffix:foo_of_A");
|
|
|
|
}
|
2012-01-06 21:21:26 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testStackOverflowOnSsaConversionBug() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "stack_overflow_on_ssa_conversion.js");
|
2010-10-02 20:27:17 +00:00
|
|
|
// all we need is for it to finish building CG successfully.
|
|
|
|
}
|
2010-11-05 00:36:44 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testExtJSSwitch() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "extjs_switch.js");
|
2011-07-04 21:21:29 +00:00
|
|
|
// all we need is for it to finish building CG successfully.
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testFunctionDotCall() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph cg = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_call.js");
|
2012-01-06 21:21:26 +00:00
|
|
|
for (CGNode n : cg) {
|
|
|
|
if (n.getMethod().getName().toString().equals("call4")) {
|
|
|
|
Assert.assertEquals(2, cg.getSuccNodeCount(n));
|
|
|
|
// ugh
|
|
|
|
List<CGNode> succs = Iterator2Collection.toList(cg.getSuccNodes(n));
|
|
|
|
Assert
|
|
|
|
.assertEquals(
|
2017-02-03 01:33:27 +00:00
|
|
|
"[Node: <Code body of function Lfunction_call.js/foo> Context: Everywhere, Node: <Code body of function Lfunction_call.js/bar> Context: Everywhere]",
|
2012-01-06 21:21:26 +00:00
|
|
|
succs.toString());
|
|
|
|
}
|
|
|
|
}
|
2011-07-05 02:32:10 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:26:01 +00:00
|
|
|
private static final Object[][] assertionsForFunctionApply = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "function_apply.js" } },
|
2012-01-06 21:26:23 +00:00
|
|
|
new Object[] { "suffix:function_apply.js", new String[] { "suffix:theOne" } },
|
|
|
|
new Object[] { "suffix:function_apply.js", new String[] { "suffix:theTwo" } } };
|
|
|
|
|
2012-01-06 21:26:01 +00:00
|
|
|
|
2012-01-06 21:21:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testFunctionDotApply() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_apply.js");
|
2012-01-06 21:26:01 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForFunctionApply);
|
2012-01-06 21:19:36 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 21:27:21 +00:00
|
|
|
private static final Object[][] assertionsForFunctionApply2 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "function_apply2.js" } },
|
2012-01-06 21:27:21 +00:00
|
|
|
new Object[] { "suffix:function_apply2.js", new String[] { "suffix:theThree" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testFunctionDotApply2() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_apply2.js");
|
2012-01-06 21:27:21 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForFunctionApply2);
|
|
|
|
}
|
2013-06-10 13:02:12 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForFunctionApply3 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "function_apply3.js" } },
|
2013-06-10 13:02:12 +00:00
|
|
|
new Object[] { "suffix:apply", new String[] { "suffix:foo" } } };
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testFunctionDotApply3() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "function_apply3.js");
|
|
|
|
verifyGraphAssertions(CG, assertionsForFunctionApply3);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:34:04 +00:00
|
|
|
private static final Object[][] assertionsForWrap1 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "wrap1.js" } },
|
2012-01-06 21:34:04 +00:00
|
|
|
new Object[] { "suffix:wrap1.js", new String[] { "suffix:i_am_reachable" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testWrap1() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap1.js");
|
2012-01-06 21:34:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForWrap1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForWrap2 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "wrap2.js" } },
|
2012-01-06 21:34:04 +00:00
|
|
|
new Object[] { "suffix:wrap2.js", new String[] { "suffix:i_am_reachable" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testWrap2() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap2.js");
|
2012-01-06 21:34:04 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForWrap2);
|
|
|
|
}
|
2012-01-06 21:27:21 +00:00
|
|
|
|
2012-01-06 21:36:59 +00:00
|
|
|
private static final Object[][] assertionsForWrap3 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "wrap3.js" } },
|
2012-01-06 21:36:59 +00:00
|
|
|
new Object[] { "suffix:wrap3.js", new String[] { "suffix:i_am_reachable" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testWrap3() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "wrap3.js");
|
2012-01-06 21:36:59 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForWrap3);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:22:27 +00:00
|
|
|
private static final Object[][] assertionsForComplexCall = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "complex_call.js" } },
|
2012-01-06 21:22:27 +00:00
|
|
|
new Object[] { "suffix:call.js", new String[] { "suffix:f3" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testComplexCall() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "complex_call.js");
|
2012-01-06 21:34:04 +00:00
|
|
|
for(CGNode nd : CG)
|
|
|
|
System.out.println(nd);
|
2012-01-06 21:22:27 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForComplexCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-06 21:23:56 +00:00
|
|
|
private static final Object[][] assertionsForGlobalObj = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "global_object.js" } },
|
2012-01-06 21:23:56 +00:00
|
|
|
new Object[] { "suffix:global_object.js", new String[] { "suffix:biz" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testGlobalObjPassing() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "global_object.js");
|
2012-01-06 21:28:46 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForGlobalObj);
|
2012-01-06 21:23:56 +00:00
|
|
|
}
|
2012-01-06 21:41:57 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForGlobalObj2 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "global_object2.js" } },
|
2012-01-06 21:41:57 +00:00
|
|
|
new Object[] { "suffix:global_object2.js", new String[] { "suffix:foo" } } };
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testGlobalObj2() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "global_object2.js");
|
2012-01-06 21:41:57 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForGlobalObj2);
|
|
|
|
}
|
2012-01-06 21:43:58 +00:00
|
|
|
|
2012-01-06 21:41:57 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForReturnThis = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "return_this.js" } },
|
2012-01-06 21:41:57 +00:00
|
|
|
new Object[] { "suffix:return_this.js", new String[] { "suffix:foo" } },
|
|
|
|
new Object[] { "suffix:return_this.js", new String[] { "suffix:bar" } } };
|
2012-01-06 21:28:46 +00:00
|
|
|
|
2012-01-06 21:41:57 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testReturnThis() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "return_this.js");
|
2012-03-01 02:45:51 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2012-07-03 22:55:02 +00:00
|
|
|
// JSCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2012-01-06 21:41:57 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForReturnThis);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForReturnThis2 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "return_this2.js" } },
|
2012-01-06 21:41:57 +00:00
|
|
|
new Object[] { "suffix:return_this2.js", new String[] { "suffix:A" } },
|
|
|
|
new Object[] { "suffix:return_this2.js", new String[] { "suffix:foo" } },
|
|
|
|
new Object[] { "suffix:return_this2.js", new String[] { "suffix:test1" } },
|
|
|
|
new Object[] { "suffix:return_this2.js", new String[] { "suffix:test2" } },
|
|
|
|
new Object[] { "suffix:test1", new String[] { "suffix:bar1" } },
|
|
|
|
new Object[] { "suffix:test2", new String[] { "suffix:bar2" } }
|
|
|
|
};
|
|
|
|
// when using the ObjectSensitivityContextSelector, we additionally know that test1 does not call bar2,
|
|
|
|
// and test2 does not call bar1
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testReturnThis2() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "return_this2.js");
|
2012-01-06 21:41:57 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForReturnThis2);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:43:37 +00:00
|
|
|
private static final Object[][] assertionsForArguments = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "arguments.js" } },
|
2012-01-06 21:43:37 +00:00
|
|
|
new Object[] { "suffix:arguments.js", new String[] { "suffix:f" } },
|
2012-02-17 20:18:32 +00:00
|
|
|
new Object[] { "suffix:f", new String[] { "!suffix:g1", "!suffix:g2", "suffix:g3", } }
|
2012-01-06 21:43:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testArguments() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "arguments.js");
|
2012-01-06 21:43:37 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForArguments);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:41:57 +00:00
|
|
|
private static final Object[][] assertionsForFunctionIsAFunction = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "Function_is_a_function.js" } },
|
2012-09-18 17:22:17 +00:00
|
|
|
new Object[] { "suffix:Function_is_a_function.js", new String[] { "suffix:Function_prototype_call" } } };
|
2012-01-06 21:41:57 +00:00
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testFunctionIsAFunction() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "Function_is_a_function.js");
|
2012-01-06 21:41:57 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForFunctionIsAFunction);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:50:52 +00:00
|
|
|
private static final Object[][] assertionsForLexicalBroken = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "lexical_broken.js" } },
|
2012-01-06 21:50:52 +00:00
|
|
|
new Object[] { "suffix:lexical_broken.js", new String[] { "suffix:f" } },
|
|
|
|
new Object[] { "suffix:f", new String[] { "suffix:g" } }
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testLexicalBroken() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "lexical_broken.js");
|
2012-01-06 21:50:52 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForLexicalBroken);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:51:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testDeadPhi() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "dead_phi.js");
|
2012-01-06 21:51:26 +00:00
|
|
|
}
|
2012-02-17 20:15:57 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForScopingOverwriteFunction = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "scoping_test.js" } },
|
2012-02-17 20:15:57 +00:00
|
|
|
new Object[] { "suffix:scoping_test.js", new String[] { "suffix:i_am_reachable" } }
|
|
|
|
};
|
|
|
|
|
2012-02-17 20:13:39 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testScopingOverwriteFunction() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "scoping_test.js");
|
2012-02-17 20:15:57 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForScopingOverwriteFunction);
|
2012-02-17 20:13:39 +00:00
|
|
|
}
|
2012-02-17 20:14:26 +00:00
|
|
|
|
2012-02-17 20:14:36 +00:00
|
|
|
private static final Object[][] assertionsForNestedParamAssign = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "nested_assign_to_param.js" } },
|
2012-02-17 20:14:36 +00:00
|
|
|
new Object[] { "suffix:nested_assign_to_param.js", new String[] { "suffix:i_am_reachable" } }
|
|
|
|
};
|
|
|
|
|
2012-02-17 20:14:26 +00:00
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testNestedAssignToParam() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-02-17 20:21:59 +00:00
|
|
|
CallGraph CG = JSCallGraphBuilderUtil.makeScriptCG("tests", "nested_assign_to_param.js");
|
2012-02-17 20:14:36 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForNestedParamAssign);
|
2012-02-17 20:14:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-01 02:45:51 +00:00
|
|
|
private static final Object[][] assertionsForDispatch = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "dispatch.js" } },
|
|
|
|
new Object[] { "dispatch.js", new String[] { "dispatch.js/left_outer", "dispatch.js/right_outer" } },
|
|
|
|
new Object[] { "dispatch.js/left_outer", new String[]{ "dispatch.js/left_inner" } },
|
|
|
|
new Object[] { "dispatch.js/right_outer", new String[]{ "dispatch.js/right_inner" } }
|
2012-03-01 02:45:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testDispatch() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "dispatch.js");
|
2012-03-01 02:45:51 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2012-07-03 22:55:02 +00:00
|
|
|
// JSCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2012-03-01 02:45:51 +00:00
|
|
|
verifyGraphAssertions(CG, assertionsForDispatch);
|
|
|
|
}
|
2012-07-30 19:40:48 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForDispatchSameTarget = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "dispatch_same_target.js" } },
|
|
|
|
new Object[] { "dispatch_same_target.js/f3", new String[] { "dispatch_same_target.js/f4" } }
|
2012-07-30 19:40:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testDispatchSameTarget() throws IOException, IllegalArgumentException, CancelException, WalaException {
|
2012-07-30 19:40:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-09 18:22:34 +00:00
|
|
|
|
|
|
|
private static final Object[][] assertionsForForInPrototype = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "for_in_prototype.js" } },
|
|
|
|
new Object[] { "for_in_prototype.js", new String[] { "suffix:A",
|
2012-07-09 18:22:34 +00:00
|
|
|
"suffix:reachable",
|
|
|
|
"suffix:also_reachable" } }
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testForInPrototype() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-07-09 18:22:34 +00:00
|
|
|
CallGraph cg = JSCallGraphBuilderUtil.makeScriptCG("tests", "for_in_prototype.js");
|
|
|
|
verifyGraphAssertions(cg, assertionsForForInPrototype);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForArrayIndexConv = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "array_index_conv.js" } },
|
|
|
|
new Object[] { "array_index_conv.js", new String[] { "suffix:reachable1",
|
2012-12-18 04:38:17 +00:00
|
|
|
"suffix:reachable2",
|
|
|
|
"suffix:reachable3",
|
|
|
|
"suffix:reachable4" } }
|
2012-07-09 18:22:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testArrayIndexConv() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-07-09 18:22:34 +00:00
|
|
|
PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv.js");
|
|
|
|
CallGraph cg = b.makeCallGraph(b.getOptions());
|
|
|
|
verifyGraphAssertions(cg, assertionsForArrayIndexConv);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForArrayIndexConv2 = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "array_index_conv2.js" } },
|
|
|
|
new Object[] { "array_index_conv2.js", new String[] { "suffix:invokeOnA" } },
|
2012-07-09 18:22:34 +00:00
|
|
|
new Object[] { "suffix:invokeOnA", new String[] { "suffix:reachable",
|
|
|
|
"suffix:also_reachable",
|
|
|
|
"suffix:reachable_too" } }
|
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testArrayIndexConv2() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2012-07-09 18:22:34 +00:00
|
|
|
PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv2.js");
|
2013-06-10 13:02:12 +00:00
|
|
|
b.setContextSelector(new PropertyNameContextSelector(b.getAnalysisCache(), b.getContextSelector()));
|
2012-07-09 18:22:34 +00:00
|
|
|
CallGraph cg = b.makeCallGraph(b.getOptions());
|
2013-01-08 01:18:27 +00:00
|
|
|
//JSCallGraphUtil.AVOID_DUMP = false;
|
|
|
|
//JSCallGraphUtil.dumpCG(b.getPointerAnalysis(), cg);
|
2012-07-09 18:22:34 +00:00
|
|
|
verifyGraphAssertions(cg, assertionsForArrayIndexConv2);
|
|
|
|
}
|
2012-03-01 02:45:51 +00:00
|
|
|
|
2013-01-08 01:18:27 +00:00
|
|
|
private static final Object[][] assertionsForDateProperty = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "date-property.js" } },
|
|
|
|
new Object[] { "date-property.js", new String[] { "suffix:_fun" } }
|
2013-01-08 01:18:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
2013-04-09 22:47:22 +00:00
|
|
|
public void testDateAsProperty() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2013-01-08 01:18:27 +00:00
|
|
|
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);
|
|
|
|
}
|
2013-04-09 22:47:22 +00:00
|
|
|
private static final Object[][] assertionsForDeadCode = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "dead.js" } },
|
|
|
|
new Object[] { "dead.js", new String[] { "suffix:twoReturns" } }
|
2013-04-09 22:47:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
|
|
|
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);
|
|
|
|
}
|
2013-06-10 13:02:12 +00:00
|
|
|
|
2014-06-26 15:12:44 +00:00
|
|
|
private static final Object[][] assertionsForShadow = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "shadow_test.js" } },
|
|
|
|
new Object[] { "shadow_test.js", new String[] { "shadow_test.js/test" } },
|
|
|
|
new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/bad" } },
|
|
|
|
new Object[] { "shadow_test.js/test", new String[] { "shadow_test.js/global_bad" } }
|
2014-06-26 15:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testShadow() throws IOException, WalaException, IllegalArgumentException, CancelException {
|
|
|
|
JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "shadow_test.js");
|
|
|
|
CallGraph cg = builder.makeCallGraph(builder.getOptions());
|
|
|
|
verifyGraphAssertions(cg, assertionsForShadow);
|
|
|
|
}
|
|
|
|
|
2013-06-10 13:02:12 +00:00
|
|
|
private static final Object[][] assertionsForExtend = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "extend.js" } },
|
|
|
|
new Object[] { "extend.js", new String[] { "suffix:bar", "!suffix:foo" } }
|
2013-06-10 13:02:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testExtend() throws IOException, WalaException, IllegalArgumentException, CancelException {
|
|
|
|
JSCFABuilder builder = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "extend.js");
|
|
|
|
CallGraph cg = builder.makeCallGraph(builder.getOptions());
|
|
|
|
verifyGraphAssertions(cg, assertionsForExtend);
|
|
|
|
}
|
2013-04-09 22:47:22 +00:00
|
|
|
|
2013-04-11 01:09:10 +00:00
|
|
|
@Test
|
|
|
|
public void testDeadCatch() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "dead_catch.js");
|
|
|
|
}
|
|
|
|
|
2013-07-30 18:04:08 +00:00
|
|
|
@Test
|
|
|
|
public void testUglyLoopCrash() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
|
|
|
JSCallGraphBuilderUtil.makeScriptCG("tests", "ssa-crash.js");
|
|
|
|
}
|
|
|
|
|
2013-06-10 13:02:12 +00:00
|
|
|
@Test
|
|
|
|
public void testTryFinallyCrash() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2015-11-11 17:03:08 +00:00
|
|
|
JSCFABuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "try-finally-crash.js");
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
boolean save = CAstCallGraphUtil.AVOID_DUMP;
|
|
|
|
//CAstCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2015-11-11 17:03:08 +00:00
|
|
|
CAstCallGraphUtil.AVOID_DUMP = save;
|
2013-06-10 13:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-09 22:47:22 +00:00
|
|
|
@Test(expected = CallGraphBuilderCancelException.class)
|
|
|
|
public void testManyStrings() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "many-strings.js");
|
|
|
|
B.getOptions().setTraceStringConstants(true);
|
2014-02-09 02:37:39 +00:00
|
|
|
ProgressMaster monitor = ProgressMaster.make(new NullProgressMonitor(), 10000, false);
|
|
|
|
monitor.beginTask("build CG", 1);
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions(), monitor);
|
|
|
|
monitor.done();
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2013-04-09 22:47:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 19:23:52 +00:00
|
|
|
@Test
|
2013-06-10 13:02:12 +00:00
|
|
|
public void testTutorialExample() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "tutorial-example.js");
|
2013-06-10 13:02:12 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2013-06-10 13:02:12 +00:00
|
|
|
// verifyGraphAssertions(CG, assertionsForDateProperty);
|
|
|
|
}
|
|
|
|
|
2014-10-15 07:01:38 +00:00
|
|
|
private static final Object[][] assertionsForLoops = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "loops.js" } },
|
|
|
|
new Object[] { "loops.js", new String[] { "loops.js/three", "loops.js/four"} }
|
2014-10-15 07:01:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Ignore("need to fix this. bug from Sukyoung's group")
|
|
|
|
@Test
|
|
|
|
public void testLoops() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "loops.js");
|
2014-10-15 07:01:38 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
boolean x = CAstCallGraphUtil.AVOID_DUMP;
|
|
|
|
CAstCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2014-10-15 07:01:38 +00:00
|
|
|
CAstCallGraphUtil.AVOID_DUMP = x;
|
|
|
|
verifyGraphAssertions(CG, assertionsForLoops);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final Object[][] assertionsForPrimitiveStrings = new Object[][] {
|
2017-02-03 01:33:27 +00:00
|
|
|
new Object[] { ROOT, new String[] { "primitive_strings.js" } },
|
|
|
|
new Object[] { "primitive_strings.js", new String[] { "primitive_strings.js/f1", "primitive_strings.js/f1"} },
|
|
|
|
new Object[] { "primitive_strings.js/f2", new String[] { "prologue.js/String_prototype_concat" } },
|
|
|
|
new Object[] { "primitive_strings.js/f1", new String[] { "prologue.js/String_prototype_concat" } },
|
2014-10-15 07:01:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Ignore("need to fix this. bug from Sukyoung's group")
|
|
|
|
@Test
|
|
|
|
public void testPrimitiveStrings() throws IllegalArgumentException, IOException, CancelException, WalaException {
|
2017-03-11 18:22:45 +00:00
|
|
|
SSAPropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "primitive_strings.js");
|
2014-10-15 07:01:38 +00:00
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
boolean x = CAstCallGraphUtil.AVOID_DUMP;
|
|
|
|
CAstCallGraphUtil.AVOID_DUMP = false;
|
2017-03-11 18:22:45 +00:00
|
|
|
CAstCallGraphUtil.dumpCG(B.getCFAContextInterpreter(), B.getPointerAnalysis(), CG);
|
2014-10-15 07:01:38 +00:00
|
|
|
CAstCallGraphUtil.AVOID_DUMP = x;
|
|
|
|
verifyGraphAssertions(CG, assertionsForPrimitiveStrings);
|
|
|
|
}
|
|
|
|
|
2014-07-01 19:23:52 +00:00
|
|
|
Object[][] renamingAssertions = {
|
2017-02-03 01:33:27 +00:00
|
|
|
{ "rename-example.js/f", new Name[]{ new Name(9, 7, "x"), new Name(9, 7, "y") } },
|
|
|
|
{ "rename-example.js/ff", new Name[]{ new Name(11, 10, "x"), new Name(11, 10, "y"), new Name(11, 10, "z") } }
|
2014-07-01 19:23:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testRenaming() throws IOException, WalaException, IllegalArgumentException, CancelException {
|
|
|
|
PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "rename-example.js");
|
|
|
|
CallGraph CG = B.makeCallGraph(B.getOptions());
|
|
|
|
verifyNameAssertions(CG, renamingAssertions);
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:28:04 +00:00
|
|
|
}
|