changes to get tests passing on Java 7
This commit is contained in:
parent
8f9e988cef
commit
878cfa615d
@ -48,6 +48,9 @@ import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.classLoader.NewSiteReference;
|
||||
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
||||
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
|
||||
import com.ibm.wala.demandpa.alg.refinepolicy.NeverRefineCGPolicy;
|
||||
import com.ibm.wala.demandpa.alg.refinepolicy.OnlyArraysPolicy;
|
||||
import com.ibm.wala.demandpa.alg.refinepolicy.SinglePassRefinementPolicy;
|
||||
import com.ibm.wala.demandpa.alg.statemachine.DummyStateMachine;
|
||||
import com.ibm.wala.demandpa.alg.statemachine.StateMachineFactory;
|
||||
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
|
||||
@ -243,6 +246,9 @@ public abstract class AbstractPtrTest {
|
||||
DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, mam, cha, options,
|
||||
getStateMachineFactory());
|
||||
|
||||
// always refine array fields; otherwise, can be very sensitive to differences
|
||||
// in library versions. otherwise, no refinement by default
|
||||
fullDemandPointsTo.setRefinementPolicyFactory(new SinglePassRefinementPolicy.Factory(new OnlyArraysPolicy(), new NeverRefineCGPolicy()));
|
||||
return fullDemandPointsTo;
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,10 @@ import org.junit.Test;
|
||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
|
||||
/**
|
||||
* Note that in this test we still do refinement of the array contents
|
||||
* pseudo-field, to avoid excessive sensitivity to library versions.
|
||||
*/
|
||||
public class NoRefinePtrTest extends AbstractPtrTest {
|
||||
|
||||
public NoRefinePtrTest() {
|
||||
|
||||
@ -257,7 +257,7 @@ public class SlicerTest {
|
||||
TestConstants.SLICE8_MAIN);
|
||||
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
|
||||
|
||||
CallGraphBuilder builder = Util.makeVanillaZeroOneContainerCFABuilder(options, new AnalysisCache(), cha, scope);
|
||||
CallGraphBuilder builder = Util.makeZeroOneCFABuilder(options, new AnalysisCache(), cha, scope);
|
||||
CallGraph cg = builder.makeCallGraph(options, null);
|
||||
|
||||
CGNode process = findMethod(cg, Descriptor.findOrCreateUTF8("()V"), Atom.findOrCreateUnicodeAtom("process"));
|
||||
@ -646,7 +646,7 @@ public class SlicerTest {
|
||||
Collection<Statement> slice = Slicer.computeBackwardSlice(s, cg, builder.getPointerAnalysis(), DataDependenceOptions.FULL,
|
||||
ControlDependenceOptions.NONE);
|
||||
dumpSlice(slice);
|
||||
Assert.assertEquals(1, countAllocations(slice));
|
||||
Assert.assertEquals(1, countApplicationAllocations(slice));
|
||||
Assert.assertEquals(1, countThrows(slice));
|
||||
Assert.assertEquals(1, countGetfields(slice));
|
||||
}
|
||||
@ -705,6 +705,22 @@ public class SlicerTest {
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int countApplicationAllocations(Collection<Statement> slice) {
|
||||
int count = 0;
|
||||
for (Statement s : slice) {
|
||||
if (s.getKind().equals(Statement.Kind.NORMAL)) {
|
||||
NormalStatement ns = (NormalStatement) s;
|
||||
if (ns.getInstruction() instanceof SSANewInstruction) {
|
||||
AnalysisScope scope = s.getNode().getClassHierarchy().getScope();
|
||||
if (scope.isApplicationLoader(s.getNode().getMethod().getDeclaringClass().getClassLoader())) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int countThrows(Collection<Statement> slice) {
|
||||
int count = 0;
|
||||
for (Statement s : slice) {
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.examples.analysis.dataflow;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -50,9 +51,9 @@ import com.ibm.wala.types.MethodReference;
|
||||
import com.ibm.wala.util.CancelException;
|
||||
import com.ibm.wala.util.collections.Pair;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.config.FileOfClasses;
|
||||
import com.ibm.wala.util.intset.IntIterator;
|
||||
import com.ibm.wala.util.intset.IntSet;
|
||||
import com.ibm.wala.util.io.FileProvider;
|
||||
|
||||
/**
|
||||
* Tests of various flow analysis engines.
|
||||
@ -63,12 +64,29 @@ public class DataflowTest extends WalaTestCase {
|
||||
|
||||
private static IClassHierarchy cha;
|
||||
|
||||
// more aggressive exclusions to avoid library blowup
|
||||
// in interprocedural tests
|
||||
private static final String EXCLUSIONS = "java\\/awt\\/.*\n" +
|
||||
"javax\\/swing\\/.*\n" +
|
||||
"sun\\/awt\\/.*\n" +
|
||||
"sun\\/swing\\/.*\n" +
|
||||
"com\\/sun\\/.*\n" +
|
||||
"sun\\/.*\n" +
|
||||
"org\\/netbeans\\/.*\n" +
|
||||
"org\\/openide\\/.*\n" +
|
||||
"com\\/ibm\\/crypto\\/.*\n" +
|
||||
"com\\/ibm\\/security\\/.*\n" +
|
||||
"org\\/apache\\/xerces\\/.*\n" +
|
||||
"java\\/security\\/.*\n" +
|
||||
"";
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA,
|
||||
(new FileProvider()).getFile(CallGraphTestUtil.REGRESSION_EXCLUSIONS), DataflowTest.class.getClassLoader());
|
||||
scope = AnalysisScopeReader.readJavaScope(TestConstants.WALA_TESTDATA, null, DataflowTest.class.getClassLoader());
|
||||
|
||||
scope.setExclusions(new FileOfClasses(new ByteArrayInputStream(EXCLUSIONS.getBytes("UTF-8"))));
|
||||
try {
|
||||
cha = ClassHierarchy.make(scope);
|
||||
} catch (ClassHierarchyException e) {
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.demandpa.alg.refinepolicy;
|
||||
|
||||
import com.ibm.wala.classLoader.IField;
|
||||
import com.ibm.wala.demandpa.alg.statemachine.StateMachine.State;
|
||||
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
|
||||
import com.ibm.wala.demandpa.util.ArrayContents;
|
||||
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
|
||||
|
||||
/**
|
||||
* Only refines for the array contents pseudo-field.
|
||||
*
|
||||
* @author manu
|
||||
*
|
||||
*/
|
||||
public class OnlyArraysPolicy implements FieldRefinePolicy {
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.alg.refinepolicy.FieldRefinePolicy#shouldRefine(com.ibm.wala.classLoader.IField, com.ibm.wala.ipa.callgraph.propagation.PointerKey, com.ibm.wala.ipa.callgraph.propagation.PointerKey, com.ibm.wala.demandpa.flowgraph.IFlowLabel, com.ibm.wala.demandpa.alg.statemachine.StateMachine.State)
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldRefine(IField field, PointerKey basePtr, PointerKey val, IFlowLabel label, State state) {
|
||||
return field == ArrayContents.v();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see com.ibm.wala.demandpa.alg.refinepolicy.FieldRefinePolicy#nextPass()
|
||||
*/
|
||||
@Override
|
||||
public boolean nextPass() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user