From 4dd34efd30421c722b50ac4a28b0d5a93246d328 Mon Sep 17 00:00:00 2001 From: sarps Date: Thu, 31 Oct 2024 20:49:01 +0100 Subject: [PATCH] Improve wala tests --- .../java/wala/JavaWalaSecurityTestCase.java | 14 +++++++------- .../ares/api/architecture/java/wala/exclusions.txt | 4 ++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/exclusions.txt diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCase.java b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCase.java index a9e3c7bb..b1672e8a 100644 --- a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCase.java +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/JavaWalaSecurityTestCase.java @@ -1,5 +1,6 @@ package de.tum.cit.ase.ares.api.architecture.java.wala; +import com.ibm.wala.classLoader.Language; import com.ibm.wala.core.java11.Java9AnalysisScopeReader; import com.ibm.wala.ipa.callgraph.*; import com.ibm.wala.ipa.callgraph.impl.DefaultEntrypoint; @@ -9,6 +10,7 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException; import com.ibm.wala.ipa.cha.ClassHierarchyFactory; +import java.io.File; import java.io.IOException; import java.util.List; @@ -20,20 +22,18 @@ public class JavaWalaSecurityTestCase { /** * Build a call graph from a class path. */ - public static CallGraph buildCallGraph(String classPath) { + public static CallGraph buildCallGraph(String classPathToConsider, String classPathToAnalyze) { try { - long startTime = System.currentTimeMillis(); - AnalysisScope scope = Java9AnalysisScopeReader.instance.makeJavaBinaryAnalysisScope( - System.getProperty("java.class.path"), - null + classPathToConsider, + new File("src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/exclusions.txt") ); // Build the class hierarchy ClassHierarchy cha = ClassHierarchyFactory.make(scope); // Create a list to store entry points - List customEntryPoints = ReachabilityChecker.getEntryPointsFromStudentSubmission(classPath, cha); + List customEntryPoints = ReachabilityChecker.getEntryPointsFromStudentSubmission(classPathToAnalyze, cha); // Create AnalysisOptions for call graph AnalysisOptions options = new AnalysisOptions(scope, customEntryPoints); @@ -42,7 +42,7 @@ public static CallGraph buildCallGraph(String classPath) { options.setReflectionOptions(AnalysisOptions.ReflectionOptions.NONE); // Create call graph builder (n-CFA, context-sensitive, etc.) - CallGraphBuilder builder = Util.makeNCFABuilder(1, options, new AnalysisCacheImpl(), cha); + CallGraphBuilder builder = Util.makeZeroOneCFABuilder(Language.JAVA, options, new AnalysisCacheImpl(), cha); // Generate the call graph CallGraph callGraph = builder.makeCallGraph(options, null); diff --git a/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/exclusions.txt b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/exclusions.txt new file mode 100644 index 00000000..b06d8027 --- /dev/null +++ b/src/main/java/de/tum/cit/ase/ares/api/architecture/java/wala/exclusions.txt @@ -0,0 +1,4 @@ +java/util/.* +jdk/.* +java/time/.* +java/security/.* \ No newline at end of file