Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions lang-java-reach-soot/src/test/java/SootCallGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ private GoalContext getGoalContext() {
return ctx;
}

private void runSootAnalysis() {
private void runSootAnalysis(String jarPAth) {
final ReachabilityAnalyzer ra = new ReachabilityAnalyzer(this.getGoalContext());
ra.setCallgraphConstructor(SootCallgraphConstructor.FRAMEWORK, false);
// Set classpaths
final Set<Path> app_paths = new HashSet<Path>(), dep_paths = new HashSet<Path>();
app_paths.add(Paths.get("./src/test/resources/examples.jar"));
app_paths.add(Paths.get(jarPAth));
dep_paths.add(Paths.get("./src/test/resources/empty.jar"));
ra.setAppClasspaths(app_paths);
ra.setDependencyClasspaths(dep_paths);
Expand Down Expand Up @@ -111,7 +111,13 @@ public void callgraphServiceRegistered() {
@Test
public void examplesSootTestNoneEntrypointGenerator() {
VulasConfiguration.getGlobal().setProperty("vulas.reach.soot.entrypointGenerator", "none");
runSootAnalysis();
runSootAnalysis("./src/test/resources/examples.jar");
}

@Test
public void examplesSootTestNoneEntrypointGeneratorJDK17() {
VulasConfiguration.getGlobal().setProperty("vulas.reach.soot.entrypointGenerator", "none");
runSootAnalysis("./src/test/resources/examples17.jar");
}

@Test
Expand All @@ -120,7 +126,16 @@ public void examplesSootTestDefaultEntryPointGenerator() {
.setProperty(
"vulas.reach.soot.entrypointGenerator",
"soot.jimple.infoflow.entryPointCreators.DefaultEntryPointCreator");
runSootAnalysis();
runSootAnalysis("./src/test/resources/examples.jar");
}

@Test
public void examplesSootTestDefaultEntryPointGeneratorJDK17() {
VulasConfiguration.getGlobal()
.setProperty(
"vulas.reach.soot.entrypointGenerator",
"soot.jimple.infoflow.entryPointCreators.DefaultEntryPointCreator");
runSootAnalysis("./src/test/resources/examples17.jar");
}

@Test
Expand All @@ -129,6 +144,15 @@ public void examplesSootTestCustomEntryPointGenerator() {
.setProperty(
"vulas.reach.soot.entrypointGenerator",
"org.eclipse.steady.cg.soot.CustomEntryPointCreator");
runSootAnalysis();
runSootAnalysis("./src/test/resources/examples.jar");
}

@Test
public void examplesSootTestCustomEntryPointGeneratorJDK17() {
VulasConfiguration.getGlobal()
.setProperty(
"vulas.reach.soot.entrypointGenerator",
"org.eclipse.steady.cg.soot.CustomEntryPointCreator");
runSootAnalysis("./src/test/resources/examples17.jar");
}
}
63 changes: 63 additions & 0 deletions lang-java-reach-soot/src/test/resources/Examples17.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.sap.psr.vulas.cg.test;

import java.util.SortedSet;
import java.util.TreeSet;

sealed abstract class Animal implements Comparable<Animal> permits Cat, Dog, Fish {

public abstract void saySomething();

public int compareTo(Animal _a) {
return getClass().getName().compareTo(_a.getClass().getName());
}
}

final class Cat extends Animal {
public void saySomething() {
System.out.println("purr");
}
}

final class Dog extends Animal {
public void saySomething() {
System.out.println("woof");
}
}

final class Fish extends Animal {
public void saySomething() {
System.out.println("...");
}
}

class Car {
public void saySomething() {
System.out.println("honk!");
}
}

public class Examples {
static SortedSet<Animal> animals = new TreeSet<>();

private static Animal createFish() {
return new Fish();
}

private static Animal createCat() {
Animal cat = new Cat();
animals.add(cat);
return cat;
}

public static void main(String[] args) {
Animal animal;
if (args.length == 0) {
animal = createCat();
animal.saySomething();
} else {
animal = createFish();
animal.saySomething();
}
}
}

Binary file not shown.