#!/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 = "." ; my $JAVA = "/usr/lib/jvm/java-8-oracle/bin/java" ; my $JAVAC = "/usr/lib/jvm/java-8-oracle/bin/javac" ; my $CPseparator = ":" ; # derived paths, no need to change this my $T3JAR = $MYHOME . "/libs/interactiveT3v0.jar" ; my $GroovyJAR = $MYHOME . "/libs/groovy-all-2.3.6.jar" ; my $MySBSTPack = $MYHOME . "/build/MySBSTPack" ; my $StandIns = $MYHOME . "/standins" ; my $Junit = $MYHOME . "/tools/junit-4.10.jar" ; # -------------------------------------------------------- # Some help-functions first ... # -------------------------------------------------------- #sub debugEcho { # print "[debug] " . $_[0] #} sub debugEcho { } sub mkTempDirs { debugEcho "creating temp-dirs" ; my $TracesDir = $MYHOME . "/temp/traces" ; my $testcasesDir = $MYHOME . "/temp/testcases" ; if (!(-e $TracesDir)) { system("mkdir -p " . $TracesDir) ; } 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 sub announcePathToTestingTool { print "CLASSPATH\n" ; print "7\n" ; print ($T3JAR . "\n") ; print ($GroovyJAR . "\n") ; print ($MySBSTPack . "\n") ; print ($StandIns . "\n") ; print ($MYHOME . "/libs/reflections-0.9.9-RC1-uberjar.jar" . "\n") ; print ($MYHOME . "/libs/javassist.jar" . "\n") ; print ($MYHOME . "/libs/guava-18.0.jar" . "\n") ; print ("READY\n") ; } # 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] ; # location to put the traces: my $traceDir = $MYHOME . "/temp/traces" ; # location to put the generated Junit classes : my $whereToPutGeneratedJunits = $MYHOME . "/temp/testcases" ; my $classpath1 = "\'" # CUT paths: ... this should be given first, to make sure that they are loaded first in case # the CUT happens to be used by mySBSTPack: . $CUTdir . $CPseparator . $contextClassPath # T3 related paths: . $GroovyJAR . $CPseparator . $T3JAR . $CPseparator . $MySBSTPack . $CPseparator . $StandIns . $CPseparator . $Junit . $CPseparator # some additional libraries used by MySBSTPack: (it strangely needs Predicate from guava .. dont know why...) . $MYHOME . "/libs/reflections-0.9.9-RC1-uberjar.jar" . $CPseparator . $MYHOME . "/libs/javassist.jar" . $CPseparator . $MYHOME . "/libs/guava-18.0.jar" . $CPseparator . "\'" ; my $classpath2 = "\'" . $GroovyJAR . $CPseparator . $T3JAR . $CPseparator . $MySBSTPack . $CPseparator . $StandIns . "\'" ; # generate a stand-in class, as needed: my $compileCmd = "\"" . $JAVAC . " -cp " . $classpath1 . "\"" ; system( $JAVA . " -cp " . $classpath1 . " SBST2015.StandInGeneratorCmd " . $CUT . " " . $StandIns . " " . $compileCmd ) ; # now calling T3 to generate the test suites .... turning off -ea option system( $JAVA . " -Xmx1000m" . " -cp " . $classpath1 . " SBST2015.GenCmd " . $CUT . " " . $CUTdir . " " . $traceDir . " >&2" # trying to redirect system.out to system.err ) ; # now generate Junit classes: system( $JAVA . " -cp " . $classpath2 . " SBST2015.JUnitGeneratorCmd" . " " . $CUT . " " . $traceDir . " " . $whereToPutGeneratedJunits . " >&2" # trying to redirect system.out to system.err ) ; } # 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") ; }