Commit 38f38283 authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

adding modes to G2 to run without coverage guidance and without static info.

parent 8b6852fd
......@@ -103,7 +103,7 @@ public class G2 {
*/
protected G2(String CUTname, G2Config config) throws Exception {
this.config = config ;
g2sg = new G2SuiteGen(CUTname,config.CUTrootDir,config.dirOfStaticInfo) ;
g2sg = new G2SuiteGen(CUTname,config.CUTrootDir, config.useCoverageGuidance,config.useStaticInfo,config.dirOfStaticInfo) ;
g2sg.regressionMode = config.regressionMode ;
g2sg.injectOracles = config.injectOracles ;
......@@ -198,9 +198,10 @@ public class G2 {
double remaining = timebudgetTracker.check() ;
t3log.info("Start generating suites for: " + g2sg.scope.CUT.getName());
while (!worklist.isEmpty()) {
if (worklist.targets.isEmpty()) {
if (worklist.targets.size() < config.numberOfCPUcores) {
// the first time, this will generate the prefixes, upon the next iterations,
// this will refine the prefixes each time the targetlist is emptied.
// this will refine the prefixes each time the targetlist is emptied (more precisely, has less targets than
// the number of cores).
refinePrefixes() ;
}
......
......@@ -11,6 +11,18 @@ public class G2Config {
public boolean injectOracles = true ;
public String refinementHeuristic = "random" ;
/**
* If true (default) that will in principle only add new test sequences to the current suite if they improve
* coverage. If false, will refine suites with randomly generated new sequences, disregarding coverage.
*/
public boolean useCoverageGuidance = true ;
/**
* If true (default) will read a file containing lists of constants exctracted from the CUT.
* If false will ignore such a file.
*/
public boolean useStaticInfo = true ;
/**
* If not null, will determine the number of prefixes that will be generated for
* ADT testing. If it is left null, it will be calculated. The default is null.
......
......@@ -61,6 +61,14 @@ public class G2SuiteGen {
// multi-core is currently not supported for this generator!
private final boolean isSingleCore = true ;
// If true (default) that will in principle only add new test sequences to the current suite if they improve
// coverage. If false, will refine suites with randomly generated new sequences, disregarding coverage.
public boolean useCoverageGuidance = true ;
// If true (default) will read a file containing lists of constants exctracted from the CUT.
// If false will ignore such a file.
public boolean useStaticInfo = true ;
public Pool pool ;
private G2ValueMG gen2vmg ;
private Generator<PARAM,STEP> valueMG ;
......@@ -76,7 +84,7 @@ public class G2SuiteGen {
String CUTrootDir)
throws Exception
{
this(CUTname,CUTrootDir,null) ;
this(CUTname,CUTrootDir,true,true,null) ;
}
/**
......@@ -86,12 +94,16 @@ public class G2SuiteGen {
*/
public G2SuiteGen(String CUTname,
String CUTrootDir,
boolean useCoverageGuidance,
boolean useStaticInfo,
String staticInfoDir)
throws Exception
{
//t3log.info("** CUT = " + CUT.getName());
Class CUT ;
if (CUTrootDir != null) {
this.useCoverageGuidance = useCoverageGuidance ;
this.useStaticInfo = useStaticInfo ;
if (CUTrootDir != null && useCoverageGuidance) {
try {
JacocoInstrumenter ji = new JacocoInstrumenter(CUTrootDir,CUTname) ;
codeCoverage = new CodeCoverage(ji) ;
......@@ -158,16 +170,20 @@ public class G2SuiteGen {
catch(Exception e) {
t3log.warning("Fail to read imap.txt in " + staticInfoDir);
}
try {
staticInfo = new StaticInfo(scope,imap,staticInfoDir) ;
t3log.info("Staticinfo.txt read, #constants="
+ staticInfo.allConstants.length
+ ", #instanceOfs="
+ staticInfo.allInstanceOfClasses.length);
if (useStaticInfo) {
try {
staticInfo = new StaticInfo(scope,imap,staticInfoDir) ;
t3log.info("Staticinfo.txt read, #constants="
+ staticInfo.allConstants.length
+ ", #instanceOfs="
+ staticInfo.allInstanceOfClasses.length);
}
catch (IOException e) {
t3log.warning("Fail to read staticinfo.txt in " + staticInfoDir);
}
}
catch (IOException e) {
t3log.warning("Fail to read staticinfo.txt in " + staticInfoDir);
}
else t3log.warning("G2 is configured to ignore staticinfo.txt, so it does.");
}
// setup value generator, and custom pool:
......
......@@ -39,7 +39,10 @@ public class G2_forSBST2016 {
String worklisttype,
String refinementHeuristic,
int maxNumberOfTargetRefinements,
int numberOfcores
int numberOfcores,
boolean turnOnCoverageGuidance,
boolean turnOnUseOfStaticInfo
) throws TimeBudgetException, InterruptedException {
TimeOut hardtimeOut = new TimeOut(timebudget+10000) ;
hardtimeOut.start();
......@@ -56,6 +59,8 @@ public class G2_forSBST2016 {
config.refinementHeuristic = refinementHeuristic ;
config.maxNumberOfRefinements_ofEachTarget = maxNumberOfTargetRefinements ;
config.numberOfCPUcores = numberOfcores ;
config.useCoverageGuidance = turnOnCoverageGuidance ;
config.useStaticInfo = turnOnUseOfStaticInfo ;
G2.generateSuites(CUTname, config, timebudget) ;
System.exit(-1);
}
......@@ -81,14 +86,22 @@ public class G2_forSBST2016 {
* arg7 trace-refinement-heuristic: random/evo
* arg8 the maximum number of times each test-target will be refined
* arg9 number of CPU cores
* arg10 whether or not to use code-coverage guidance
* arg11 whether or not to use staticinfo.txt
*/
static public void main(String[] args) throws Throwable {
if (args[0].equals("generate")) {
if (args.length != 10) throw new IllegalArgumentException() ;
if (args.length != 12) throw new IllegalArgumentException() ;
long timebudget = Integer.parseInt(args[5]) ;
int maxNumberOfTargetRefinements = Integer.parseInt(args[8]) ;
int numOfCores = Integer.parseInt(args[9]) ;
generate(args[1],args[2],args[3],args[4],timebudget, args[6], args[7], maxNumberOfTargetRefinements, numOfCores) ;
boolean useCoverageGuide = Boolean.parseBoolean(args[10]) ;
boolean useStaticInfo = Boolean.parseBoolean(args[11]) ;
generate(args[1],args[2],args[3],args[4],timebudget, args[6], args[7],
maxNumberOfTargetRefinements,
numOfCores,
useCoverageGuide,
useStaticInfo) ;
return ;
}
if (args[0].equals("replayall")) {
......
......@@ -24,16 +24,16 @@ public class StaticInfo {
TestingScope scope ;
ImplementationMap imap ;
private List<String> allConstants_ = new LinkedList<String>() ;
String[] allConstants ;
String[] allConstants = {} ;
private List<String> constantsOfPrivateMethods_ = new LinkedList<String>() ;
String[] constantsOfPrivateMethods ;
String[] constantsOfPrivateMethods = {} ;
private Map<Object,List<String>> constants_ = new HashMap<Object,List<String>>() ;
// mapping methods and constructors to constants
Map<Object,String[]> constants = new HashMap<Object,String[]>() ;
private List<Class> allInstanceOfClasses_ = new LinkedList<Class>() ;
Class[] allInstanceOfClasses ;
Class[] allInstanceOfClasses = {} ;
private List<Class> instanceOfClassesOfPrivateMethods_ = new LinkedList<Class>() ;
Class[] instanceOfClassesOfPrivateMethods ;
Class[] instanceOfClassesOfPrivateMethods = {} ;
private Map<Object,List<Class>> instanceOfClasses_ = new HashMap<Object,List<Class>>() ;
// mapping methods and constructors to instanceof-classes
Map<Object,Class[]> instanceOfClasses = new HashMap<Object,Class[]>() ;
......@@ -51,6 +51,12 @@ public class StaticInfo {
readConstants(dir) ;
}
//public StaticInfo(TestingScope scope, ImplementationMap imap) throws IOException {
// this.CUT = scope.CUT ;
// this.scope = scope ;
// this.imap = imap ;
//}
/**
* Read the constants info from an info-file.
* NOTE: the algorithm assumes the constants are arranged in lines; thus assuming
......
......@@ -9,7 +9,7 @@ public class Test_G2SuiteGen_forCUTwith_constants {
static void genWithG2() throws Exception{
String staticInfoDir = "/Users/iswbprasetya/tmp/t3" ;
Class CUT = Sequenic.T3.Examples.IncomeTax.class ;
G2SuiteGen g2 = new G2SuiteGen(CUT.getName(),null,staticInfoDir) ;
G2SuiteGen g2 = new G2SuiteGen(CUT.getName(),null,true,true,staticInfoDir) ;
g2.maxSuffixLength = 0 ;
g2.regressionMode = true ;
int N0 = Math.min(500, Math.max(10, g2.staticInfo.allConstants.length * 20)) ;
......
......@@ -674,8 +674,8 @@ public class SUITE implements Serializable {
pw.write(" catch (Exception e) { } }\n") ;
pw.write(" } ;\n") ;
pw.write(" suiterunner.start() ;\n") ;
// wait 60 ms -- hard wired here:
pw.write(" try { mainthread.sleep(60000); log.warning(\"** JUnit's test suite execution has TIMED OUT.\"); }\n") ;
// wait 10s -- hard wired here:
pw.write(" try { mainthread.sleep(10000); log.warning(\"** JUnit's test suite execution has TIMED OUT.\"); }\n") ;
pw.write(" catch (Exception e) { log.warning(\"Test suite execution is done.\"); }") ;
pw.write(" }\n\n") ;
// test-1
......@@ -683,7 +683,7 @@ public class SUITE implements Serializable {
pw.write(" public void test1() throws Exception {\n") ;
pw.write(" if (info==null) { log.info(\"NO VERDICT.\"); return ; } \n");
pw.write(" boolean verdict = !info.seenCrash() ;\n");
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL\") ;\n") ;
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL xxxxxxxxxxxx \") ;\n") ;
pw.write(" assertTrue(verdict) ;\n");
pw.write(" }\n\n") ;
// test-2
......@@ -691,7 +691,7 @@ public class SUITE implements Serializable {
pw.write(" public void testExceptionTypeOnly() throws Exception {\n") ;
pw.write(" if (info==null) { log.info(\"NO VERDICT.\"); return ; } \n");
pw.write(" boolean verdict = info.inconsistentExc.isEmpty() ;\n");
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL\") ;\n") ;
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL xxxxxxxxxxxx \") ;\n") ;
pw.write(" assertTrue(verdict) ;\n");
pw.write(" }\n\n") ;
// test-3
......@@ -699,7 +699,7 @@ public class SUITE implements Serializable {
pw.write(" public void testAllOracles() throws Exception {\n") ;
pw.write(" if (info==null) { log.info(\"NO VERDICT.\"); return ; } \n");
pw.write(" boolean verdict = info.violating.isEmpty() ;\n");
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL\") ;\n") ;
pw.write(" if (verdict) log.info(\"PASS\") ; else log.info(\"FAIL xxxxxxxxxxxx \") ;\n") ;
pw.write(" assertTrue(verdict) ;\n");
pw.write(" }\n") ;
pw.write("}") ;
......
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