Skip to content

Commit

Permalink
enable fast test by loading classes only once
Browse files Browse the repository at this point in the history
  • Loading branch information
jay2013 committed Feb 18, 2022
1 parent 65f0b39 commit ef0af2c
Show file tree
Hide file tree
Showing 36 changed files with 172 additions and 267 deletions.
9 changes: 9 additions & 0 deletions qilin.core/src/qilin/core/PTAScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public static PTAScene v() {
return instance;
}

public static void junitReset() {
VirtualCalls.reset();
instance = null;
}

public static void reset() {
G.reset();
VirtualCalls.reset();
Expand Down Expand Up @@ -74,6 +79,10 @@ public Value getFieldGlobalThrow() {
return this.fakeMainFactory.getFieldGlobalThrow();
}

public void setMainClass(SootClass m) {
sootScene.setMainClass(m);
}

/*
* wrapper methods of Soot Scene. Note, we do not allow you to use Soot Scene directly in qilin.qilin.pta subproject
* to avoid confusing.
Expand Down
7 changes: 6 additions & 1 deletion qilin.core/src/qilin/core/builder/FakeMainFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ private List<SootMethod> getEntryPoints() {
}

if (CoreConfig.v().getPtaConfig().singleentry) {
ret.addAll(EntryPoints.v().application());
List<SootMethod> entries = EntryPoints.v().application();
if (entries.isEmpty()) {
throw new RuntimeException("Must specify MAINCLASS when appmode enabled!!!");
} else {
ret.addAll(entries);
}
} else {
System.out.println("include implicit entry!");
ret.addAll(EntryPoints.v().application());
Expand Down
3 changes: 2 additions & 1 deletion qilin.core/src/qilin/core/builder/MethodNodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ final public void caseNewArrayExpr(NewArrayExpr nae) {

@Override
final public void caseNewExpr(NewExpr ne) {
SootClass cl = PTAScene.v().loadClassAndSupport(ne.getType().toString());
RefType refType = (RefType) ne.getType();
SootClass cl = refType.getSootClass();
PTAUtils.clinitsOf(cl).forEach(mpag::addTriggeredClinit);
setResult(pag.heapAbstractor().abstractHeap(ne, ne.getType(), method));
}
Expand Down
4 changes: 2 additions & 2 deletions qilin.core/src/qilin/core/pag/StringConstantNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public String toString() {
}

public String getString() {
if (!(newExpr instanceof String)) {
if (!(newExpr instanceof StringConstant)) {
System.out.println(newExpr + ";;" + newExpr.getClass());
}
return (String) newExpr;
return ((StringConstant) newExpr).value;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion qilin.microben/src/qilin/microben/core/reflog/FieldGet.log

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions qilin.microben/src/qilin/microben/core/reflog/FieldSet.log

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 17 additions & 0 deletions qilin.microben/src/qilin/microben/core/reflog/Reflection.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Array.newInstance;int[];qilin.microben.core.reflog.ArrayNewInstance.main;27;;
Class.forName;qilin.microben.core.reflog.ClassForName;qilin.microben.core.reflog.ClassForName.main;27;;
Class.forName;qilin.microben.core.reflog.ClassForName;qilin.microben.core.reflog.ClassForName.main;29;;
Class.forName;java.lang.Object;qilin.microben.core.reflog.ClassForName.main;31;;
Class.forName;qilin.microben.core.reflog.ClassForName1;qilin.microben.core.reflog.ClassForName1.main;27;;
Class.forName;qilin.microben.core.reflog.ClassForName1;qilin.microben.core.reflog.ClassForName1.main;29;;
Class.forName;java.lang.Object;qilin.microben.core.reflog.ClassForName1.main;31;;
Class.newInstance;qilin.microben.core.reflog.ClassNewInstance;qilin.microben.core.reflog.ClassNewInstance.main;28;;
Constructor.newInstance;<qilin.microben.core.reflog.ConstructorNewInstance: void <init>(java.lang.Object)>;qilin.microben.core.reflog.ConstructorNewInstance.main;35;;
Field.get*;<javax.xml.xpath.XPathConstants: javax.xml.namespace.QName STRING>;qilin.microben.core.reflog.DoopRefBug.main;33;;
Field.get*;<qilin.microben.core.reflog.FieldGet: java.lang.Object f>;qilin.microben.core.reflog.FieldGet.main;30;;
Field.get*;<qilin.microben.core.reflog.FieldGetStatic: java.lang.Object f>;qilin.microben.core.reflog.FieldGetStatic.main;29;;
Field.set*;<qilin.microben.core.reflog.FieldSet: java.lang.Object f>;qilin.microben.core.reflog.FieldSet.main;31;;
Field.set*;<qilin.microben.core.reflog.FieldSet: java.lang.Object f>;qilin.microben.core.reflog.FieldSet.main;32;;
Field.set*;<qilin.microben.core.reflog.FieldSetStatic: java.lang.Object f>;qilin.microben.core.reflog.FieldSetStatic.main;28;;
Method.invoke;<qilin.microben.core.reflog.MethodInvoke: java.lang.Object id(java.lang.Object)>;qilin.microben.core.reflog.MethodInvoke.main;26;;
Method.invoke;<qilin.microben.core.reflog.MethodInvokeStatic: java.lang.Object id(java.lang.Object)>;qilin.microben.core.reflog.MethodInvokeStatic.main;33;;
2 changes: 0 additions & 2 deletions qilin.pta/src/driver/PTAOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ protected void parseCommandLineOptions(CommandLine cmd) {
// application configuration
if (cmd.hasOption("mainclass")) {
PTAConfig.v().getAppConfig().MAIN_CLASS = cmd.getOptionValue("mainclass");
} else if (PTAConfig.v().getPtaConfig().singleentry) {
throw new RuntimeException("Must specify MAINCLASS when appmode enabled!!!");
}
if (cmd.hasOption("jre")) {
PTAConfig.v().getAppConfig().JRE = cmd.getOptionValue("jre");
Expand Down
30 changes: 12 additions & 18 deletions qilin.pta/test/qilin/test/FlowSensTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,38 @@

package qilin.test;

import driver.Main;
import org.junit.Ignore;
import org.junit.Test;
import qilin.test.util.JunitTests;

public class FlowSensTests extends JunitTests {
@Test
public void testLoops() {
String[] args = generateArguments("qilin.microben.flowsens.Loops");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.Loops"));
}

@Test
@Ignore
public void testFlowSens0() {
String[] args = generateArguments("qilin.microben.flowsens.FlowSens0");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.FlowSens0"));
}

@Test
@Ignore
public void testInstanceOf0() {
String[] args = generateArguments("qilin.microben.flowsens.InstanceOf0");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.InstanceOf0"));
}

@Test
@Ignore
public void testBranching1() {
String[] args = generateArguments("qilin.microben.flowsens.Branching1");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.Branching1"));
}

@Test
@Ignore
public void testStrongUpdate1() {
String[] args = generateArguments("qilin.microben.flowsens.StrongUpdate1");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.StrongUpdate1"));
}

@Test
@Ignore
public void testStrongUpdate2() {
String[] args = generateArguments("qilin.microben.flowsens.StrongUpdate2");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.flowsens.StrongUpdate2"));
}
}
13 changes: 4 additions & 9 deletions qilin.pta/test/qilin/test/context/CFATests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@

package qilin.test.context;

import driver.Main;
import org.junit.Test;
import qilin.test.util.JunitTests;

public class CFATests extends JunitTests {

@Test
public void testCFA1k0() {
String[] args = generateArguments("qilin.microben.context.cfa.CFA1k0", "1c");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.cfa.CFA1k0", "1c"));
}

@Test
public void testCFA1k1() {
String[] args = generateArguments("qilin.microben.context.cfa.CFA1k1", "1c");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.cfa.CFA1k1", "1c"));
}

@Test
public void testCFA1k2() {
String[] args = generateArguments("qilin.microben.context.cfa.CFA1k2", "1c");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.cfa.CFA1k2", "1c"));
}

@Test
public void testCFA2k() {
String[] args = generateArguments("qilin.microben.context.cfa.CFA2k", "2c");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.cfa.CFA2k", "2c"));
}
}
31 changes: 10 additions & 21 deletions qilin.pta/test/qilin/test/context/CollectionsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,57 @@

package qilin.test.context;

import driver.Main;
import org.junit.Test;
import qilin.test.util.JunitTests;

public class CollectionsTests extends JunitTests {
@Test
public void testArrayList0() {
String[] args = generateArguments("qilin.microben.context.collections.ArrayList0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.ArrayList0", "2o"));
}

@Test
public void testLinkedList0() {
String[] args = generateArguments("qilin.microben.context.collections.LinkedList0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.LinkedList0", "2o"));
}

@Test
public void testVector0() {
String[] args = generateArguments("qilin.microben.context.collections.Vector0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.Vector0", "2o"));
}

@Test
public void testHashMap0() {
String[] args = generateArguments("qilin.microben.context.collections.HashMap0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.HashMap0", "2o"));
}

@Test
public void testTreeMap0() {
String[] args = generateArguments("qilin.microben.context.collections.TreeMap0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.TreeMap0", "2o"));
}

@Test
public void testHashSet0() {
String[] args = generateArguments("qilin.microben.context.collections.HashSet0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.HashSet0", "3o"));
}

@Test
public void testTreeSet0() {
String[] args = generateArguments("qilin.microben.context.collections.TreeSet0", "3o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.TreeSet0", "3o"));
}

@Test
public void testHashTable0() {
String[] args = generateArguments("qilin.microben.context.collections.HashTable0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.HashTable0", "2o"));
}

@Test
public void testPriorityQueue0() {
String[] args = generateArguments("qilin.microben.context.collections.PriorityQueue0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.PriorityQueue0", "2o"));
}

@Test
public void testStack0() {
String[] args = generateArguments("qilin.microben.context.collections.Stack0", "2o");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.collections.Stack0", "2o"));
}
}
10 changes: 3 additions & 7 deletions qilin.pta/test/qilin/test/context/HybTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,22 @@

package qilin.test.context;

import driver.Main;
import org.junit.Test;
import qilin.test.util.JunitTests;

public class HybTests extends JunitTests {
@Test
public void testHyb0() {
String[] args = generateArguments("qilin.microben.context.hyb.Hyb0", "1h");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.hyb.Hyb0", "1h"));
}

@Test
public void testHyb1() {
String[] args = generateArguments("qilin.microben.context.hyb.Hyb1", "1h");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.hyb.Hyb1", "1h"));
}

@Test
public void testHyb2() {
String[] args = generateArguments("qilin.microben.context.hyb.Hyb2", "2h");
checkAssertions(Main.run(args));
checkAssertions(run("qilin.microben.context.hyb.Hyb2", "2h"));
}
}
Loading

0 comments on commit ef0af2c

Please sign in to comment.