#!/usr/bin/env perl use strict; use warnings; local $| = 1 ; # -------------------------------------------------------- # Prototype runtool, this version will generate Nx JUnit test-classes. # -------------------------------------------------------- # -------------------------------------------------------- # Few thing that may need to be re-cofigured # -------------------------------------------------------- my $MYHOME = "/media/sf_T2benchmark/testingtools/t3" ; my $JAVA = "/usr/lib/jvm/jdk1.8.0_05/jre/bin/java" ; my $CPseparator = ":" ; # derived paths, no need to change this my $T3JAR = $MYHOME . "/jars/T3v0.jar" ; my $Junit = $MYHOME . "/jars/junit.jar" ; my $Hamcrest = $MYHOME . "/jars/hamcrest-core-1.3.jar" ; #my $ALLJARS = $MYHOME . "/jars" ; # -------------------------------------------------------- # Some help-functions first ... # -------------------------------------------------------- #sub debugEcho { # print "[debug] " . $_[0] #} sub debugEcho { } sub mkTempDirs { debugEcho "creating temp-dirs" ; my $DATADir = $MYHOME . "/temp/data" ; my $testcasesDir = $MYHOME . "/temp/testcases" ; if (!(-e $DATADir)) { system("mkdir -p " . $DATADir) ; } if (!(-e $testcasesDir)) { system("mkdir -p " . $testcasesDir) ; } } sub BENCHMARKtoken { my $token = readline(*STDIN) ; chomp $token ; if ($token ne "BENCHMARK") { print STDERR "ERROR: expecting BENCHMARK token" ; exit 0 ; } } sub readPath { my $t = ; chomp $t ; return $t ; } sub readNum { my $N = ; chomp $N ; return 0 + $N ; } sub readContextClassPaths { my $N = $_[0] ; my $paths = "." ; my $k ; for ($k=0; $k<$N; $k++) { my $p = ; chomp $p ; $paths = $paths . $CPseparator ; $paths = $paths . $p ; } return $paths ; } # for passing the path to T3-jar .. not sure if this is a good way # to do it. sub announcePathToTestingTool { print "CLASSPATH\n" ; #print "2\n" ; #print ($T3JAR . "\n") ; #print ($ALLJARS . "\n") ; print "1\n" ; print ($T3JAR . "\n") ; print ("READY\n") ; } # replaceIt(s,a,b) replaces occurences of string a in string s, with b sub replaceIt { my $str = $_[0] ; my $find = $_[1]; my $replace = $_[2] ; # escape regex metachars if present: $find = quotemeta $find; $replace = quotemeta $replace; $str =~ s/$find/$replace/g ; return $str ; } # as replaceIt, but without replcing metachars: sub replaceIt2 { my $str = $_[0] ; my $find = $_[1]; my $replace = $_[2] ; $str =~ s/$find/$replace/g ; return $str ; } my $NUMofTestClasses = 50 ; #my $NUMofTestClasses = 10 ; # For creating a Junit test-class wrapper sub mkJunit { my $CUT = $_[0] ; my $CUTdashed = replaceIt($CUT,".","_") ; my $template = $MYHOME . "/T3TestClassWrapper_TC_Template.java" ; open (TemplateFile,"<",$template); # read the template Test-class: my $Test = "" ; while () { $Test = $Test . $_ ; } close (TemplateFile); # generate N-times test-classes my $k=0 ; my $canBreak = 0 ; # avoiding using "break" syntax while ($k < $NUMofTestClasses && $canBreak==0) { my $ADTtestclassName = "ADTTest" . $k . "_" . $CUTdashed ; my $nonADTtestclassName = "nonADTTest" . $k . "_" . $CUTdashed ; my $ADTtestclass = $MYHOME . "/temp/testcases/" . $ADTtestclassName . ".java" ; my $nonADTtestclass = $MYHOME . "/temp/testcases/" . $nonADTtestclassName . ".java" ; $canBreak = 1 ; # for ADT suites: my $ADTtrFilePattern = "ADT_" . $CUT . "_S" . $k ; if (trFileExists($ADTtrFilePattern)) { $canBreak = 0 ; # only generate Junit if the corresponding tr-file exists: open (TestClassFile,">",$ADTtestclass) ; my $Instance = replaceIt2($Test, "xxxClass", $ADTtestclassName) ; $Instance= replaceIt2($Instance,"xxxSuite", $ADTtrFilePattern) ; $Instance = replaceIt2($Instance,"xxxLog" , $MYHOME . "/logs/REPLAY_" . $ADTtestclassName) ; $Instance = replaceIt2($Instance,"xxxTargetDir" , $MYHOME . "/temp/testcases/") ; print TestClassFile $Instance ; close (TestClassFile) ; } # for non-ADT suites: my $nonADTtrFilePattern = "nonADT_" . $CUT . "_S" . $k ; if (trFileExists($nonADTtrFilePattern)) { $canBreak = 0 ; # only generate Junit if the corresponding tr-file exists: open (TestClassFile,">",$nonADTtestclass) ; my $Instance = replaceIt2($Test, "xxxClass", $nonADTtestclassName) ; $Instance= replaceIt2($Instance,"xxxSuite", $nonADTtrFilePattern) ; $Instance = replaceIt2($Instance,"xxxLog" , $MYHOME . "/logs/REPLAY_" . $nonADTtestclassName) ; $Instance = replaceIt2($Instance,"xxxTargetDir" , $MYHOME . "/temp/testcases/") ; print TestClassFile $Instance ; close (TestClassFile) ; } # if neither file exist, canBreak would be 1; and the loop will then break $k ++ ; } } sub trFileExists { my $trFilePattern = $_[0] ; my $TRdir = $MYHOME . "/temp/testcases" ; opendir(DIR, $TRdir) ; while (my $file = readdir(DIR)) { if (index($file, $trFilePattern) != -1) { return 1 ; } } return 0 ; } # to run T3; runT3(CUT,class-dir of CUT, class-path context) sub runT3 { my $CUT = $_[0] ; # the root of the class-directory where CUT resides my $CUTdir = $_[1] ; # class-path to stuffs needed to run CUT: my $contextClassPath = $_[2] ; my $T3 = " Sequenic.T3.T3Cmd " ; my $LOG = $MYHOME . "/logs/GEN_" . $CUT ; # T3 parameters for generating regression sequences. The produced suite # will be split in N smaller suites. my $T3params = "-reg " . "--core=2 " . "--prefixlength=6 --variprefix --suffixlength=1 " . "--msamples=100 " . "--splitsuite=" . $NUMofTestClasses . " " . "--savedir=" . $MYHOME . "/temp/testcases " . "--scandir=" . $CUTdir . " " . "--reportStream=System.err " . "--tracePrintStream=System.err " ; # surpress logging # . " -lf " . $LOG . " " ; my $classpath = "\'" . $T3JAR . $CPseparator . $Junit . $CPseparator . $Hamcrest . $CPseparator . $CUTdir . $CPseparator . $contextClassPath . "\'" ; # now calling T3 the 2nd time, to generate regression suites system( $JAVA . " -ea " . " -Xmx1000m " . "-cp " . $classpath . " " . $T3 . " " . $T3params . " " . $CUT . " >&2" # trying to redirect system.out to system.err ) ; # now generate Junit wrapper too, to prepare for replay: mkJunit($CUT) ; } # run T3 n-times, for each of n CUTs sub runLoop { my $N = $_[0] ; my $CUTdir = $_[1] ; my $contextClassPath = $_[2] ; my $k ; for ($k=0; $k<$N; $k++) { mkTempDirs() ; my $CUT = ; chomp $CUT ; runT3($CUT,$CUTdir,$contextClassPath) ; print ("READY\n") ; } } # -------------------------------------------------------- # Here begins the protocol # -------------------------------------------------------- debugEcho "SBST protocol START\n"; BENCHMARKtoken() ; my $src = readPath() ; my $bin = readPath(); my $numOfContextClassPaths = readNum() ; my $contextClassPath = readContextClassPaths($numOfContextClassPaths) ; my $numOfTargetClasses = readNum() ; announcePathToTestingTool() ; # Now the protocol is going to pass N x CUTs; we run T3 on each of them: runLoop($numOfTargetClasses,$bin,$contextClassPath) ; # DONE. debugEcho "SBST protocol END" ; endDEBUG() ; sub endDEBUG { debugEcho ("src = " . $src . "\n") ; debugEcho ("bin = " . $bin . "\n") ; debugEcho ("N = " . ($numOfContextClassPaths + 1 - 1) . "\n") ; }