package jeiel.experiment; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import Sequenic.T2.TrFile; import Sequenic.T2.Coverage.BasicPath; import Sequenic.T2.Msg.T2Exception; import Sequenic.T2.Seq.Trace; import Sequenic.T2ext.Instrumenter.CFGBunchFile; import Sequenic.T2ext.Maintenance.Reduce; import Sequenic.T2ext.Selection.InterclassGraph; import Sequenic.T2ext.Selection.RegressionTestSelector; import Sequenic.T2ext.Selection.SelectiveRunner; /** * Psubj = ArrayList (others to be added) * Pmut = 1, 2 or 3 * Pid = [1..120] * Tlength = 2,4,8,16 * Tsize = 10,100,1K,10K,100K * Tdup = 1,2,3 //For each length-size size, three duplicates * Timing = 1,2,3 //When timing is important, repeat each subject 3 times * * PRELIMINARY: * -Each test suite, how many tests remain if redundancy is removed? * A: See redundancy.csv * * PRELIMINARY 2: * -Average number of covered prime paths per trace, per test suite * -Average time to load test suite and replay test suite on original program * A: See prelim2.csv * * PRELIMINARY 3: * In ArrayList there are 70 unique prime paths total, in all trace files combined. * The L16_1K trace files cover all unique prime paths. * -For each Pmut*Pid, do RH, BP and BVbroken differ in which prime paths they mark * (1) mod-traversing (2) skip without synthesizing ('pure') (3) synthesize (4) can not synthesize * A: See prelim3.xlsx, othere is only one case, see 3b * Also, case (4), unsynthesizeable paths, do not occur, because no multiply-visited nodes. * Synthesized paths are rare, but do occur. * -Are there any multiply-visited nodes * A: No * * 3b) BVbroken and RH never differ. In one of the modifications (patch 34, e.g. in m1/29) * there is a single different: One path is marked modtrav by BP that is 'pure' skipped by RH/BVbroken * The path is the cycle [1,2,1]. In the method, node 3 is modified. * Any execution of the method must traverse the edge 1 -> 3 in a simple path. * I.e. if cycle [1,2,1] is covered by a trace, then simple path [0,1,3,..] must also be covered. * RH marks (1,3) as dangerous, BP marks the method dangerous. * Consequently, only BP selects cycle [1,2,1]. * Both are safe/correct, prelim3b shows that any trace selected by RH is also selected by BP and vice versa. * * -Are there cost-differences in constructing RH/BP selectors: * A: Not significant, BP is 60% more expensive (1.18ms vs. 0.71ms on average), * but this is insignificant in absolute terms. * Loading the CFGs takes 340 ms, loading trace files and replaying is much more. * * CONCLUSION: No differences between RH, BP and BVbroken * * * EXPERIMENT 1: * How many traces are selected? (Use BP) * How long to replay selected * How long to replay all (necessary?) * How many are obsolete * * Psubj*Pmut*Pid*Tlen*Tsize*Tdup = 21 600, too much... * * * * @author jeiels * */ public class Runner { private static PrintStream out = System.out; static void preliminary() { out.println("file,# of total traces, # unique traces, #non-redundant traces, #unique paths"); final String dir = "./MyArrayList_mutated_versions/originalNtraces/"; String[] list = new File(dir).list(); ArrayList dst = new ArrayList(); try { for(String file : list) { if(!file.startsWith("cov")) continue; out.print(file); TrFile trFile = TrFile.load(dir+file); int total = Reduce.unique(trFile.traces.iterator(), dst); total += dst.size(); out.print(", "+total+", "+dst.size()+", "); dst.clear(); Reduce.minimal(trFile.traces.iterator(), dst); out.println(dst.size()+", "+Reduce.minimal(dst.iterator(), null)); dst.clear(); } } catch (T2Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } static void preliminary2() { out.println("file,# of total traces, # avg paths per trace, load time (ms), replay-all (ms)"); final String dir = "./MyArrayList_mutated_versions/originalNtraces/"; String[] list = new File(dir).list(); try { for(String file : list) { if(!file.startsWith("cov")) continue; out.print(file); long beforeLoad = System.currentTimeMillis(); TrFile trFile = TrFile.load(dir+file); SelectiveRunner runner = new SelectiveRunner(trFile); long afterLoad = System.currentTimeMillis(); int totTraces = runner.runAll(); long afterReplay = System.currentTimeMillis(); long x = 0; for(Trace t : trFile.traces) x += t.coverage().size(); x = x * 1000; x = x / totTraces; double average = x / 1000.0; out.format(", %d, %.2f, %d, %d%n", totTraces, average, (afterLoad-beforeLoad),(afterReplay-afterLoad)); } } catch (T2Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } static void preliminary3() { /* Note, after running this it was discovered that BP selected some BasicPaths that RH did not. * See method clear(), m1/29 (v.34.patch) * * The method contained a modification at node 3, line 668. * * RH marks [1,3] as dangerous * Because all executions of clear() must visit node 3, BP selects the whole method as modtrav. * * Consequentely, The cycle [1,2,1] is not modtrav with RH, but it is with BP. * * In practice, any trace selected by BP will also be selected by RH */ // final String dir = "./MyArrayList_mutated_versions/originalNtraces/"; // String[] list = new File(dir).list(); // Set allPaths = new HashSet(); // try // { // for(String file : list) // { // if(!file.startsWith("cov")) // continue; // TrFile trFile = TrFile.load(dir+file); // for(Trace t : trFile.traces) // allPaths.addAll(t.coverage()); // out.println("Total number of basic paths = " + allPaths.size()); // } // } catch (T2Exception e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } //RESULT: There are 70 unique basicpaths in all the trace files combined //The L16 1K files each have 70, so we will just use those. out.println("m#, id, load oldCFGS (ms), load newCFGS (ms), construct RH (ms), construct BP (ms), construct bvBROKEN(ms)," + " modtravRH, pureRH,synRH,unsynRH,modtravBP,pureBP,synBP,unsynBP,modtravBV,pureBV,synBV,unsynBV"); try { Set allPaths = new HashSet(); for(Trace t : TrFile.load("./MyArrayList_mutated_versions/originalNtraces/cov_L16_1K_DUP1.tr").traces) allPaths.addAll(t.coverage()); for(String m : new String[] {"m1/","m2/","m3/"}) for(int i = 0;i<120;i++) { out.print(m+", "+i); long time = System.currentTimeMillis(); CFGBunchFile oldCFGS = CFGBunchFile.load("./MyArrayList_mutated_versions/originalNtraces/java_1_4/util/MyArrayList.cfgs"); time = System.currentTimeMillis() - time; out.print(", "+time); time = System.currentTimeMillis(); CFGBunchFile newCFGS = CFGBunchFile.load( "./MyArrayList_mutated_versions/"+m+i+"/java_1_4/util/MyArrayList.cfgs"); time = System.currentTimeMillis() - time; out.print(", "+time); RegressionTestSelector[] sels = new RegressionTestSelector[3]; time = System.currentTimeMillis(); sels[0] = new RegressionTestSelector(oldCFGS.cfgs, newCFGS.cfgs, RegressionTestSelector.RothermelHarrold); time = System.currentTimeMillis() - time; out.print(", "+time); time = System.currentTimeMillis(); sels[1] = new RegressionTestSelector(oldCFGS.cfgs, newCFGS.cfgs, RegressionTestSelector.BallPartial); time = System.currentTimeMillis() - time; out.print(", "+time); time = System.currentTimeMillis(); sels[2] = new RegressionTestSelector(oldCFGS.cfgs, newCFGS.cfgs, RegressionTestSelector.BallValid); time = System.currentTimeMillis() - time; out.print(", "+time); // OK, each of the 70 paths can either be: non-modified, synthesized, unsynthesizable or modified for(RegressionTestSelector sel : sels) { int modtrav=0, unsyn=0, syn=0, pure = 0; for(BasicPath p : allPaths) { if(sel.isModificationTraversing(p)) modtrav++; else { BasicPath p2 = sel.synthesizeCoverage(p); if(p2==null) unsyn++; else if(p2.getNodes()==p.getNodes()) pure++; else syn++; } } out.format(", %d, %d, %d, %d",modtrav,pure,syn,unsyn); } out.println(); } } catch (T2Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } static void prelim3b() { //Just check for all trace files whether any of them is selected differently in BP //For m1/29 CFGBunchFile oldCFGS = CFGBunchFile.load("./MyArrayList_mutated_versions/originalNtraces/java_1_4/util/MyArrayList.cfgs"); CFGBunchFile newCFGS = CFGBunchFile.load( "./MyArrayList_mutated_versions/m1/29/java_1_4/util/MyArrayList.cfgs"); RegressionTestSelector rh = new RegressionTestSelector(oldCFGS.cfgs, newCFGS.cfgs, RegressionTestSelector.RothermelHarrold); RegressionTestSelector bp = new RegressionTestSelector(oldCFGS.cfgs, newCFGS.cfgs, RegressionTestSelector.BallPartial); final String dir = "./MyArrayList_mutated_versions/originalNtraces/"; String[] list = new File(dir).list(); try { for(String file : list) { if(!file.startsWith("cov")) continue; TrFile trFile = TrFile.load(dir+file); SelectiveRunner runner = new SelectiveRunner(trFile); int totTraces = runner.runSelected(rh); int totTraces2 = runner.runSelected(bp); out.println(file+" "+totTraces+" "+totTraces2); if(totTraces!=totTraces2) out.println("!!!!!!!!!"); } } catch (Exception e) { // TODO: handle exception } } public static void multiplyVisitedNode() { CFGBunchFile oldCFGS = CFGBunchFile.load("./MyArrayList_mutated_versions/originalNtraces/java_1_4/util/MyArrayList.cfgs"); for(String m : new String[] {"m1/","m2/","m3/"}) for(int i = 0;i<120;i++) { CFGBunchFile newCFGS = CFGBunchFile.load( "./MyArrayList_mutated_versions/"+m+i+"/java_1_4/util/MyArrayList.cfgs"); System.out.print(m+i); if(InterclassGraph.hasMultiplyVisitedNode(oldCFGS.cfgs, newCFGS.cfgs)) out.print("MULTIPLY VISITED NODE!!!"); out.println(); } //THERE ARE NO MULTIPLY VISITED NODES } static void experiment1() { try { out = new PrintStream("./experiment1.csv"); } catch (FileNotFoundException e) { throw new Error(e); } out.println("m#, id, len, #tot, load Tr(ms), selRun(ms), #sel, #obs"); ProcessBuilder pb = new ProcessBuilder("java","-Xmx800m","-ea","-cp", System.getProperty("java.class.path")+":.", "jeiel.experiment.RunModifiedVersion"); pb.redirectErrorStream(true); for(String m : new String[] {"m1/","m2/","m3/"}) for(int i = 0;i<120;i+=4) { System.out.println(m+i); runProcess(pb, "./MyArrayList_mutated_versions/"+m+i+"/", false); } out.flush(); out.close(); } public static void runProcess(ProcessBuilder pb, String dir, boolean silent) { try { Process p = pb.directory( new File(dir).getCanonicalFile() ).start(); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { if(!silent) out.println(inputLine); } in.close(); p.waitFor(); //*/ } catch (Exception e) { e.printStackTrace(); System.exit(1); } } /** * @param args */ public static void main(String[] args) { experiment1(); } }