Skip to content

Commit f41e566

Browse files
committed
fixed integration test initialization
1 parent 1450737 commit f41e566

File tree

7 files changed

+96
-49
lines changed

7 files changed

+96
-49
lines changed

soot-infoflow-integration/test/soot/jimple/infoflow/collections/test/junit/AliasListTests.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,42 @@
33
import java.util.Collections;
44

55
import org.junit.Assert;
6-
import org.junit.Ignore;
76
import org.junit.Test;
87

98
import soot.jimple.infoflow.IInfoflow;
109
import soot.jimple.infoflow.InfoflowConfiguration;
1110

1211
public class AliasListTests extends FlowDroidTests {
13-
@Override
14-
protected void setConfiguration(InfoflowConfiguration config) {
15-
16-
}
17-
18-
private static final String testCodeClass = "soot.jimple.infoflow.collections.test.AliasListTestCode";
19-
20-
@Test(timeout = 30000)
21-
public void testShiftOnAlias1() {
22-
IInfoflow infoflow = initInfoflow();
23-
infoflow.getConfig().getPathConfiguration().setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
24-
String epoint = "<" + testCodeClass + ": void " + getCurrentMethod() + "()>";
25-
infoflow.computeInfoflow(appPath, libPath, Collections.singleton(epoint), sources, sinks);
26-
Assert.assertEquals(getExpectedResultsForMethod(epoint), infoflow.getResults().size());
27-
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(0)"));
28-
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(1)"));
29-
Assert.assertFalse(containsStmtString(infoflow.getResults(), "get(int)>(2)"));
30-
}
31-
32-
@Test(timeout = 30000)
33-
public void testShiftOnAlias2() {
34-
IInfoflow infoflow = initInfoflow();
35-
infoflow.getConfig().getPathConfiguration().setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
36-
String epoint = "<" + testCodeClass + ": void " + getCurrentMethod() + "()>";
37-
infoflow.computeInfoflow(appPath, libPath, Collections.singleton(epoint), sources, sinks);
38-
Assert.assertEquals(getExpectedResultsForMethod(epoint), infoflow.getResults().size());
39-
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(0)"));
40-
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(1)"));
41-
Assert.assertFalse(containsStmtString(infoflow.getResults(), "get(int)>(2)"));
42-
}
12+
@Override
13+
protected void setConfiguration(InfoflowConfiguration config) {
14+
15+
}
16+
17+
private static final String testCodeClass = "soot.jimple.infoflow.collections.test.AliasListTestCode";
18+
19+
@Test(timeout = 30000)
20+
public void testShiftOnAlias1() {
21+
IInfoflow infoflow = initInfoflow();
22+
infoflow.getConfig().getPathConfiguration()
23+
.setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
24+
String epoint = "<" + testCodeClass + ": void " + getCurrentMethod() + "()>";
25+
infoflow.computeInfoflow(appPath, libPath, Collections.singleton(epoint), sources, sinks);
26+
Assert.assertEquals(getExpectedResultsForMethod(epoint), infoflow.getResults().size());
27+
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(0)"));
28+
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(1)"));
29+
Assert.assertFalse(containsStmtString(infoflow.getResults(), "get(int)>(2)"));
30+
}
31+
32+
@Test(timeout = 30000)
33+
public void testShiftOnAlias2() {
34+
IInfoflow infoflow = initInfoflow();
35+
infoflow.getConfig().getPathConfiguration()
36+
.setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
37+
String epoint = "<" + testCodeClass + ": void " + getCurrentMethod() + "()>";
38+
infoflow.computeInfoflow(appPath, libPath, Collections.singleton(epoint), sources, sinks);
39+
Assert.assertEquals(getExpectedResultsForMethod(epoint), infoflow.getResults().size());
40+
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(0)"));
41+
Assert.assertTrue(containsStmtString(infoflow.getResults(), "get(int)>(1)"));
42+
Assert.assertFalse(containsStmtString(infoflow.getResults(), "get(int)>(2)"));
43+
}
4344
}

