From 24caeb7088237fdea47a3cb8c164a44b371621c4 Mon Sep 17 00:00:00 2001 From: msridhar1 Date: Wed, 18 Nov 2009 22:15:23 +0000 Subject: [PATCH] more flows-to tests git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3765 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../src/demandpa/FlowsToTestArraySetIter.java | 29 ++++++++++++++++ .../src/demandpa/FlowsToTestFields.java | 34 +++++++++++++++++++ .../src/demandpa/FlowsToTestFieldsHarder.java | 32 +++++++++++++++++ .../src/demandpa/FlowsToTestHashSet.java | 32 +++++++++++++++++ .../core/tests/demandpa/AbstractPtrTest.java | 4 ++- .../core/tests/demandpa/NoRefinePtrTest.java | 21 ++++++++++++ .../wala/core/tests/demandpa/TestInfo.java | 8 +++++ 7 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 com.ibm.wala.core.testdata/src/demandpa/FlowsToTestArraySetIter.java create mode 100644 com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFields.java create mode 100644 com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFieldsHarder.java create mode 100644 com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java diff --git a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestArraySetIter.java b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestArraySetIter.java new file mode 100644 index 000000000..fe49fa4a7 --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestArraySetIter.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2008 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 demandpa; + +/** + * @author manu + * + */ +public class FlowsToTestArraySetIter { + + public static void main(String[] args) { + ArraySet s1 = new ArraySet(); + ArraySet s2 = new ArraySet(); + s1.add(new FlowsToType()); + s2.add(new B()); + A a = (A) s1.iterator().next(); + B b = (B) s2.iterator().next(); + TestUtil.makeVarUsed(b); + TestUtil.makeVarUsed(a); + } +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFields.java b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFields.java new file mode 100644 index 000000000..abdfbae5d --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFields.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2008 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 demandpa; + +/** + * @author manu + * + */ +public class FlowsToTestFields { + + /** + * @param args + */ + public static void main(String[] args) { + Object o1 = new FlowsToType(); + Object o2 = new Object(); + A a1 = new A(); + A a2 = new A(); + a1.f = o1; + a2.f = o2; + Object o3 = a1.f; + Object o4 = a2.f; + TestUtil.makeVarUsed(o3); + TestUtil.makeVarUsed(o4); + } +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFieldsHarder.java b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFieldsHarder.java new file mode 100644 index 000000000..c72b76b76 --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestFieldsHarder.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2008 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 demandpa; + +/** + * @author manu + * + */ +public class FlowsToTestFieldsHarder { + + /** + * @param args + */ + public static void main(String[] args) { + Object o1 = new FlowsToType(); + A a1 = new A(); + a1.f = o1; + A a2 = new A(); + a2.f = a1; + A a3 = (A) a2.f; + Object o2 = a3.f; + TestUtil.makeVarUsed(o2); + } +} diff --git a/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java new file mode 100644 index 000000000..e73a1265f --- /dev/null +++ b/com.ibm.wala.core.testdata/src/demandpa/FlowsToTestHashSet.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2008 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 demandpa; + +import java.util.HashSet; + +/** + * @author manu + * + */ +public class FlowsToTestHashSet { + + @SuppressWarnings("unchecked") + public static void main(String[] args) { + HashSet s1 = new HashSet(); + HashSet s2 = new HashSet(); + s1.add(new FlowsToType()); + s2.add(new Object()); + Object o1 = s1.iterator().next(); + Object o2 = s2.iterator().next(); + TestUtil.makeVarUsed(o1); + TestUtil.makeVarUsed(o2); + } +} diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java index a8e7b830a..407de92fb 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/AbstractPtrTest.java @@ -234,7 +234,9 @@ public abstract class AbstractPtrTest { // TODO Auto-generated method stub TypeReference flowsToTypeRef = TypeReference.findOrCreate(ClassLoaderReference.Application, StringStuff .deployment2CanonicalTypeString("demandpa.FlowsToType")); - for (NewSiteReference n : Iterator2Iterable.make(mainMethod.getIR().iterateNewSites())) { + final IR mainIR = mainMethod.getIR(); +// System.err.println(mainIR); + for (NewSiteReference n : Iterator2Iterable.make(mainIR.iterateNewSites())) { if (n.getDeclaredType().equals(flowsToTypeRef)) { return heapModel.getInstanceKeyForAllocation(mainMethod, n); } diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java index af335cfa2..f8171cda2 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/NoRefinePtrTest.java @@ -130,4 +130,25 @@ public class NoRefinePtrTest extends AbstractPtrTest { public void testFlowsToId() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_ID, 8); } + + @Test + public void testFlowsToFields() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { + doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_FIELDS, 6); + } + + @Test + public void testFlowsToFieldsHarder() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { + doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_FIELDS_HARDER, 6); + } + + @Test + public void testFlowsToArraySetIter() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { + doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_ARRAYSET_ITER, 8); + } + + // don't test this until we have a way to handle different library versions +// @Test +// public void testFlowsToHashSet() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { +// doFlowsToSizeTest(TestInfo.FLOWSTO_TEST_HASHSET, 8); +// } } diff --git a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java index a43bb9045..d7c8649fa 100644 --- a/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java +++ b/com.ibm.wala.core.tests/src/com/ibm/wala/core/tests/demandpa/TestInfo.java @@ -99,4 +99,12 @@ public class TestInfo { public static final String FLOWSTO_TEST_ID = "Ldemandpa/FlowsToTestId"; + public static final String FLOWSTO_TEST_FIELDS = "Ldemandpa/FlowsToTestFields"; + + public static final String FLOWSTO_TEST_FIELDS_HARDER = "Ldemandpa/FlowsToTestFieldsHarder"; + + public static final String FLOWSTO_TEST_ARRAYSET_ITER = "Ldemandpa/FlowsToTestArraySetIter"; + + public static final String FLOWSTO_TEST_HASHSET = "Ldemandpa/FlowsToTestHashSet"; + }