Commit 96791ef1 authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

adding test suite minimalization

parent 38f38283
......@@ -218,7 +218,8 @@ public class G2 {
target.refine() ;
worklist.evaluateAndPutBack(target) ;
target.saveSuite() ;
// target.saveSuite() ;
target.saveMinimizedSuite();
return 0 ;
}
).count() ; // use count to force the map to be executed
......
......@@ -26,6 +26,7 @@ import java.util.logging.Logger;
import Sequenic.T3.CONSTANTS;
import Sequenic.T3.Pool;
import Sequenic.T3.T3Random;
import Sequenic.T3.Sequence.Datatype.SEQ;
import Sequenic.T3.Sequence.Datatype.SUITE;
......@@ -260,17 +261,79 @@ public class SingleTarget {
return ;
}
/**
* Return a minimized version of the current test suite.
*/
SUITE minimize() {
if (suite==null) {
t3log.warning("Test suite minimalization is asked to minimize a null SUITE");
return null ;
}
if (g2sg.codeCoverage == null) {
// cannot minimize without code coverage guidance
t3log.warning("Test suite minimalization is ignored because Jacoco instrumentation fails or is not present.");
return suite ;
}
SUITE S = new SUITE(suite.CUTname) ;
S.suitename = suite.suitename ;
List<SEQ> dropped = new LinkedList<SEQ>() ;
try { double overallCov = 0.0 ;
double targetCov = 0.0 ;
Pool pool = new Pool() ;
g2sg.codeCoverage.clear();
for (SEQ seq : suite.suite) {
try { seq.exec(g2sg.scope.CUT,pool) ;
g2sg.codeCoverage.collectRTdata();
g2sg.codeCoverage.analyze() ;
double cc = getFreshClassCoverage() ;
double tc = getFreshTargetCoverage() ;
if (cc > overallCov || tc > targetCov) {
S.suite.add(seq) ;
overallCov = cc ;
targetCov = tc ;
}
else dropped.add(seq) ;
}
catch (Exception e) { /* the test sequence crashes ... don't add it */ }
}
}
catch(Exception e) { /* coverage instrumentation fails */
t3log.warning("Test suite minimalization is ignored because Jacoco instrumentation fails.");
return suite ;
}
int ND = dropped.size() ;
// put back about 10% of dropped suite:
int putback = ND/10 ;
for (int k=0; k<putback; k++) {
int i = T3Random.getRnd().nextInt(dropped.size()) ;
S.suite.add(dropped.get(i)) ;
dropped.remove(i) ;
}
t3log.info("Constructing a minimized SUITE: from #" + suite.suite.size() + " to #" + S.suite.size());
return S ;
}
/**
* Save the suite S to a trace file. Generate a JUnit class wrapper if requested.
* Swallow exception!
*/
public void saveSuite() {
public void saveSuite() { saveSuiteWorker(suite) ; }
/**
* First minimize the suite before saving it.
*/
public void saveMinimizedSuite() { saveSuiteWorker(minimize()) ; }
private void saveSuiteWorker(SUITE S) {
if (config.dirToSaveSuites == null) return ;
if (suite == null) return ;
if (S == null) return ;
try {
String trname = "trace_" + suite.suitename ;
// save the suite:
String traceFilePath = suite.save(config.dirToSaveSuites, trname, false);
String traceFilePath = S.save(config.dirToSaveSuites, trname, false);
if (config.generateJunitForEachSuite) {
String testClassName = "Test_" + suite.suitename ;
......@@ -282,7 +345,7 @@ public class SingleTarget {
}
t3log.info("=== Saving suite for " + getName() + "(" + getNumOfParams() + ")"
+ ", iteration:" + numberOfIterations()
+ ", #size:" + suite.suite.size()
+ ", #size:" + S.suite.size()
+ ", tcov:" + getLastTargetCov()
+ ", ccov:" + getLastClassCov()
);
......@@ -290,7 +353,7 @@ public class SingleTarget {
}
catch(Exception e) {
e.printStackTrace();
t3log.warning("Problem in saving test suite " + suite.suitename + ", or its JUnit testclass.");
t3log.warning("Problem in saving test suite " + S.suitename + ", or its JUnit testclass.");
}
}
......
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