soot-infoflow-integration/test/soot/jimple/infoflow/collections/test/junit/FlowDroidTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ protected boolean containsStmtString(InfoflowResults res, String substr) {
196196
*
197197
* @return The directory in which the FlowDroid main project is located
198198
*/
199-
public static File getIntegrationRoot() {
200-
File testRoot = new File(".");
201-
if (!new File(testRoot, "src").exists())
199+
public static File getIntegrationRoot() throws IOException {
200+
File testRoot = new File(".").getCanonicalFile();
201+
if (!new File(testRoot, "testAPKs").exists())
202202
testRoot = new File(testRoot, "soot-infoflow-integration");
203-
if (!new File(testRoot, "src").exists())
203+
if (!new File(testRoot, "testAPKs").exists())
204204
throw new RuntimeException(String.format("Test root not found in %s", testRoot.getAbsolutePath()));
205205
return testRoot;
206206
}

soot-infoflow-integration/test/soot/jimple/infoflow/integration/test/junit/river/BaseJUnitTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Collection;
66

77
import org.junit.Before;
8+
import org.junit.BeforeClass;
89

910
import soot.SootMethod;
1011
import soot.jimple.infoflow.AbstractInfoflow;
@@ -35,6 +36,39 @@ protected boolean isEntryPointMethod(SootMethod method) {
3536
}
3637
}
3738

39+
@BeforeClass
40+
public static void setUp() throws IOException {
41+
File f = getIntegrationRoot();
42+
StringBuilder appPathBuilder = new StringBuilder();
43+
addTestPathes(f, appPathBuilder);
44+
45+
File fi = new File(f, "../soot-infoflow");
46+
if (!fi.getCanonicalFile().equals(f.getCanonicalFile())) {
47+
addTestPathes(fi, appPathBuilder);
48+
}
49+
fi = new File(f, "../soot-infoflow-summaries");
50+
if (!fi.getCanonicalFile().equals(f.getCanonicalFile())) {
51+
addTestPathes(fi, appPathBuilder);
52+
}
53+
fi = new File("soot-infoflow");
54+
if (fi.exists()) {
55+
addTestPathes(fi, appPathBuilder);
56+
}
57+
fi = new File("soot-infoflow-summaries");
58+
if (fi.exists()) {
59+
addTestPathes(fi, appPathBuilder);
60+
}
61+
appPath = appPathBuilder.toString();
62+
63+
StringBuilder libPathBuilder = new StringBuilder();
64+
addRtJarPath(libPathBuilder);
65+
libPath = libPathBuilder.toString();
66+
if (libPath.isEmpty())
67+
throw new RuntimeException("Could not find rt.jar!");
68+
69+
initializeSourceSinks();
70+
}
71+
3872
@Before
3973
public void resetSootAndStream() throws IOException {
4074
soot.G.reset();

soot-infoflow-integration/test/soot/jimple/infoflow/integration/test/junit/river/RiverBaseJUnitTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import soot.jimple.infoflow.InfoflowConfiguration;
44

55
public abstract class RiverBaseJUnitTests extends BaseJUnitTests {
6-
7-
@Override
8-
protected void setConfiguration(InfoflowConfiguration config) {
9-
config.setAdditionalFlowsEnabled(true);
10-
config.getPathConfiguration().setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
11-
}
12-
6+
7+
@Override
8+
protected void setConfiguration(InfoflowConfiguration config) {
9+
config.setAdditionalFlowsEnabled(true);
10+
config.getPathConfiguration().setPathReconstructionMode(InfoflowConfiguration.PathReconstructionMode.Fast);
11+
}
12+
1313
}

soot-infoflow-summaries/test/soot/jimple/infoflow/test/methodSummary/junit/BaseSummaryTaintWrapperTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.Assert.fail;
66

77
import java.io.File;
8-
import java.io.FileNotFoundException;
98
import java.io.IOException;
109
import java.util.ArrayList;
1110
import java.util.Arrays;
@@ -94,7 +93,7 @@ private void checkInfoflow(IInfoflow infoflow, int resultCount) {
9493

9594
protected abstract AbstractInfoflow createInfoflowInstance();
9695

97-
protected IInfoflow initInfoflow() throws FileNotFoundException, XMLStreamException {
96+
protected IInfoflow initInfoflow() throws IOException, XMLStreamException {
9897
IInfoflow result = createInfoflowInstance();
9998
result.getConfig().getAccessPathConfiguration().setUseRecursiveAccessPaths(false);
10099
IInfoflowConfig testConfig = new IInfoflowConfig() {
@@ -190,10 +189,18 @@ private static void appendWithSeparator(StringBuilder sb, File f) throws IOExcep
190189
*
191190
* @return The directory in which StubDroid is located
192191
*/
193-
public static File getTestRoot() {
194-
File testRoot = new File(".");
195-
if (!new File(testRoot, "testSummaries").exists())
196-
testRoot = new File(testRoot, "soot-infoflow-summaries");
192+
public static File getTestRoot() throws IOException {
193+
File testRoot = new File(".").getCanonicalFile();
194+
if (!new File(testRoot, "testSummaries").exists()) {
195+
// Try a subfolder
196+
File subFolder = new File(testRoot, "soot-infoflow-summaries");
197+
if (subFolder.exists())
198+
testRoot = subFolder;
199+
else {
200+
// Try a sibling folder
201+
testRoot = new File(testRoot.getParentFile(), "soot-infoflow-summaries");
202+
}
203+
}
197204
if (!new File(testRoot, "testSummaries").exists())
198205
throw new RuntimeException(String.format("Test root not found in %s", testRoot.getAbsolutePath()));
199206
return testRoot;

soot-infoflow-summaries/test/soot/jimple/infoflow/test/methodSummary/junit/HierarchyTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.Assert.assertTrue;
55

66
import java.io.File;
7+
import java.io.IOException;
78
import java.util.Collection;
89
import java.util.List;
910
import java.util.Set;
@@ -18,7 +19,7 @@ public class HierarchyTests {
1819
protected final IMethodSummaryProvider testProvider;
1920
protected final IMethodSummaryProvider manualProvider;
2021

21-
public HierarchyTests() {
22+
public HierarchyTests() throws IOException {
2223
File testRoot = BaseSummaryTaintWrapperTests.getTestRoot();
2324
testProvider = new EagerSummaryProvider(new File(testRoot, "testSummaries"));
2425
manualProvider = new EagerSummaryProvider(new File(testRoot, "summariesManual"));

soot-infoflow/test/soot/jimple/infoflow/test/junit/JUnitTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public static void setUp() throws IOException {
9090
if (libPath.isEmpty())
9191
throw new RuntimeException("Could not find rt.jar!");
9292

93+
initializeSourceSinks();
94+
}
95+
96+
protected static void initializeSourceSinks() {
9397
sources = new ArrayList<String>();
9498
sources.add(sourcePwd);
9599
sources.add(sourceUserData);

0 commit comments

Comments
 (0)