package Common; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.file.DirectoryStream; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; import java.util.Map; import org.junit.Test; import static Sequenic.T3.SuiteUtils.Query.SeqPredicate.* ; import Sequenic.T3.Pool; import Sequenic.T3.Info.ObjectCoverage; import Sequenic.T3.Sequence.Datatype.SUITE; import static Sequenic.T3.SuiteUtils.Query.LTLQuery.* ; import static Sequenic.T3.SuiteUtils.Query.AlgQuery.* ; public class Common { // the dir where the CUT and its friends can be found: //static private String binpath = "D:/workshop/EclipseT3workspace/T2benchmark/bin" ; static private String binpath = "/media/sf_T2benchmark/build/CUTclasses" ; // the dir to put the generated trace file //static private String trdir = "D:/workshop/EclipseT3workspace/T2benchmark" ; static private String trdir = "/media/sf_T2benchmark/testingtools/t3custom/temp/data" ; static private String JAVA8HOME = "/usr/lib/jvm/jdk1.8.0_05" ; static public String getCUTrootBindir() { String binpath_ = System.getProperty("CUTrootBindir") ; if (binpath_ != null) return binpath_ ; else return binpath ; } static public String getTrDir() { String trdir_ = System.getProperty("TraceFileDir") ; if (trdir_ != null) return trdir_ ; return trdir ; } public static boolean trFileAlreadyExists(String CUT) throws Exception { DirectoryStream stream = Files.newDirectoryStream(FileSystems.getDefault().getPath(trdir)) ; for (Path entry: stream) { if (Files.isDirectory(entry)) continue ; String entry_ = entry.getFileName().toString() ; if (entry_.startsWith("ADT_" + CUT)) return true ; } return false ; } public static void replay(String prefix) throws Throwable { Sequenic.T3.ReplayCmd.main(" " // reg. expre prefix(.)* to match a prefix : + " --bulk=" + prefix + "(.)*" + " --regressionmode" + " --reportStream=System.err" + " --tracePrintStream=System.err" + " -sx" + " " + trdir ) ; } public static void replayCUTtest(String CUT) throws Throwable { if (! Common.trFileAlreadyExists(CUT)) throw new Sequenic.T3.T3Exception("No trace file found!") ; else { //System.out.println("Trace files exist...") ; Common.replay("ADT_" + CUT) ; Common.replay("nonADT_" + CUT); } } public static Process runShellCommand(String... command) throws Exception { ProcessBuilder pb = new ProcessBuilder(command) ; System.err.println("** " + pb.command()) ; Map env = pb.environment(); env.put("JAVA_HOME", JAVA8HOME); Process P = pb.start() ; return P ; } /** * Run a specification-checker. The checker is a Groovy-script. */ public static boolean checkSpecification(String groovyfile) throws Exception { //BufferedReader br = runShellCommand("cmd", "/C", "echo %JAVA_HOME%") ; //BufferedReader br = runShellCommand("c:/cygwin/bin/bash.exe","-c","java -version") ; String classpath = "/media/sf_T2benchmark/testingtools/t3/jars/interactiveT3v0.jar" + ":/media/sf_T2benchmark/build/CUTclasses" + ":/media/sf_T2benchmark/testingtools/t3custom/commonbin" ; Process P = runShellCommand("bash", "-c", "groovy -cp " + classpath + " " + groovyfile) ; InputStream output = P.getInputStream(); //InputStream output = P.getErrorStream(); BufferedReader br = new BufferedReader(new InputStreamReader(output)); String line; while ((line = br.readLine()) != null) { System.err.println(line) ; if (line.startsWith("**false**")) return false ; } P.waitFor() ; return true ; } public static boolean checkSpecification(String traceprefix, LTL query) throws Exception { List suites = SUITE.loadMany(traceprefix,getTrDir()) ; System.err.println("*** Reading " + suites.size() + " suites") ; for (SUITE S : suites) { System.err.print("** Check-specing " + S.suitename + " (" + S.suite.size() + "seqs ) ... ") ; //S.exec(new Pool(), null,-1, 3, true, true, false, System.err) ; if (!ltlquery(S).with(query).valid()) { System.err.println("not valid!") ; return false ; } System.err.println("valid") ; } return true ; } }