#!/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/t3custom" ; my $JAVA = "/usr/lib/jvm/jdk1.8.0_05/jre/bin/java" ; my $CPseparator = ":" ; # derived paths, no need to change this my $T3JAR = $MYHOME . "/../t3/jars/interactiveT3v0.jar" ; my $Junit = $MYHOME . "/../t3/jars/junit.jar" ; my $Hamcrest = $MYHOME . "/../t3/jars/hamcrest-core-1.3.jar" ; my $Groovy = $MYHOME . "/../t3/jars/groovy-all-2.3.6.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 "4\n" ; print ($T3JAR . "\n") ; print ($Groovy . "\n") ; print ($MYHOME . "/commonbin\n") ; print ($MYHOME . "/bin\n") ; print ("READY\n") ; } # for obtaining the class-name and package-path from a full class-name sub getSimpleClassName { my $CUT = $_[0] ; my @nameElements = split('\.',$CUT) ; return @nameElements[$#nameElements] ; } sub getPackagePath { my $CUT = $_[0] ; my @nameElements = split('\.',$CUT) ; my $path = join('/', @nameElements[0 .. ($#nameElements - 1)]) ; return ("/" . $path) ; } sub getPackageQualifiedName { my $CUT = $_[0] ; my @nameElements = split('\.',$CUT) ; my $name = join('.', @nameElements[0 .. ($#nameElements - 1)]) ; return $name ; } sub createPackageDir { my $CUT = $_[0] ; my @nameElements = split('\.',$CUT) ; for (my $i = 0; $i < $#nameElements; $i++) { my $dir = $MYHOME . "/temp/testcases/" . join('/', @nameElements[0 .. $i]) ; system("mkdir " . $dir) ; } } # For copying the test-class source sub copyTestClass { my $CUT = $_[0] ; my $testclass = getPackagePath($CUT) . "/ReplayTest" . getSimpleClassName($CUT) . ".java" ; my $additionalTestclass = getPackagePath($CUT) . "/AdditionalTest" . getSimpleClassName($CUT) . ".java" ; createPackageDir($CUT) ; system("cp " . $MYHOME . "/tests" . $testclass . " " . $MYHOME . "/temp/testcases" . $testclass ) ; if (!(-e ($MYHOME . "/tests" . $additionalTestclass))) { system("cp " . $MYHOME . "/tests" . $additionalTestclass . " " . $MYHOME . "/temp/testcases" . $additionalTestclass ) ; } } # to run a T3 test-class to generate a trace file sub runT3testclass { my $CUT = $_[0] ; my $CUTdir = $_[1] ; my $contextClassPath = $_[2] ; my $pckgName = getPackageQualifiedName($CUT) ; my $testclass = "T3Test" . getSimpleClassName($CUT) ; if ($pckgName ne "") { $testclass = $pckgName . "." . $testclass ; } my $classpath = "\'" . $T3JAR . $CPseparator . $Junit . $CPseparator . $Hamcrest . $CPseparator . $MYHOME . "/commonbin" . $CPseparator . $MYHOME . "/bin" . $CPseparator . $CUTdir . $CPseparator . $contextClassPath . "\'" ; # now calling the test-class to generate regression suites: system( $JAVA . " -ea " . " -Xmx1000m " . "-cp " . $classpath . " " . "org.junit.runner.JUnitCore " . $testclass . " >&2" # trying to redirect system.out to system.err ) ; } # do runT3testclass 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 ; runT3testclass($CUT,$CUTdir,$contextClassPath) ; copyTestClass($CUT) ; 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") ; }