Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Dec 29, 2023
1 parent 09a28ea commit 4b9d854
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
5 changes: 3 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ val collectTestDataA by
includeEmptyDirs = false
destinationDirectory = layout.buildDirectory.dir(name)
exclude(
// This is an invalid class so don't include it, e.g., it causes D8 to crash
"**/CodeDeleted.class",
"**/SortingExample.class",
"**/A.class",
// "**/SortingExample.class",
// "**/A.class",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ private static Set<Pair<CGNode, CGNode>> edgeDiff(

private static void test(String mainClass, String javaScopeFile)
throws IllegalArgumentException, IOException, CancelException, ClassHierarchyException {
test(mainClass, javaScopeFile, false);
}

private static void test(String mainClass, String javaScopeFile, boolean allowExtraJavaCGEdges)
throws IllegalArgumentException, IOException, CancelException, ClassHierarchyException {
Pair<CallGraph, PointerAnalysis<InstanceKey>> java = makeJavaBuilder(javaScopeFile, mainClass);

AnalysisScope javaScope = java.fst.getClassHierarchy().getScope();
Expand All @@ -109,13 +114,15 @@ private static void test(String mainClass, String javaScopeFile)
Set<MethodReference> androidMethods = applicationMethods(android.fst);
Set<MethodReference> javaMethods = applicationMethods(java.fst);

Set<Pair<CGNode, CGNode>> javaExtraEdges =
edgeDiff(java.fst, android.fst, false);
assert !checkEdgeDiff(android, androidMethods, javaMethods, javaExtraEdges) : "found extra edges in Java call graph";
if (!allowExtraJavaCGEdges) {
Set<Pair<CGNode, CGNode>> javaExtraEdges = edgeDiff(java.fst, android.fst, false);
assert !checkEdgeDiff(android, androidMethods, javaMethods, javaExtraEdges)
: "found extra edges in Java call graph";
}

Set<Pair<CGNode, CGNode>> androidExtraEdges =
edgeDiff(android.fst, java.fst, true);
assert !checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges) : "found extra edges in Android call graph";
Set<Pair<CGNode, CGNode>> androidExtraEdges = edgeDiff(android.fst, java.fst, true);
assert !checkEdgeDiff(java, javaMethods, androidMethods, androidExtraEdges)
: "found extra edges in Android call graph";

checkSourceLines(java.fst, android.fst);
}
Expand Down Expand Up @@ -199,31 +206,32 @@ private static boolean checkEdgeDiff(
}
}

// for (CGNode n : firstResult.fst) {
// System.err.println("### " + n);
// if (n.getIR() != null) {
// System.err.println(n.getIR());

// System.err.println("return: " + android.snd.getPointsToSet(new ReturnValueKey(n)));
// System.err.println(
// "exceptions: " + android.snd.getPointsToSet(new ExceptionReturnValueKey(n)));
// for (int i = 1; i < n.getIR().getSymbolTable().getMaxValueNumber(); i++) {
// LocalPointerKey x = new LocalPointerKey(n, i);
// OrdinalSet<InstanceKey> s = android.snd.getPointsToSet(x);
// if (s != null && !s.isEmpty()) {
// System.err.println(i + ": " + s);
// }
// }
// }
// }
// for (CGNode n : firstResult.fst) {
// System.err.println("### " + n);
// if (n.getIR() != null) {
// System.err.println(n.getIR());

// System.err.println("return: " + android.snd.getPointsToSet(new
// ReturnValueKey(n)));
// System.err.println(
// "exceptions: " + android.snd.getPointsToSet(new ExceptionReturnValueKey(n)));
// for (int i = 1; i < n.getIR().getSymbolTable().getMaxValueNumber(); i++) {
// LocalPointerKey x = new LocalPointerKey(n, i);
// OrdinalSet<InstanceKey> s = android.snd.getPointsToSet(x);
// if (s != null && !s.isEmpty()) {
// System.err.println(i + ": " + s);
// }
// }
// }
// }
}
return fail;
}

@Test
public void testJLex()
throws ClassHierarchyException, IllegalArgumentException, IOException, CancelException {
test(TestConstants.JLEX_MAIN, TestConstants.JLEX);
test(TestConstants.JLEX_MAIN, TestConstants.JLEX, true);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static String getJavaJar(AnalysisScope javaScope) throws IOException {

public static File convertJarToDex(String jarFile) throws IOException {
Path tmpDir = Files.createTempDirectory("dex");
//tmpDir.toFile().deleteOnExit();
tmpDir.toFile().deleteOnExit();
try {
D8.run(
D8Command.builder()
Expand Down

0 comments on commit 4b9d854

Please sign in to comment.