package sbst.runtool; import java.io.File; import java.util.List; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; public class Randoop implements ITestingTool{ List classPath; static final String randoopJar = System.getProperty("sbst.benchmark.randoop"); public List getExtraClassPath(){ return null; } public void initialize(File src, File bin, List classPath){ this.classPath = classPath; } public void run(String cName){ try{ StringBuilder sb = new StringBuilder(); for(int i = 0; i < classPath.size(); i++){ if(i > 0) sb.append(":"); sb.append(classPath.get(i)); } randoop(sb.toString(), cName); }catch(IOException ioe){ ioe.printStackTrace(); throw new RuntimeException("Failed to run Randoop"); } } private boolean randoop(String cp, String cut) throws IOException { final String javaCmd = "java"; ProcessBuilder pbuilder = new ProcessBuilder(javaCmd, "-Xmx512m", "-classpath", randoopJar + ":" + cp, "randoop.main.Main", "gentests", "--testclass=" + cut, /*"--timelimit=120", "--outputlimit=100", "--output-tests=all",*/ "--junit-output-dir=./temp/testcases/"); pbuilder.redirectErrorStream(true); Process process = null; InputStreamReader stdout = null; InputStream stderr = null; OutputStreamWriter stdin = null; boolean mutationExitStatus = false; process = pbuilder.start(); stderr = process.getErrorStream(); stdout = new InputStreamReader(process.getInputStream()); stdin = new OutputStreamWriter(process.getOutputStream()); BufferedReader reader = new BufferedReader(stdout); String line = null; while((line = reader.readLine()) != null) { //System.out.println(line); } reader.close(); try { process.waitFor(); } catch (InterruptedException e) { e.printStackTrace(); } int exitStatus = process.exitValue(); //System.out.println("exit status = " + exitStatus); mutationExitStatus = exitStatus == 0; if(stdout !=null) stdout.close(); if(stdin !=null) stdin.close(); if(stderr !=null) stderr.close(); if(process !=null) process.destroy(); new File("./temp/testcases/RandoopTest.java").delete(); return mutationExitStatus; } }