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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-08-07 20:02:48 +00:00
|
|
|
package com.ibm.wala.core.tests.callGraph;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2014-11-12 01:03:09 +00:00
|
|
|
import java.util.jar.JarFile;
|
2014-08-07 20:02:48 +00:00
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import com.ibm.wala.analysis.reflection.java7.MethodHandles;
|
2018-10-13 12:42:08 +00:00
|
|
|
import com.ibm.wala.classLoader.Language;
|
2014-08-07 20:02:48 +00:00
|
|
|
import com.ibm.wala.core.tests.shrike.DynamicCallGraphTestBase;
|
2017-02-03 01:33:27 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
|
2014-08-07 20:02:48 +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;
|
2017-03-16 02:06:19 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.IAnalysisCacheView;
|
2014-08-07 20:02:48 +00:00
|
|
|
import com.ibm.wala.ipa.callgraph.impl.Util;
|
|
|
|
import com.ibm.wala.ipa.callgraph.propagation.SSAPropagationCallGraphBuilder;
|
|
|
|
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;
|
2014-08-07 20:02:48 +00:00
|
|
|
import com.ibm.wala.shrikeBT.analysis.Analyzer.FailureException;
|
|
|
|
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
2014-11-12 01:03:09 +00:00
|
|
|
import com.ibm.wala.types.ClassLoaderReference;
|
2014-08-07 20:02:48 +00:00
|
|
|
import com.ibm.wala.util.CancelException;
|
|
|
|
import com.ibm.wala.util.io.TemporaryFile;
|
|
|
|
|
|
|
|
public class Java7CallGraphTest extends DynamicCallGraphTestBase {
|
2014-11-12 01:03:09 +00:00
|
|
|
|
2017-07-27 21:53:07 +00:00
|
|
|
@Test public void testOcamlHelloHash() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, InterruptedException {
|
2017-04-14 04:16:22 +00:00
|
|
|
if (!"True".equals(System.getenv("APPVEYOR"))) {
|
|
|
|
testOCamlJar("hello_hash.jar");
|
|
|
|
}
|
2014-11-12 01:03:09 +00:00
|
|
|
}
|
|
|
|
|
2017-07-27 21:53:07 +00:00
|
|
|
private void testOCamlJar(String jarFile, String... args) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, InterruptedException {
|
2014-11-12 01:03:09 +00:00
|
|
|
File F = TemporaryFile.urlToFile(jarFile.replace('.', '_') + ".jar", getClass().getClassLoader().getResource(jarFile));
|
|
|
|
F.deleteOnExit();
|
|
|
|
|
|
|
|
AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope("base.txt", CallGraphTestUtil.REGRESSION_EXCLUSIONS);
|
2016-06-03 11:07:05 +00:00
|
|
|
scope.addToScope(ClassLoaderReference.Application, new JarFile(F, false));
|
2014-11-12 01:03:09 +00:00
|
|
|
|
2017-01-12 21:34:54 +00:00
|
|
|
ClassHierarchy cha = ClassHierarchyFactory.make(scope);
|
2014-08-07 20:02:48 +00:00
|
|
|
Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lpack/ocamljavaMain");
|
|
|
|
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
|
2018-10-13 12:42:08 +00:00
|
|
|
options.setUseConstantSpecificKeys(true);
|
2017-03-16 02:06:19 +00:00
|
|
|
IAnalysisCacheView cache = new AnalysisCacheImpl();
|
2014-08-07 20:02:48 +00:00
|
|
|
|
2018-10-13 12:42:08 +00:00
|
|
|
SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);
|
|
|
|
|
2018-08-03 19:52:24 +00:00
|
|
|
MethodHandles.analyzeMethodHandles(options, builder);
|
2014-08-07 20:02:48 +00:00
|
|
|
|
|
|
|
CallGraph cg = builder.makeCallGraph(options, null);
|
|
|
|
|
2018-10-13 12:42:08 +00:00
|
|
|
System.err.println(cg);
|
|
|
|
|
2014-08-07 20:02:48 +00:00
|
|
|
instrument(F.getAbsolutePath());
|
2014-11-12 01:03:09 +00:00
|
|
|
run("pack.ocamljavaMain", null, args);
|
2014-08-07 20:02:48 +00:00
|
|
|
|
2017-11-23 01:28:36 +00:00
|
|
|
checkNodes(cg, t -> {
|
|
|
|
String s = t.toString();
|
|
|
|
return s.contains("Lpack/") || s.contains("Locaml/stdlib/");
|
2014-08-07 20:02:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|