Commit 632508d0 authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

adding more statistics tracking to G2; tweaking G2 jandling of ADT-method to...

adding more statistics tracking to G2; tweaking G2 jandling of ADT-method to make it refined based on selected prefixes rather than all prefixes.
parent c88f7dad
......@@ -146,7 +146,7 @@ public class G2 {
SingleTarget t ;
if (config.refinementHeuristic.equals("evo")) t = new EvoSingleTarget(config,g2sg,co) ;
else t = new SingleTarget(config,g2sg,co) ;
//worklist.addTarget(t);
worklist.addTarget(t);
}
for (Method m : g2sg.scope.methods) {
if (Modifier.isStatic(m.getModifiers())) continue ;
......@@ -207,6 +207,7 @@ public class G2 {
int prefixRefinementCount = 0 ;
int prefixStagnationCount = 0 ;
int stagnationLimit = 3 ;
int topIterationCount = 0 ; // counting target-refinement
boolean generateMorePrefix = worklist.hasADTtarget() ;
while (!worklist.isEmpty()) {
if (generateMorePrefix && prefixStagnationCount < stagnationLimit) {
......@@ -218,7 +219,7 @@ public class G2 {
// reset this flag to false:
generateMorePrefix = false ;
if (numOfAddedPrefixes==null) {
// cannot generate prefixes because CUT has no constructor/factory,
// g2sg signaled that it cannot generate prefixes because CUT has no constructor/factory,
// we should now remove all ADT targets because we can't solve them anyway
worklist.removeADTtargets();
t3log.info("Since " + g2sg.scope.CUT.getName() + " can't be instantiated, we now DROP all ADT targets.") ;
......@@ -234,7 +235,9 @@ public class G2 {
}
if (g2sg.currentPrefixes != null) {
// generating some analytics data
String savedir = "/Users/iswbprasetya/tmp/t3" ;
DataTable dt_prefixcov = new DataTable(1,DataTable.DOUBLE) ;
......@@ -268,6 +271,7 @@ public class G2 {
);
}
}
// pick a target and refine:
SingleTarget target = worklist.getNext(remaining/budget) ;
int sizeOld = 0 ;
if (target.suite != null && target.suite.suite != null) sizeOld = target.suite.suite.size() ;
......@@ -284,13 +288,33 @@ public class G2 {
// only save if the new suite is larger:
if (sizeNew > sizeOld) target.saveSuite() ;
if (quality == TargetQuality.STAGNATE)
t3log.info("Refinement for " + target.getName() + " has STAGNATED; it will not be further refined.");
// save a minimized version of the test suite; however this seem to drop
// mutation kill rates in some situation; so I will just comment this out.
// Will later make it configurable.
//target.saveMinimizedSuite();
if (quality == TargetQuality.STAGNATE)
t3log.info("Refinement for " + target.getName() + " has STAGNATED; it will not be further refined.");
topIterationCount++ ;
// Reporting some statistics
String s = "Worklist iteration " + topIterationCount + "\n";
double totTargetConv = 0d ;
for(SingleTarget ST : worklist.allTargets) {
int size = 0 ;
double tcov = ST.getLastTargetCov() ;
totTargetConv += tcov ;
if (ST.suite != null) size = ST.suite.suite.size() ;
s += " " + ST.getName() + "_" + ST.getNumOfParams()
+ ", generation:" + ST.numberOfIterations()
+ ", seqs-tried:" + ST.totNumberOfTriedSequences
+ ", size:" + size
+ ", cov:" + tcov + "\n" ;
}
totTargetConv = totTargetConv / (double) worklist.allTargets.size();
s += "Tot. target coverage:" + totTargetConv ;
t3log.info(s);
remaining = timebudgetTracker.check() ;
}
}
......
......@@ -50,7 +50,7 @@ public class G2Config {
* does not require a prefix. If null then this will be calculated. The default
* is null.
*/
public Integer singeMethodTestSuiteSize = null ;
public Integer singleMethodTestSuiteSize = null ;
public String dirToSaveSuites = null ;
public String dirToSaveJunit = null ;
......
......@@ -52,6 +52,9 @@ public class SingleTarget {
public List<Double> targetcov;
public List<Double> classcov;
// for additional statistics:
public int totNumberOfTriedSequences = 0 ;
static protected Logger t3log = Logger.getLogger(CONSTANTS.T3loggerName) ;
protected SingleTarget(){}
......@@ -126,25 +129,49 @@ public class SingleTarget {
if (isADT) {
// g2sg.scope.configureForADTtesting(); this will be done in the generate below
SUITE prefixes = g2sg.getPrefixes() ;
// take a selection of these prefixes:
SUITE selected = prefixes ;
int selectedMaxSize = 50 ;
if (prefixes != null && prefixes.suite.size() > selectedMaxSize) {
selected = new SUITE() ;
selected.suitename = prefixes.suitename ;
selected.CUTname = prefixes.CUTname ;
int K = selectedMaxSize/3 ;
SEQ[] array_ = prefixes.suite.toArray(new SEQ[0]) ;
int N = array_.length ;
// always include the last selectedMaxSize/3, since these are more recently added
for (int k=0; k<K; k++) {
selected.suite.add(array_[N-k-1]) ;
}
// randomly select the rest:
for (int k=K; k<N; k++) {
selected.suite.add(array_[T3Random.getRnd().nextInt(N-K)]) ;
}
}
int multiplier = 2 ;
return g2sg.generateSuiteForASingleMethod(prefixes,m,multiplier) ;
if (selected != null) totNumberOfTriedSequences += multiplier*selected.suite.size() ;
return g2sg.generateSuiteForASingleMethod(selected,m,multiplier) ;
}
else {
// g2sg.scope.configureForNonADTTesting(); this will be done in the generate below
Integer N = config.singeMethodTestSuiteSize ;
Integer N = config.singleMethodTestSuiteSize ;
if (N == null) {
N = Math.max(50,power(4,m.getParameterCount())) ;
}
totNumberOfTriedSequences += N ;
return g2sg.generateSuiteForASingleStaticMethod(m,N) ;
}
}
// else target is a constructor
// g2sg.scope.configureForADTtesting(); ; this will be done in the generate below
Constructor co = (Constructor) target ;
Integer N = config.singeMethodTestSuiteSize ;
Integer N = config.singleMethodTestSuiteSize ;
if (N == null) {
N = Math.max(50,power(4,co.getParameterCount())) ;
}
totNumberOfTriedSequences += N ;
return g2sg.generateSuiteForConstructor(co,N) ;
}
......
......@@ -38,7 +38,7 @@ public class Test_G2_forTriangle {
}
static void genWithG2() throws Exception {
G2.generateSuites("Sequenic.T3.Examples.Triangle1",config(),3000000) ;
G2.generateSuites("Sequenic.T3.Examples.Triangle1",config(),60000) ;
}
public static void replayG2() throws Throwable {
......
......@@ -30,7 +30,11 @@ import java.util.Random;
*/
public class Worklist {
protected List<SingleTarget> targets = new LinkedList<SingleTarget>() ;
// all the targets, including those that have been processed. We keep
// the for e.g. collecting statistics.
protected List<SingleTarget> allTargets = new LinkedList<SingleTarget>() ;
protected List<SingleTarget> activeTargets = new LinkedList<SingleTarget>() ;
protected List<SingleTarget> waiting = new LinkedList<SingleTarget>() ;
protected Random rnd = new Random() ;
......@@ -64,7 +68,7 @@ public class Worklist {
int Nmax = target.maxNumberOfRefinement ;
if (Nmax > 1) {
double loweringCorrection = Math.max(0,1.0 - progressiveMinimumCoverage)/(double)(Nmax - 1) ;
progressiveMinimumCoverage += 1d - (double) target.numberOfIterations()*loweringCorrection ;
progressiveMinimumCoverage = 1d - (double) target.numberOfIterations()*loweringCorrection ;
}
if (target.getLastTargetCov() >= progressiveMinimumCoverage)
return TargetQuality.GOOD_ENOUGH ;
......@@ -78,7 +82,10 @@ public class Worklist {
* (it should be added to the waiting list, not to the target list immediately)
*/
public void addTarget(SingleTarget target) { waiting.add(target) ; }
public void addTarget(SingleTarget target) {
allTargets.add(target) ;
waiting.add(target) ;
}
/**
* Check if the target is already good enough. If so, return true. If not,
......@@ -91,17 +98,17 @@ public class Worklist {
return quality ;
}
public boolean isEmpty() { return targets.isEmpty() && waiting.isEmpty() ; }
public boolean isEmpty() { return activeTargets.isEmpty() && waiting.isEmpty() ; }
public boolean hasADTtarget() {
return targets.stream().anyMatch(T -> T.isADT) || waiting.stream().anyMatch(T -> T.isADT) ;
return activeTargets.stream().anyMatch(T -> T.isADT) || waiting.stream().anyMatch(T -> T.isADT) ;
}
/**
* Remove all ADT targets (e.g. because we can't generate prefixes).
*/
public void removeADTtargets() {
targets.removeIf(T -> T.isADT) ;
activeTargets.removeIf(T -> T.isADT) ;
waiting.removeIf(T -> T.isADT) ;
}
......@@ -119,30 +126,30 @@ public class Worklist {
*/
public SingleTarget getNext(double remainingTimeBudget) {
if (isEmpty()) return null ;
if (targets.isEmpty()) {
targets.addAll(waiting) ;
if (activeTargets.isEmpty()) {
activeTargets.addAll(waiting) ;
waiting.clear();
sort() ;
}
if (remainingTimeBudget >= 0.5) {
int k = rnd.nextInt(targets.size()) ;
SingleTarget T = targets.remove(k) ;
int k = rnd.nextInt(activeTargets.size()) ;
SingleTarget T = activeTargets.remove(k) ;
return T ;
}
SingleTarget T = targets.remove(0) ;
SingleTarget T = activeTargets.remove(0) ;
return T ;
}
protected void sort() {
SingleTarget[] ts = targets.toArray(new SingleTarget[0]) ;
targets.clear() ;
SingleTarget[] ts = activeTargets.toArray(new SingleTarget[0]) ;
activeTargets.clear() ;
int N = ts.length ;
for (int i=0; i<N ; i++) {
int best = i ;
for (int j=i ; j<N ; j++) {
if (isFavoredOver(ts[j],ts[best])) best = j ;
}
targets.add(ts[best]) ;
activeTargets.add(ts[best]) ;
SingleTarget tmp = ts[i] ;
ts[i] = ts[best] ; ts[best] = tmp ;
}
......
......@@ -29,12 +29,12 @@ public class WorklistLowcovFirst extends Worklist {
@Override
public SingleTarget getNext(double remainingTimeBudget) {
if (isEmpty()) return null ;
if (targets.isEmpty()) {
targets.addAll(waiting) ;
if (activeTargets.isEmpty()) {
activeTargets.addAll(waiting) ;
waiting.clear();
sort() ;
}
return targets.remove(0) ;
return activeTargets.remove(0) ;
}
}
......@@ -26,11 +26,11 @@ public class WorklistRandom extends Worklist {
@Override
public SingleTarget getNext(double remainingTimeBudget) {
if (isEmpty()) return null ;
if (targets.isEmpty()) {
targets.addAll(waiting) ;
if (activeTargets.isEmpty()) {
activeTargets.addAll(waiting) ;
waiting.clear() ;
}
return targets.remove(rnd.nextInt(targets.size())) ;
return activeTargets.remove(rnd.nextInt(activeTargets.size())) ;
}
......
......@@ -11,50 +11,50 @@ public class Triangle1 implements Serializable {
public Triangle1(){
System.out.println("*** Triangle()") ;
//System.out.println("*** Triangle()") ;
}
public void setX(float x) {
System.out.println("* setX " + x) ;
//System.out.println("* setX " + x) ;
if (x<=0) throw new IllegalArgumentException() ;
this.x = x ;
}
public void setY(float y) {
System.out.println("* setY " + y) ;
//System.out.println("* setY " + y) ;
if (y<=0) throw new IllegalArgumentException() ;
this.y = y ;
}
public void setZ(float z) {
System.out.println("* setZ " + z) ;
//System.out.println("* setZ " + z) ;
if (z<=0) throw new IllegalArgumentException() ;
this.z = z ;
}
public boolean isTriangle() {
System.out.println("* isTriangle") ;
//System.out.println("* isTriangle") ;
if (x >= y+z) return false ;
if (y >= x+z) return false ;
return z < x+y ;
}
public boolean isIsoleces() {
System.out.println("* isIsoleces") ;
//System.out.println("* isIsoleces") ;
if (x==y) return true ;
if (y==z) return true ;
if (x==z) return true ;
return false ;
}
public boolean isEquilateral() {
System.out.println("* isEquilateral") ;
//System.out.println("* isEquilateral") ;
return (x==y) && (y==z) ;
}
public boolean isScalene() {
System.out.println("* isEquilateral") ;
//System.out.println("* isEquilateral") ;
return ! isIsoleces() ;
}
@Override
public boolean equals(Object o) {
System.out.println("* equals") ;
//System.out.println("* equals") ;
if (o instanceof Triangle1) {
//if (o != this) System.out.println(">>> o is NOT this!") ;
//else System.out.println(">>> o is this!") ;
......@@ -67,7 +67,7 @@ public class Triangle1 implements Serializable {
}
public String toString() {
System.out.println("* toString") ;
//System.out.println("* toString") ;
return "Triangle: " + x + "/" + y + "/" + z ;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment