2014-10-02 01:32:36 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright (c) 2002 - 2014 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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-11-14 18:02:56 +00:00
|
|
|
package com.ibm.wala.core.tests.shrike;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
|
|
|
import com.ibm.wala.core.tests.util.TestConstants;
|
2017-02-03 01:33:27 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
|
2013-11-14 18:02:56 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
|
|
|
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.cha.ClassHierarchy;
|
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
2017-01-12 21:34:54 +00:00
|
|
|
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
|
2013-11-14 18:02:56 +00:00
|
|
|
import com.ibm.wala.shrikeBT.analysis.Analyzer.FailureException;
|
|
|
|
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
|
|
|
import com.ibm.wala.util.CancelException;
|
|
|
|
|
2014-08-07 20:02:48 +00:00
|
|
|
public class DynamicCallGraphTest extends DynamicCallGraphTestBase {
|
|
|
|
|
2016-06-11 01:21:08 +00:00
|
|
|
protected final String testJarLocation;
|
|
|
|
|
|
|
|
protected DynamicCallGraphTest(String testJarLocation) {
|
|
|
|
this.testJarLocation = testJarLocation;
|
|
|
|
}
|
2015-06-28 21:06:21 +00:00
|
|
|
|
2016-06-11 01:21:08 +00:00
|
|
|
public DynamicCallGraphTest() {
|
|
|
|
this(getClasspathEntry("com.ibm.wala.core.testdata"));
|
|
|
|
}
|
|
|
|
|
2017-05-11 15:47:19 +00:00
|
|
|
private static CallGraph staticCG(String mainClass, String exclusionsFile) throws IOException, ClassHierarchyException, IllegalArgumentException, CancelException {
|
2013-11-14 18:02:56 +00:00
|
|
|
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, exclusionsFile != null? exclusionsFile: CallGraphTestUtil.REGRESSION_EXCLUSIONS);
|
2017-01-12 21:34:54 +00:00
|
|
|
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
|
2015-06-28 21:06:21 +00:00
|
|
|
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, mainClass);
|
2013-11-14 18:02:56 +00:00
|
|
|
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
|
2017-02-03 01:33:27 +00:00
|
|
|
return CallGraphTestUtil.buildZeroOneCFA(options, new AnalysisCacheImpl(), cha, scope, false);
|
2013-11-14 18:02:56 +00:00
|
|
|
}
|
2014-08-07 20:02:48 +00:00
|
|
|
|
2013-11-14 18:02:56 +00:00
|
|
|
@Test
|
2017-07-27 21:53:07 +00:00
|
|
|
public void testGraph() throws IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, IllegalArgumentException, ClassHierarchyException, CancelException, InterruptedException {
|
2014-08-07 20:02:48 +00:00
|
|
|
instrument(testJarLocation);
|
2015-06-28 21:06:21 +00:00
|
|
|
run("dynamicCG.MainClass", null);
|
|
|
|
CallGraph staticCG = staticCG("LdynamicCG/MainClass", null);
|
|
|
|
checkEdges(staticCG);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-07-27 21:53:07 +00:00
|
|
|
public void testCallbacks() throws IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, IllegalArgumentException, ClassHierarchyException, CancelException, InterruptedException {
|
2015-06-28 21:06:21 +00:00
|
|
|
instrument(testJarLocation);
|
|
|
|
run("dynamicCG.CallbacksMainClass", null);
|
|
|
|
CallGraph staticCG = staticCG("LdynamicCG/CallbacksMainClass", null);
|
2014-08-07 20:02:48 +00:00
|
|
|
checkEdges(staticCG);
|
2013-11-14 18:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-07-27 21:53:07 +00:00
|
|
|
public void testExclusions() throws IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, IllegalArgumentException, ClassHierarchyException, CancelException, InterruptedException {
|
2014-08-07 20:02:48 +00:00
|
|
|
instrument(testJarLocation);
|
2015-06-28 21:06:21 +00:00
|
|
|
run("dynamicCG.MainClass", "ShrikeTestExclusions.txt");
|
|
|
|
CallGraph staticCG = staticCG("LdynamicCG/MainClass", "ShrikeTestExclusions.txt");
|
2014-08-07 20:02:48 +00:00
|
|
|
checkEdges(staticCG);
|
2013-11-14 18:02:56 +00:00
|
|
|
}
|
2014-08-07 20:02:48 +00:00
|
|
|
|
2017-12-01 12:01:16 +00:00
|
|
|
@Test
|
|
|
|
public void testLambdas() throws IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, IllegalArgumentException, ClassHierarchyException, CancelException, InterruptedException {
|
|
|
|
instrument(testJarLocation);
|
|
|
|
run("lambda.SortingExample", null);
|
|
|
|
CallGraph staticCG = staticCG("Llambda/SortingExample", null);
|
|
|
|
checkEdges(staticCG);
|
|
|
|
}
|
|
|
|
|
2013-11-14 18:02:56 +00:00
|
|
|
}
|