diff --git a/dt-impact-tracer/pom.xml b/dt-impact-tracer/pom.xml index c8aaa044..e16fe633 100644 --- a/dt-impact-tracer/pom.xml +++ b/dt-impact-tracer/pom.xml @@ -116,7 +116,7 @@ com.reedoei eunomia - 1.3.1 + 1.3.2 com.google.code.gson @@ -133,6 +133,16 @@ jfreesvg 3.3 + + org.apache.commons + commons-csv + 1.4 + + + com.github.javaparser + javaparser-symbol-solver-core + 3.22.0 + diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/Main/RunnerMain.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/Main/RunnerMain.java index 16f0313f..5c08c399 100644 --- a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/Main/RunnerMain.java +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/Main/RunnerMain.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -92,7 +93,7 @@ public static void main(String[] args) { } // TODO: Allow handling of randomize option; for now just run in fixed order - SmartRunner runner = new SmartRunner(TestFramework.junitTestFramework(), new TestInfoStore(), classpath, new HashMap(), Paths.get("/dev/null")); + SmartRunner runner = new SmartRunner(TestFramework.junitTestFramework(), new TestInfoStore(), classpath, new LinkedHashMap(), Paths.get("/dev/null")); Configuration.config().setDefault("testplugin.classpath", ""); long start = System.nanoTime(); diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/FileCompare.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/FileCompare.java new file mode 100644 index 00000000..b0f348ab --- /dev/null +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/FileCompare.java @@ -0,0 +1,120 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.Stack; +import java.io.FileNotFoundException; +import java.util.Scanner; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; +import org.apache.commons.io.FileUtils; + +public class FileCompare{ + + public static long filesCompareByLine(String str_path1, String str_path2) throws IOException { + Path path1 = Paths.get(str_path1); + Path path2 = Paths.get(str_path2); + try (BufferedReader bf1 = Files.newBufferedReader(path1); + BufferedReader bf2 = Files.newBufferedReader(path2)) { + long lineNumber = 1; + String line1 = "", line2 = ""; + while ((line1 = bf1.readLine()) != null) { + line2 = bf2.readLine(); + if (line2 == null || !line1.equals(line2)) { + return lineNumber; + } + lineNumber++; + } + if (bf2.readLine() == null) { + return -1; + } + else { + return lineNumber; + } + } catch (FileNotFoundException e){ + System.out.println("Not Found"); + return -500; + } + } + + private static void tryCreateDirectory(final File theDir) { + try { + Files.createDirectory(theDir.toPath()); + } catch (FileAlreadyExistsException ignored) { + // The directory must have been created in between the check above and our attempt to create it. + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) throws IOException{ + + List argsList = new ArrayList(Arrays.asList(args)); + int firstFileIndex = argsList.indexOf("-firstFile"); + int secondFileIndex = argsList.indexOf("-secondFile"); + String first_file = argsList.get(firstFileIndex+1); + String second_file = argsList.get(secondFileIndex+1); + File folder = new File(first_file); + File[] listOfFiles = folder.listFiles(); + File theDir = new File("matchingOutput"); + // if the directory does not exist, create it + tryCreateDirectory(theDir); + FileWriter output = null; + BufferedWriter writer = null; + try { + output = new FileWriter("matchingOutput" + File.separator + "nomatch", true); + writer = new BufferedWriter(output); + for (int i = 0; i < listOfFiles.length; i++) { + if (listOfFiles[i].isFile()) { + String input_file = listOfFiles[i].getName(); + try { + String primary_file = first_file+File.separator+input_file; + String secondary_file = second_file+File.separator+input_file; + long x = filesCompareByLine(primary_file, secondary_file); + if (x!= -1 && x != -500) { + writer.write(input_file); + System.out.println("Files: " + input_file); + } + } catch (Exception e) { + System.out.println("File Not Found in Second List" + listOfFiles[i].getName()); + } + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + /*try { + File rootFile = new File(argsList.get(inputTestList)+"sootSeqOutput/test"); + Scanner fileReader = new Scanner(rootFile); + while (fileReader.hasNextLine()) { + String data = fileReader.nextLine(); + } + } catch (FileNotFoundException e) { + }*/ + } +} diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/GeneratingAST.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/GeneratingAST.java new file mode 100644 index 00000000..0d353fa2 --- /dev/null +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/GeneratingAST.java @@ -0,0 +1,55 @@ +import edu.washington.cs.dt.impact.util.MethodVisitor; +import com.github.javaparser.JavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.visitor.ModifierVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import com.github.javaparser.utils.CodeGenerationUtils; +import com.github.javaparser.utils.Log; +import com.github.javaparser.utils.SourceRoot; +import com.github.javaparser.ast.body.MethodDeclaration; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Paths; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.io.*; +/** + * Some code that uses JavaParser. + */ + +public class GeneratingAST { + public static void createAST(){ + try { + String filename = "src/main/java/com/github/kevinsawicki/http/HttpRequest.java"; + File sourceFile = new File(filename); + CompilationUnit compilationUnit = JavaParser.parse(sourceFile); + String package_path = filename.replace("src/main/java/", " "); + package_path = package_path.replace(".java", " "); + String[] parts = package_path.trim().split("/"); + String package_name = String.join(".", parts); + MethodVisitor visitor = new MethodVisitor(); + visitor.visit(compilationUnit, package_name); + } catch (FileNotFoundException e) { + } + } + public static void main(String[] args) throws FileNotFoundException{ + List argsList = new ArrayList(Arrays.asList(args)); + int inputFileIndex = argsList.indexOf("-inputFile"); + String input_file = argsList.get(inputFileIndex); + System.out.println(inputFileIndex); + System.out.println(input_file); + try { + createAST(); + } catch (Exception e){ + + } + //System.out.println(path.toAbsolutePath()); + //System.out.println(path.toRealPath()); + //System.out.println(path); + } +} diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Instrumenter.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Instrumenter.java index 292c3df8..eac1a785 100644 --- a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Instrumenter.java +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Instrumenter.java @@ -17,9 +17,11 @@ import soot.SootClass; import soot.SootMethod; import soot.Type; +import soot.Trap; import soot.Unit; import soot.jimple.IdentityStmt; import soot.jimple.InvokeExpr; +import soot.jimple.InvokeStmt; import soot.jimple.Jimple; import soot.jimple.RetStmt; import soot.jimple.ReturnStmt; @@ -51,7 +53,7 @@ public class Instrumenter extends BodyTransformer{ private static SootClass tracerClass; - private static SootMethod trace, output, reset, selectionOutput, selectionTrace; + private static SootMethod trace, output, reset, selectionOutput, selectionTrace, timerOutput, startTimer, endTimer, startExecution, endExecution, exceptionMessage; private static final String JUNIT4_TAG = "VisibilityAnnotationTag"; private static final String JUNIT4_TYPE = "Lorg/junit/Test;"; private static final String JUNIT4_BEFORE = "Lorg/junit/Before;"; @@ -63,13 +65,18 @@ public class Instrumenter extends BodyTransformer{ public Instrumenter() { Scene.v().setSootClassPath(System.getProperty("java.class.path")); - tracerClass = Scene.v().loadClassAndSupport("edu.washington.cs.dt.impact.util.Tracer"); trace = tracerClass.getMethodByName("trace"); selectionTrace = tracerClass.getMethodByName("selectionTrace"); selectionOutput = tracerClass.getMethodByName("selectionOutput"); output = tracerClass.getMethodByName("output"); reset = tracerClass.getMethodByName("reset"); + timerOutput = tracerClass.getMethodByName("timerOutput"); + startExecution = tracerClass.getMethodByName("startExecution"); + endExecution = tracerClass.getMethodByName("endExecution"); + startTimer = tracerClass.getMethodByName("startTimer"); + endTimer = tracerClass.getMethodByName("endTimer"); + exceptionMessage = tracerClass.getMethodByName("exceptionMessage"); } public Instrumenter(TECHNIQUE t) { @@ -83,14 +90,13 @@ public Instrumenter(TECHNIQUE t) { @Override protected void internalTransform(Body body, String phase, @SuppressWarnings("rawtypes") Map options) { - SootMethod method = body.getMethod(); - + SootMethod method = body.getMethod(); if (method.getName().equals("") || method.getName().equals("")) { return; } - boolean isSetupOrTeardown = false; - + boolean isBefore = false; + boolean isAfter = false; boolean isJUnit4 = false; VisibilityAnnotationTag vat = (VisibilityAnnotationTag) method.getTag(JUNIT4_TAG); if (vat != null) { @@ -100,12 +106,13 @@ protected void internalTransform(Body body, String phase, isJUnit4 = at.getType().equals(JUNIT4_TYPE); } if (!isSetupOrTeardown) { - isSetupOrTeardown = at.getType().equals(JUNIT4_BEFORE) - || at.getType().equals(JUNIT4_AFTER); + isBefore = at.getType().equals(JUNIT4_BEFORE); + isAfter = at.getType().equals(JUNIT4_AFTER); + isSetupOrTeardown = isBefore || isAfter; } } } - + boolean isJUnit3 = false; boolean extendsJUnit = false; if (!isJUnit4 && method.getName().length() > 3) { @@ -120,12 +127,11 @@ protected void internalTransform(Body body, String phase, superClass = superClass.getSuperclass(); } isJUnit3 = method.isPublic() && retType.equals(JUNIT3_RETURN) - && extendsJUnit && prefix.equals(JUNIT3_METHOD_PREFIX); + && extendsJUnit && prefix.equals(JUNIT3_METHOD_PREFIX); } - // exclude the instrumentation of setups/teardowns - // and JUnit3 methods that are not tests - if ((extendsJUnit && !isJUnit3) || isSetupOrTeardown) { + // exclude the instrumentation JUnit3 methods that are not tests + if ((extendsJUnit && !isJUnit3)) { return; } @@ -133,10 +139,10 @@ protected void internalTransform(Body body, String phase, // get a snapshot iterator of the unit since we are going to // mutate the chain when iterating over it. Iterator stmtIt = units.snapshotIterator(); - String packageMethodName = method.getDeclaringClass().getName() + "." + method.getName(); - if (isJUnit4 || isJUnit3) { - // instrumentation of JUnit files + + if (isJUnit4 || isJUnit3 || isSetupOrTeardown) { + // instrumentation of JUnit files and setup and teardown methods // get access to Throwable class and toString method SootClass thrwCls = Scene.v().getSootClass("java.lang.Throwable"); @@ -144,13 +150,30 @@ protected void internalTransform(Body body, String phase, PatchingChain pchain = body.getUnits(); Stmt sFirstNonId = getFirstNonIdStmt(pchain); - Stmt sLast = (Stmt) pchain.getLast(); + Stmt sLast = (Stmt) pchain.getLast(); + Stmt sFirst = (Stmt) pchain.getFirst(); + StringBuffer sb = new StringBuffer(); + String part = "body"; + if (isBefore) { + part = "before"; + } else if (isAfter){ + part = "after"; + } + + InvokeExpr firstExpr = Jimple.v().newStaticInvokeExpr(startExecution.makeRef(),StringConstant.v(packageMethodName), StringConstant.v(part)); + Stmt firstStmt = Jimple.v().newInvokeStmt(firstExpr); + units.insertAfter(firstStmt, sFirst); + + InvokeExpr lastExpr = Jimple.v().newStaticInvokeExpr(endExecution.makeRef(),StringConstant.v(packageMethodName), StringConstant.v(part), StringConstant.v("Regular")); + Stmt lastStmt = Jimple.v().newInvokeStmt(lastExpr); + units.insertBefore(lastStmt, sLast); + // Don't instrument empty methods if (sFirstNonId == sLast) { return; } - + // FOR NOW, no other returns allowed apart from last stmt for (Unit u : pchain) { assert (!(u instanceof ReturnStmt) && !(u instanceof RetStmt)) || u == sLast; @@ -159,8 +182,9 @@ protected void internalTransform(Body body, String phase, Stmt sGotoLast = Jimple.v().newGotoStmt(sLast); probe.add(sGotoLast); Local lException1 = getCreateLocal(body, "", RefType.v(thrwCls)); - Stmt sCatch = Jimple.v().newIdentityStmt(lException1, Jimple.v().newCaughtExceptionRef()); - probe.add(sCatch); + Stmt sCatch = Jimple.v().newIdentityStmt(lException1, Jimple.v().newCaughtExceptionRef()); + probe.add(sCatch); + // TODO after catching an exception in a test, throw the exception back // Type throwType = thrwCls.getType(); @@ -170,18 +194,30 @@ protected void internalTransform(Body body, String phase, // probe.add(callThrow); insertRightBeforeNoRedirect(pchain, probe, sLast); - // insert trap (catch) body.getTraps().add(Jimple.v().newTrap(thrwCls, sFirstNonId, sGotoLast, sCatch)); - // Do not forget to insert instructions to report the counter - stmtIt = units.snapshotIterator(); while (stmtIt.hasNext()) { - Stmt stmt = (Stmt)stmtIt.next(); - - if ((stmt instanceof ReturnStmt) - ||(stmt instanceof ReturnVoidStmt)) { - + Stmt stmt = (Stmt) stmtIt.next(); + if(stmt.containsInvokeExpr()){ + if(!(stmt.toString().contains("org.junit")) && !(stmt.getInvokeExpr().getMethod().getName().equals("")) && !(stmt.getInvokeExpr().getMethod().getName().equals(""))){ + + sb.append(stmt.getInvokeExpr().getMethodRef().declaringClass().getName() + "." + stmt.getInvokeExpr().getMethod().getName() + "\n"); + InvokeExpr startExpr= Jimple.v().newStaticInvokeExpr(startTimer.makeRef()); + Stmt startStmt = Jimple.v().newInvokeStmt(startExpr); + units.insertBefore(startStmt, stmt); + + InvokeExpr endExpr= Jimple.v().newStaticInvokeExpr(endTimer.makeRef()); + Stmt endStmt = Jimple.v().newInvokeStmt(endExpr); + units.insertAfter(endStmt, stmt); + + // reset the timer + InvokeExpr resetExpr = Jimple.v().newStaticInvokeExpr(timerOutput.makeRef(),StringConstant.v(packageMethodName) , StringConstant.v(stmt.getInvokeExpr().getMethod().getName().toString()), StringConstant.v(stmt.getInvokeExpr().getMethodRef().declaringClass().getName())); + Stmt resetStmt = Jimple.v().newInvokeStmt(resetExpr); + units.insertAfter(resetStmt, endStmt); + } + } + if ((stmt instanceof ReturnStmt) || (stmt instanceof ReturnVoidStmt)) { if (technique != TECHNIQUE.SELECTION) { // output the contents of the tracer InvokeExpr reportExpr= Jimple.v().newStaticInvokeExpr(output.makeRef(), @@ -197,16 +233,30 @@ protected void internalTransform(Body body, String phase, // output the contents of the tracer InvokeExpr reportExpr= Jimple.v().newStaticInvokeExpr( selectionOutput.makeRef(), StringConstant.v(packageMethodName)); + Stmt reportStmt = Jimple.v().newInvokeStmt(reportExpr); units.insertBefore(reportStmt, stmt); // reset the tracer InvokeExpr resetExpr= Jimple.v().newStaticInvokeExpr(reset.makeRef()); Stmt resetStmt = Jimple.v().newInvokeStmt(resetExpr); + units.insertAfter(resetStmt, reportStmt); } } + } + Chain new_units = body.getUnits(); + Iterator new_stmtIt = new_units.snapshotIterator(); + while (new_stmtIt.hasNext()) { + Stmt stmt = (Stmt) new_stmtIt.next(); + InvokeExpr lExceptionMessage = Jimple.v().newStaticInvokeExpr(exceptionMessage.makeRef(), StringConstant.v(packageMethodName), StringConstant.v(part)); + Stmt exceptionStmt = Jimple.v().newInvokeStmt(lExceptionMessage); + if(stmt.toString().contains("@caughtexception")){ + units.insertAfter(exceptionStmt, stmt); + } + } + selectionOutput(packageMethodName, sb, "testOutput"); } else { if (technique == TECHNIQUE.SELECTION) { // instrumentation of class files for test selection @@ -214,10 +264,11 @@ protected void internalTransform(Body body, String phase, // each test executed without duplicates Set duplicates = new HashSet(); StringBuffer sb = new StringBuffer(); + StringBuffer fb = new StringBuffer(); UnitGraph ug = new ExceptionalUnitGraph(body); Stack remaining = new Stack(); remaining.addAll(ug.getHeads()); - + List incStmts = new LinkedList(); List stmts = new LinkedList(); @@ -226,48 +277,54 @@ protected void internalTransform(Body body, String phase, // cast back to a statement. Stmt stmt = (Stmt)current; - if (stmt instanceof ReturnVoidStmt) { - continue; - } - + //if (stmt instanceof ReturnVoidStmt) { + // continue; + //} + if(stmt.containsInvokeExpr()){ + if(!(stmt.toString().contains("org.junit")) && !(stmt.getInvokeExpr().getMethod().getName().equals("")) && !(stmt.getInvokeExpr().getMethod().getName().equals(""))){ + + fb.append(stmt.getInvokeExpr().getMethodRef().declaringClass().getName() + "." + stmt.getInvokeExpr().getMethod().getName() + "\n"); + } + } if (!duplicates.contains(current)) { List children = ug.getSuccsOf(current); // don't check identity statements (parameters) if (!(stmt instanceof IdentityStmt)) { for (Unit u : children) { sb.append(packageMethodName + " : " - + current.toString().split(" goto")[0] + " >>>>>>>> " + + current.toString().split(" goto")[0] + " >>>>>>>> " + packageMethodName + " : " + u.toString().split(" goto")[0] + "\n"); - } + } InvokeExpr incExpr= Jimple.v().newStaticInvokeExpr( selectionTrace.makeRef(), StringConstant.v(stmt.toString()), StringConstant.v(packageMethodName)); Stmt incStmt = Jimple.v().newInvokeStmt(incExpr); incStmts.add(incStmt); stmts.add(stmt); - } + } remaining.addAll(children); duplicates.add(current); } } - + for (int i = 0; i < incStmts.size(); i++) { units.insertBefore(incStmts.get(i), stmts.get(i)); } - selectionOutput(packageMethodName, sb); + selectionOutput(packageMethodName, sb, "selectionOutput"); + selectionOutput(packageMethodName, fb, "methodOutput"); } else { // instrumentation of class files for test prioritization and parallelization Set lines = new HashSet(); while (stmtIt.hasNext()) { // cast back to a statement. Stmt stmt = (Stmt)stmtIt.next(); - + if (stmt instanceof ReturnVoidStmt) { continue; } - + if (stmt instanceof IdentityStmt) { continue; } @@ -275,11 +332,10 @@ protected void internalTransform(Body body, String phase, LineNumberTag t = (LineNumberTag) stmt.getTag("LineNumberTag"); if (stmt.hasTag("LineNumberTag") && !lines.contains(t.getLineNumber())) { lines.add(t.getLineNumber()); - - InvokeExpr incExpr= Jimple.v().newStaticInvokeExpr(trace.makeRef(), - StringConstant.v(stmt.toString()), - StringConstant.v(packageMethodName)); - Stmt incStmt = Jimple.v().newInvokeStmt(incExpr); + InvokeExpr incExpr= Jimple.v().newStaticInvokeExpr(trace.makeRef(), + StringConstant.v(stmt.toString()), + StringConstant.v(packageMethodName)); + Stmt incStmt = Jimple.v().newInvokeStmt(incExpr); units.insertBefore(incStmt, stmt); } } @@ -288,8 +344,8 @@ protected void internalTransform(Body body, String phase, } // used for the instrumentation of test selection class files - private static void selectionOutput(String packageMethodName, StringBuffer sb) { - File theDir = new File("selectionOutput"); + private static void selectionOutput(String packageMethodName, StringBuffer sb, String FileName) { + File theDir = new File(FileName); // if the directory does not exist, create it if (!theDir.exists()) { try { @@ -304,7 +360,7 @@ private static void selectionOutput(String packageMethodName, StringBuffer sb) { FileWriter output = null; BufferedWriter writer = null; try { - output = new FileWriter("selectionOutput" + File.separator + packageMethodName); + output = new FileWriter(FileName + File.separator + packageMethodName); writer = new BufferedWriter(output); writer.write(sb.toString()); } catch (Exception e) { @@ -342,6 +398,18 @@ private static Stmt getFirstNonIdStmt(PatchingChain pchain) { return sFirstNonId; } + private static Stmt getLastInvokeStmt(PatchingChain pchain) { + Stmt sFirstNonId = null; + Stmt sLastInvoke = null; + for (Iterator it = pchain.iterator(); it.hasNext(); ) { + sFirstNonId = (Stmt) it.next(); + if (sFirstNonId instanceof InvokeStmt) { + sLastInvoke = sFirstNonId; + } + } + return sLastInvoke; + } + private static Local getCreateLocal(Body b, String localName, Type t) { // try getting it Local l = getLocal(b, localName); @@ -362,6 +430,7 @@ private static Local getLocal(Body b, String localName) { for (Iterator itLoc = locals.iterator(); itLoc.hasNext(); ) { Local l = itLoc.next(); if (l.getName().equals(localName)) { + System.out.println("Locals: " + l.toString()); return l; } } diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/MethodVisitor.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/MethodVisitor.java new file mode 100644 index 00000000..06c9b271 --- /dev/null +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/MethodVisitor.java @@ -0,0 +1,62 @@ +package edu.washington.cs.dt.impact.util; + +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.BinaryExpr; +import com.github.javaparser.ast.stmt.IfStmt; +import com.github.javaparser.ast.stmt.Statement; +import com.github.javaparser.ast.visitor.ModifierVisitor; +import com.github.javaparser.ast.visitor.Visitable; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; +import com.github.javaparser.utils.CodeGenerationUtils; +import com.github.javaparser.utils.Log; +import com.github.javaparser.utils.SourceRoot; +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.printer.XmlPrinter; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.io.*; + +public class MethodVisitor extends VoidVisitorAdapter +{ + private static void tryCreateDirectory(final File theDir) { + try { + Files.createDirectory(theDir.toPath()); + } catch (FileAlreadyExistsException ignored) { + // The directory must have been created in between the check above and our attempt to create it. + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public void visit(MethodDeclaration n, Object arg) + { + File theDir = new File("xmlOutput"); + tryCreateDirectory(theDir); + FileWriter output = null; + BufferedWriter writer = null; + try { + XmlPrinter printer = new XmlPrinter(true); + output = new FileWriter("xmlOutput" + File.separator + arg.toString() + "."+ n.getName().asString()); + writer = new BufferedWriter(output); + writer.write(printer.output(n)); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + // extract method information here. + // put in to hashmap + } +} diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Runtime.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Runtime.java new file mode 100644 index 00000000..a7502625 --- /dev/null +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Runtime.java @@ -0,0 +1,144 @@ +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.Stack; +import java.io.FileNotFoundException; +import java.util.Scanner; +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVPrinter; + + +public class Runtime{ + private static void tryCreateDirectory(final File theDir) { + try { + Files.createDirectory(theDir.toPath()); + } catch (FileAlreadyExistsException ignored) { + // The directory must have been created in between the check above and our attempt to create it. + } catch (IOException e) { + throw new RuntimeException(e); + } + } + public static void main(String[] args) throws IOException { + List argsList = new ArrayList(Arrays.asList(args)); + int inputTestListIndex = argsList.indexOf("-inputFile"); + int inputTestList = inputTestListIndex + 1; + File theDir = new File("sootCsvOutput"); + String[] paths = argsList.get(inputTestList).split("/"); + System.out.println("File: " + paths[paths.length - 4]); + tryCreateDirectory(theDir); + FileWriter x = null; + BufferedWriter writer = null; + try { + x = new FileWriter("sootCsvOutput" + File.separator + paths[paths.length - 4] + "-test.csv"); + writer = new BufferedWriter(x); + CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.DEFAULT + .withHeader("Test Name", "Part", "Method Unter Test Name", "Execution Time", "Throw Exception")); + try { + File rootFile = new File(argsList.get(inputTestList)+"sootSeqOutput/test"); + Scanner fileReader = new Scanner(rootFile); + HashMap set_up = new HashMap(); + HashMap tear_down = new HashMap(); + while (fileReader.hasNextLine()) { + String data = fileReader.nextLine(); + String[] test_info = data.split(" > "); + String initial = test_info[0].trim(); + if (!initial.equals("Started")){ + continue; + } + String name_info = test_info[1].trim(); + String part = name_info.split(" >> ")[0].trim(); + String name = name_info.split(" >> ")[1].trim(); + String q_name = test_info[3].trim(); + String exec_info = test_info[4].trim(); + String return_from = exec_info.split(" >> ")[0].trim(); + String exec_time = exec_info.split(" >> ")[1].trim().split(" : ")[1].trim(); + if (part.contains("body")) { + String subFile = argsList.get(inputTestList) + "sootTimerOutput/"; + try { + File subDir = new File(subFile+name); + Scanner subReader = new Scanner(subDir); + while(subReader.hasNextLine()){ + String full_method_name = subReader.nextLine(); + String method_name_info = full_method_name.split(" >>> ")[1]; + csvPrinter.printRecord(name, part, method_name_info.split(" : ")[0].trim(), method_name_info.split(" : ")[1].trim(), return_from); + } + subReader.close(); + } catch (FileNotFoundException e) { + + } + } else { + String testOutput = argsList.get(inputTestList)+"target/testOutput/"; + String subFile = argsList.get(inputTestList)+"sootTimerOutput/"; + ArrayList result = new ArrayList(); + try { + File testDir = new File(testOutput+name); + Scanner testReader = new Scanner(testDir); + File temp = new File("new_csv.txt"); + FileWriter output = new FileWriter(temp); + BufferedWriter writer_2 = new BufferedWriter(output); + while(testReader.hasNextLine()){ + String full_method_name = testReader.nextLine(); + File subDir = new File(subFile+name); + Scanner subReader = new Scanner(subDir); + while(subReader.hasNextLine()){ + String method_name = subReader.nextLine(); + String sub_method = method_name.split(" >>> ")[1]; + if(sub_method.split(" : ")[0].trim().equals(full_method_name.trim())){ + csvPrinter.printRecord(name, part, sub_method.split(" : ")[0].trim(), sub_method.split(" : ")[1].trim(), return_from); + result.add(sub_method); + break; + } + } + subReader.close(); + } + testReader.close(); + File subDir = new File(subFile+name); + Scanner subReader = new Scanner(subDir); + while(subReader.hasNextLine()){ + String method_name = subReader.nextLine(); + String sub_method = method_name.split(" >>> ")[1]; + Boolean found = false; + for (int i = 0; i < result.size(); i++) { + if(sub_method.trim().equals(result.get(i).trim())){ + result.remove(i); + found = true; + break; + } + } + if (!found) { + writer_2.write(method_name + "\n"); + } + } + subReader.close(); + writer_2.close(); + temp.renameTo(subDir); + } catch (FileNotFoundException e) { + + } + } + } + fileReader.close(); + } catch (FileNotFoundException e) { + + } + csvPrinter.flush(); + x.close(); + writer.close(); + } catch (IOException e){ + x.close(); + writer.close(); + } + } +} diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/StopWatch.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/StopWatch.java new file mode 100644 index 00000000..623c0018 --- /dev/null +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/StopWatch.java @@ -0,0 +1,42 @@ +/** + * Copyright 2014 University of Washington. All Rights Reserved. + * @author Ridwan + * + * Used by the Instrumenter to record the execution time for each method under tests. + */ + +package edu.washington.cs.dt.impact.util; + + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.Stack; + +public class StopWatch { + private static long start = 0L; + private static long end = 0L; + public static void setStartTime() { + start = System.nanoTime(); + } + public static void setEndTime() { + end = System.nanoTime(); + } + public static Long getTotalTime(){ + return end - start; + } + public static void reset() { + start = 0L; + end = 0L; + } +} + diff --git a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Tracer.java b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Tracer.java index 799f0dfe..5803d236 100644 --- a/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Tracer.java +++ b/dt-impact-tracer/src/main/java/edu/washington/cs/dt/impact/util/Tracer.java @@ -7,7 +7,7 @@ package edu.washington.cs.dt.impact.util; - +import edu.washington.cs.dt.impact.util.StopWatch; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -20,12 +20,15 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.Stack; public class Tracer { private static Map> statements = new ConcurrentHashMap<>(); private static final List selectionStatements = Collections.synchronizedList(new LinkedList<>()); private static Set duplicates = ConcurrentHashMap.newKeySet(); private static boolean printLastElement = true; + private static StopWatch timer = new StopWatch(); + private static StopWatch totalExecutionTime = new StopWatch(); public static void trace(String str, String methodName) { if (statements.containsKey(methodName)) { @@ -89,13 +92,13 @@ public static void reset() { public static void selectionTrace(String str, String packageMethodName) { String s = packageMethodName + " : " + str.split(" goto")[0]; - if (str.contains("staticinvoke ") || duplicates.contains(s)) { return; - } + }*/ - duplicates.add(s); + // duplicates.add(s); selectionStatements.add(s); printLastElement = true; } @@ -116,7 +119,8 @@ public static void selectionOutput(String packageMethodName) { writer = new BufferedWriter(output); synchronized (selectionStatements) { - if (selectionStatements.size() > 1) { + + if (selectionStatements.size() > 1) { String prev = selectionStatements.get(0); for (int i = 1; i < selectionStatements.size(); i++) { writer.write(prev + " >>>>>>>> " + selectionStatements.get(i) + "\n"); @@ -141,4 +145,125 @@ public static void selectionOutput(String packageMethodName) { } } } + + public static void startTimer (){ + timer.setStartTime(); + } + public static void endTimer(){ + timer.setEndTime(); + } + + public static void exceptionMessage(String packageMethodName, String prefix){ + endExecution(packageMethodName, prefix, "Exception"); + File theDir = new File("sootException"); + // if the directory does not exist, create it + tryCreateDirectory(theDir); + FileWriter output = null; + BufferedWriter writer = null; + try { + output = new FileWriter("sootException" + File.separator + "test", true); + writer = new BufferedWriter(output); + writer.write("Caught Execption in : " + packageMethodName + "\n"); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + } + + public static void timerOutput(String packageMethodName, String methodName, String declaringClass){ + File theDir = new File("sootTimerOutput"); + // if the directory does not exist, create it + tryCreateDirectory(theDir); + + FileWriter output = null; + BufferedWriter writer = null; + long elapsedTime = timer.getTotalTime(); + timer.reset(); + try { + output = new FileWriter("sootTimerOutput" + File.separator + packageMethodName, true); + writer = new BufferedWriter(output); + writer.write(packageMethodName + " >>> " + declaringClass + "." + methodName + " : " + elapsedTime + "\n"); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + } + + public static void startExecution(String packageMethodName, String prefix){ + File theDir = new File("sootSeqOutput"); + // if the directory does not exist, create it + tryCreateDirectory(theDir); + + FileWriter output = null; + BufferedWriter writer = null; + totalExecutionTime.setStartTime(); + try { + output = new FileWriter("sootSeqOutput" + File.separator + "test", true); + writer = new BufferedWriter(output); + writer.write("Started > " + prefix + " >> " + packageMethodName); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + } + + public static void endExecution(String packageMethodName, String prefix, String endMethod){ + File theDir = new File("sootSeqOutput"); + // if the directory does not exist, create it + tryCreateDirectory(theDir); + + FileWriter output = null; + BufferedWriter writer = null; + totalExecutionTime.setEndTime(); + long elapsedTime = totalExecutionTime.getTotalTime(); + totalExecutionTime.reset(); + try { + output = new FileWriter("sootSeqOutput" + File.separator + "test", true); + writer = new BufferedWriter(output); + writer.write(" > Ended > " + packageMethodName + " > " + endMethod + " >> " + "Time : " + elapsedTime + " " + "\n"); + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + try { + if (writer != null) { + writer.close(); + } + if (output != null) { + output.close(); + } + } catch (IOException e) { + // Ignore issues during closing + } + } + } } diff --git a/generate.sh b/generate.sh new file mode 100644 index 00000000..c17b1a2f --- /dev/null +++ b/generate.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Example usage: bash generate.sh firstVers/lib t2 secondVers/lib + +if [[ $1 == "" ]] || [[ $2 == "" ]] || [[ $3 == "" ]]; then + echo "arg1 - Path to module that has its dependencies copied, and source and test compiled. This directory should contain the pom.xml and is the version to collect metadata for regression testing algorithms." + echo "arg2 - The algorithm to run. Valid options are T1 (prioritization, statement, absolute), T2 (prioritization, statement, relative), T3 (prioritization, function, absolute), and T4 (prioritization, function, relative)." + echo "arg3 - Path to module that has its dependencies copied, and source and test compiled. This directory should contain the pom.xml and is the version to run the regression testing algorithms." + exit 1 +fi + +source shared/set-vars.sh "$1" "$2" "$3" + +ret_code=$? +if [ $ret_code != 0 ]; then + printf "Failed setting up variables. See error above." + exit $ret_code +fi + +mkdir -p $DT_SCRIPTS/${SUBJ_NAME}-results +echo "Starting setup for $TECH" +if [[ $TECH == "prio" ]] || [[ $TECH == "para" ]]; then + bash $DT_SCRIPTS/generate/setup-prio-para.sh +elif [[ $TECH == "sele" ]]; then + bash $DT_SCRIPTS/generate/setup-sele-firstVers.sh + bash $DT_SCRIPTS/generate/setup-sele-subseqVers.sh +else + echo "Unknown $TECH. Is $ALGO set correctly in shared/set-vars.sh?" + exit 1 +fi diff --git a/generate/setup-prio-para.sh b/generate/setup-prio-para.sh new file mode 100644 index 00000000..4f828087 --- /dev/null +++ b/generate/setup-prio-para.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Runs commands for "Instructions to setup a subject for test prioritization" section. + +set -e + +# 1. Find the human-written tests in the old subject. +cd $DT_SUBJ +echo "[DEBUG] Finding human written tests in old subject." +bash "$DT_SCRIPTS/shared/get-test-order.sh" old + +# 2. Instrument the source and test files. +echo "[DEBUG] Instrumenting source and test files for old subject." +rm -rf sootOutput/ + +#echo "java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_TESTS --soot-cp $DT_LIBS:$DT_CLASS:$DT_TESTS:$JAVA_HOME/jre/lib/*" +java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_TESTS --soot-cp $DT_LIBS:$DT_CLASS:$DT_TESTS:$JAVA_HOME/jre/lib/* + +#echo "java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_CLASS --soot-cp $DT_LIBS:$DT_CLASS:$JAVA_HOME/jre/lib/*" +java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_CLASS --soot-cp $DT_LIBS:$DT_CLASS:$JAVA_HOME/jre/lib/* + +# Copy over any resource files from the classes/ and test-classes/ directories (e.g. configuration files). +# Make sure we don't copy any .class files though. +cd classes/ +find . -iname "*.class" -printf "%P\n" > ../exclude-list.txt +cd .. +rsync -av classes/ sootOutput/ --exclude-from=exclude-list.txt + +cd test-classes/ +find . -name "*.class" -printf "%P\n" > ../exclude-list.txt +cd .. +rsync -av test-classes/ sootOutput/ --exclude-from=exclude-list.txt + +# 3. Run the instrumented tests. +echo "[DEBUG] Running instrumented tests." +cd $DT_SUBJ_SRC +#echo "[DEBUG] java -cp $DT_TOOLS: edu.washington.cs.dt.impact.Main.RunnerMain -classpath $DT_LIBS:$DT_TOOLS:$DT_SUBJ/sootOutput/: -inputTests $DT_SUBJ/$SUBJ_NAME-orig-order" +java -cp $DT_TOOLS: edu.washington.cs.dt.impact.Main.RunnerMain -classpath $DT_LIBS:$DT_TOOLS:$DT_SUBJ/sootOutput/: -inputTests $DT_SCRIPTS/${SUBJ_NAME}-results/$SUBJ_NAME-orig-order > /dev/null + +rm -rf $DT_SCRIPTS/${SUBJ_NAME}-results/sootTestOutput-orig +mv sootTestOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/sootTestOutput-orig + +cd $DT_SUBJ +rm -rf sootOutput/ + +# 4. Get the time each test took to run. +cd $DT_SUBJ_SRC +echo "[DEBUG] Getting time for orig tests. $DT_SUBJ/$SUBJ_NAME-orig-time.txt" +java -cp $DT_TOOLS: edu.washington.cs.dt.impact.Main.RunnerMain -classpath $DT_LIBS:$DT_TOOLS:$DT_CLASS:$DT_TESTS: -inputTests $DT_SCRIPTS/${SUBJ_NAME}-results/$SUBJ_NAME-orig-order -getTime > $DT_SCRIPTS/${SUBJ_NAME}-results/$SUBJ_NAME-orig-time.txt diff --git a/generate/setup-sele-firstVers.sh b/generate/setup-sele-firstVers.sh new file mode 100644 index 00000000..a232ddf0 --- /dev/null +++ b/generate/setup-sele-firstVers.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Runs commands for "Instructions to setup a subject for test selection" section. + +set -e + +cd $DT_SUBJ +cd .. +rm -rf sootTimerOutput/ +rm -rf sootSeqOutput/ + +cd $DT_SUBJ +echo "[DEBUG] Finding human written tests in old subject." +bash "$DT_SCRIPTS/shared/get-test-order.sh" old + +# 1. Generate the static information needed by test selection for the old version of the subject. +cd $DT_SUBJ +rm -rf sootOutput/ +rm -rf selectionOutput/ +rm -rf methodOutput/ + +echo "[DEBUG] Instrumenting subject for selection (\$DT_TESTS)." +java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_TESTS --soot-cp $DT_LIBS:$DT_CLASS:$DT_TESTS:$JAVA_HOME/jre/lib/*: -technique selection +echo "[DEBUG] Instrumenting subject for selection (\$DT_CLASS)." +java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain -inputDir $DT_CLASS --soot-cp $DT_LIBS:$DT_CLASS:$JAVA_HOME/jre/lib/*: -technique selection + +rm -rf $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-${VER_NAME}/ +rm -rf $DT_SCRIPTS/${SUBJ_NAME}-results/methodOutput-${VER_NAME}/ +mv selectionOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-${VER_NAME}/ +mv methodOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/methodOutput-${VER_NAME}/ + +# Copy over any resource files from the classes/ and test-classes/ directories (e.g. configuration files). +# Make sure we don't copy any .class files though. +cd classes/ +find . -iname "*.class" -printf "%P\n" > ../exclude-list.txt +cd .. +rsync -av classes/ sootOutput/ --exclude-from=exclude-list.txt + +cd test-classes/ +find . -name "*.class" -printf "%P\n" > ../exclude-list.txt +cd .. +rsync -av test-classes/ sootOutput/ --exclude-from=exclude-list.txt + +# 2. Run the instrumented tests. +cd $DT_SUBJ_SRC +echo "[DEBUG] Running the instrumented human-written tests." + +echo "[DEBUG] java -cp $DT_TOOLS: edu.washington.cs.dt.impact.Main.RunnerMain -classpath $DT_LIBS:$DT_TOOLS:$DT_SUBJ/sootOutput/: -inputTests $DT_SUBJ/$SUBJ_NAME-orig-order" + +java -cp $DT_TOOLS: edu.washington.cs.dt.impact.Main.RunnerMain -classpath $DT_LIBS:$DT_TOOLS:$DT_SUBJ/sootOutput/: -inputTests $DT_SCRIPTS/${SUBJ_NAME}-results/$SUBJ_NAME-orig-order + + +java -cp $DT_TOOLS: Runtime -inputFile $DT_SUBJ/../ -inputName $DT_SUBJ + +rm -rf $DT_SCRIPTS/${SUBJ_NAME}-results/sootTestOutput-orig-selection +mv sootTestOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/sootTestOutput-orig +mv sootCsvOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/sootCSV-${VER_NAME}/ + +cd $DT_SUBJ +# rm -rf sootOutput/ diff --git a/generate/setup-sele-subseqVers.sh b/generate/setup-sele-subseqVers.sh new file mode 100644 index 00000000..91e44532 --- /dev/null +++ b/generate/setup-sele-subseqVers.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Runs commands for "Instructions to setup a subject for test selection" section. + +set -e + +echo "[DEBUG] Generate the static information needed by test selection for the new version of the subject." +cd $NEW_DT_SUBJ +rm -rf sootOutput/ +rm -rf selectionOutput/ + +java -cp $DT_TOOLS:$JAVA_HOME/jre/lib/*: edu.washington.cs.dt.impact.Main.InstrumentationMain --soot-cp $NEW_DT_LIBS:$NEW_DT_CLASS:$JAVA_HOME/jre/lib/*: -inputDir $NEW_DT_CLASS -technique selection + + +rm -rf sootOutput/ + +rm -rf $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-subseqVers/ +mv selectionOutput/ $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-subseqVers/ diff --git a/runtime_generator.sh b/runtime_generator.sh new file mode 100644 index 00000000..9ae8919d --- /dev/null +++ b/runtime_generator.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +if [[ $1 == "" ]]; then + echo "arg1 - The algorithm to run. Valid options are T1 (prioritization, statement, absolute), T2 (prioritization, statement, relative), T3 (prioritization, function, absolute), T4 (prioritization, function, relative), S1 (selection, statement, original), S2 (selection, statement, absolute), S3 (selection, statement, relative), S4 (selection, function, original), S5 (selection, function, absolute), S6 (selection, function, relative), P1 (parallelization, original), and P2 (parallelization, time)." + echo "arg2 (optional) - Number of machines to simulate for parallelization. Valid otpions are 2, 4, 8, and 16." + exit 1 +fi + +scripts_folder=$(cd "$(dirname $BASH_SOURCE)"; pwd) +algo=$1 +machines=$2 + +# Clear any existing logs +rm -rf ${scripts_folder}/logs/ +mkdir -p ${scripts_folder}/logs/ + +# Clone the firstVers if it doesn't exist +if [[ ! -d "firstVers" ]]; then + echo "Cloning firstVers" + git clone https://github.com/kevinsawicki/http-request.git firstVers &> ${scripts_folder}/logs/firstVers-clone-log.txt + echo "Compiling firstVers" + cd firstVers/lib + git checkout d0ba95cf3c621c74a023887814e8c1f73b5da1b2 &> ${scripts_folder}/logs/checkout-firstVers.txt + mvn install dependency:copy-dependencies -DskipTests &> ${scripts_folder}/logs/install-log-firstVers.txt + cd ${scripts_folder} +fi + +# update dt-impact-tracer + +cd dt-impact-tracer/ +mvn install -DskipTests &> ../logs/dt-impact-tracer-install.log +cd .. +mv dt-impact-tracer/target/dt-impact-tracer-1.0.5.3.jar shared/impact-tools/dt-impact-tracer-1.0.5.3.jar + +mv dt-impact-tracer/target/dt-impact-tracer-1.0.5.3-jar-with-dependencies.jar shared/impact-tools/dt-impact-tracer-1.0.5.3-jar-with-dependencies.jar + +# Clear any existing results +rm -rf lib-results/ +rm -rf firstVers/lib/target/ + +cd firstVers/lib +git checkout d0ba95cf3c621c74a023887814e8c1f73b5da1b2 &> ${scripts_folder}/logs/checkout-firstVers.txt +git log -2 --pretty=format:"%h" &> ${scripts_folder}/logs/commitlist-firstVers.txt +mvn install dependency:copy-dependencies -DskipTests &> ${scripts_folder}/logs/install-log-firstVers.txt + +echo -e "" >> ${scripts_folder}/logs/commitlist-firstVers.txt + +cd ${scripts_folder} + +declare -A commitArray +num=-1 + +echo "Setting up the two versions for data generation" + +while read line; do + #Reading each line + commitArray[$((++num))]=$line + cd ${scripts_folder} + cd firstVers/lib + git checkout $line &> ${scripts_folder}/logs/checkout-$line-firstVers.txt + mvn install dependency:copy-dependencies -DskipTests &> ${scripts_folder}/logs/install-log-$line.txt + cd ${scripts_folder} + rm -rf $line + cp -r firstVers $line + bash generate.sh $line/lib $algo firstVers/lib &> logs/setup.txt +done < ${scripts_folder}/logs/commitlist-firstVers.txt + +p=${commitArray[0]}/lib +q=${commitArray[1]}/lib + +source shared/set-vars.sh "$p" "$algo" "$q" + +cd $DT_SUBJ_SRC + +git diff ${commitArray[0]} ${commitArray[1]} --name-only &> ${scripts_folder}/logs/diff.txt +echo -e "" >> ${scripts_folder}/logs/diff.txt + +while read c_file; do + java -cp $DT_TOOLS: GeneratingAST \ + -inputFile $c_file \ + &> ${scripts_folder}/logs/generate_ast.txt +done < ${scripts_folder}/logs/diff.txt + + +java -cp $DT_TOOLS: FileCompare \ + -firstFile $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-${commitArray[0]}/ \ + -secondFile $DT_SCRIPTS/${SUBJ_NAME}-results/selectionOutput-${commitArray[1]}/ \ + &> ${scripts_folder}/logs/compare.txt + +cd ${scripts_folder} + +# echo "Two versions" + +#bash setup.sh firstVers/lib $algo secondVers/lib &> logs/setup.txt +#echo "Running the unenhanced regression testing algorithm on the secondVers" +#bash run.sh firstVers/lib $algo secondVers/lib "$machines" &> logs/run-unenhanced.txt +#echo "Computing dependencies on the firstVers" +#bash compute-deps.sh firstVers/lib $algo secondVers/lib "$machines" &> logs/compute-deps.txt +#echo "Running the enhanced regression testing algorithm on the secondVers" +#bash run.sh firstVers/lib $algo secondVers/lib "$machines" &> logs/run-enhanced.txt diff --git a/shared/impact-tools/dt-impact-tracer-1.0.5.3-jar-with-dependencies.jar b/shared/impact-tools/dt-impact-tracer-1.0.5.3-jar-with-dependencies.jar new file mode 100644 index 00000000..3f44460c Binary files /dev/null and b/shared/impact-tools/dt-impact-tracer-1.0.5.3-jar-with-dependencies.jar differ diff --git a/shared/impact-tools/dt-impact-tracer-1.0.5.3.jar b/shared/impact-tools/dt-impact-tracer-1.0.5.3.jar index f53612aa..4b2f596d 100644 Binary files a/shared/impact-tools/dt-impact-tracer-1.0.5.3.jar and b/shared/impact-tools/dt-impact-tracer-1.0.5.3.jar differ diff --git a/shared/set-vars.sh b/shared/set-vars.sh index f9ed3d00..ae9657cc 100644 --- a/shared/set-vars.sh +++ b/shared/set-vars.sh @@ -99,6 +99,7 @@ TOOLS=$(find "$DT_SCRIPTS/shared/impact-tools/" -name "*.jar" -not -name "randoo export DT_TOOLS=$(echo $TOOLS | sed -E "s/ /:/g") export SUBJ_NAME="$(echo $DT_SUBJ_ROOT | rev | cut -d'/' -f1 | rev)" +export VER_NAME="$(echo $DT_SUBJ_ROOT | rev | cut -d'/' -f2 | rev)" export ALGO=$(echo "$2" | tr '[:upper:]' '[:lower:]') if [[ "$ALGO" == "t1" ]]; then