summaryrefslogtreecommitdiff
path: root/src/partest
diff options
context:
space:
mode:
authormichelou <michelou@epfl.ch>2007-11-15 16:00:16 +0000
committermichelou <michelou@epfl.ch>2007-11-15 16:00:16 +0000
commita7cd73f5f511a8f3e4589a10fd85b69ccb7fe35b (patch)
tree45804b92095ad2477e9bac7c94eeaea33e659fda /src/partest
parent8fc8fb71ac8df99e06c0c64986d6b4922d902d16 (diff)
downloadscala-a7cd73f5f511a8f3e4589a10fd85b69ccb7fe35b.tar.gz
scala-a7cd73f5f511a8f3e4589a10fd85b69ccb7fe35b.tar.bz2
scala-a7cd73f5f511a8f3e4589a10fd85b69ccb7fe35b.zip
improved code (actor exit problem still pending)
Diffstat (limited to 'src/partest')
-rw-r--r--src/partest/scala/tools/partest/MasterActor.scala6
-rw-r--r--src/partest/scala/tools/partest/TestRunner.scala142
-rw-r--r--src/partest/scala/tools/partest/WorkerActor.scala66
3 files changed, 150 insertions, 64 deletions
diff --git a/src/partest/scala/tools/partest/MasterActor.scala b/src/partest/scala/tools/partest/MasterActor.scala
index 8ead5e5ea8..6f385110ed 100644
--- a/src/partest/scala/tools/partest/MasterActor.scala
+++ b/src/partest/scala/tools/partest/MasterActor.scala
@@ -27,7 +27,7 @@ import utils.PrintMgr._
class MasterActor(testDir: File, out: PrintStream) extends Actor {
import scala.actors.Actor._
- private final val testPathLen = testDir.getPath.length
+ private final val testPathLen = testDir.getAbsolutePath.length
private final val WIDTH = 56
private final val TIMEOUT = 1360000
@@ -129,7 +129,7 @@ class MasterActor(testDir: File, out: PrintStream) extends Actor {
}
counter += 1
printOutline("testing: ")
- val name = file.getPath.substring(testPathLen)
+ val name = file.getAbsolutePath.substring(testPathLen)
print("[...]" + name + List.toString(List.make(WIDTH - name.length, ' ')) + "[")
if (succeeded) {
printSuccess(" OK ")
@@ -143,7 +143,7 @@ class MasterActor(testDir: File, out: PrintStream) extends Actor {
out.println(counter - failed)
out.close
println
- exit
+ System.exit(1) //exit // Help! Philipp.
}
case msg =>
diff --git a/src/partest/scala/tools/partest/TestRunner.scala b/src/partest/scala/tools/partest/TestRunner.scala
index 36c1d13722..f1edfe2d68 100644
--- a/src/partest/scala/tools/partest/TestRunner.scala
+++ b/src/partest/scala/tools/partest/TestRunner.scala
@@ -11,7 +11,8 @@
package scala.tools.partest
import java.awt.event.{ActionEvent, ActionListener}
-import java.io.{File, FilenameFilter, FileOutputStream, PrintStream}
+import java.io.{File, FilenameFilter, FileInputStream, FileOutputStream,
+ PrintStream}
import scala.tools.nsc.Settings
@@ -23,9 +24,10 @@ import utils.PrintMgr._
* @version 1.0
*/
class Test(val kind: String, val file: File) {
- val dir = file.getParent
+ val dir = file.getParentFile
+ val dirpath = dir.getAbsolutePath
protected def baseSettings(settings: Settings) {
- settings.classpath.value = dir
+ settings.classpath.value = dirpath
settings.outdir.value = {
var outDir = new File(dir, fileBase + "-" + kind + ".obj")
outDir.mkdir
@@ -60,15 +62,16 @@ case class JVMTest(override val file: File) extends Test("jvm", file) {
override def defineSettings(settings: Settings) {
baseSettings(settings)
settings.target.value =
- if (dir endsWith "jvm5") "jvm-1.5" else "jvm-1.4"
- settings.classpath.value = System.getProperty("JVMEXTCP")
- TestRunner.printVerbose("CLASSPATH="+settings.classpath.value +"\n")
+ if (dirpath endsWith "jvm5") "jvm-1.5" else "jvm-1.4"
+ settings.classpath.value = System.getProperty("EXT_CLASSPATH")
+ TestRunner.printVerbose("CLASSPATH="+settings.classpath.value)
}
}
case class ShootoutTest(override val file: File) extends Test("shootout", file) {
override def defineSettings(settings: Settings) {
baseSettings(settings)
- settings.classpath.value = System.getProperty("JVMEXTCP")
+ settings.classpath.value = System.getProperty("EXT_CLASSPATH")
+ TestRunner.printVerbose("CLASSPATH="+settings.classpath.value)
}
}
@@ -77,6 +80,9 @@ case class ShootoutTest(override val file: File) extends Test("shootout", file)
* @version 1.0
*/
object TestRunner {
+ private final val version = System.getProperty("java.version", "")
+ private final val isJava5 = version matches "1.[5|6|7].*"
+
private var posCheck = false
private var negCheck = false
private var jvmCheck = false
@@ -86,54 +92,120 @@ object TestRunner {
private var conservative = false
private var verbose = false
- private var testDir: File = _
+ private val srcDir = {
+ val dirname = System.getProperty("scalatest.cwd", "")
+ val dir = if (dirname.isEmpty) { // guess
+ val libDir = new File(classOf[Test].getResource("/").toURI)
+ val path = libDir.getAbsolutePath
+ val parent = libDir.getParentFile
+ val rootDir =
+ if (path contains "quick") parent.getParentFile.getParentFile.getParentFile
+ else if (path contains "dists") parent.getParentFile.getParentFile
+ else parent
+ new File(rootDir, "test" + File.separator + "files")
+ } else
+ new File(dirname)
+ dir
+ }
+ private val testDir = srcDir.getParentFile
+
+ private var testFiles = new collection.mutable.ListBuffer[File]
private val con = new PrintStream(Console.out)
private var out = con
+ private def createTestFile(file: File, suffix: String): File = {
+ def getBaseName(f: File): String = {
+ val name = f.getName
+ val inx = name lastIndexOf '.'
+ if (inx < 0) name else name.substring(0, inx)
+ }
+ def concat(outputFile: File, inputFiles: File*) {
+ val out = new FileOutputStream(outputFile)
+ for (f <- inputFiles) {
+ val in = new FileInputStream(f)
+ val buf = new Array[Byte](1024)
+ var len = 0
+ while (len != -1) {
+ out.write(buf, 0, len)
+ len = in.read(buf)
+ }
+ in.close
+ }
+ out.close
+ }
+ try {
+ val parent = file.getParentFile
+ val outDir = new File(parent, getBaseName(file) + "-" + suffix + ".obj")
+ outDir.mkdir
+ val testfile = new File(outDir, "test.scala")
+ val runnerfile = new File(parent, file.getName + ".runner")
+ concat(testfile, file, runnerfile)
+ testfile
+ }
+ catch {
+ case e: Exception =>
+ println("Couldn't create test file for \"" + file.getPath + "\"")
+ file
+ }
+ }
+
private def go {
val master = new MasterActor(testDir, out)
val filter = new FilenameFilter {
def accept(dir: File, name: String): Boolean = name endsWith ".scala"
}
- def getFiles(kind: String): List[File] = {
- val kindDir = "files" + File.separator + kind
- val dir = new File(testDir, kindDir)
- if (dir.isDirectory) dir.listFiles(filter).toList
- else {
- println("Directory \"" + testDir.getPath + File.separator + kindDir + "\" not found")
+ def getFiles(kind: String, doCheck: Boolean): List[File] = {
+ val dir = new File(srcDir, kind)
+ if (dir.isDirectory) {
+ if (! testFiles.isEmpty) {
+ val dirpath = dir.getAbsolutePath
+ val files = testFiles filter { _.getParentFile.getAbsolutePath == dirpath }
+ files.toList
+ } else if (doCheck)
+ dir.listFiles(filter).toList
+ else // skip
+ Nil
+ } else {
+ println("Directory \"" + dir.getPath + "\" not found")
Nil
}
}
master.start
- if (posCheck) {
+ val posFiles = getFiles("pos", posCheck)
+ if (! posFiles.isEmpty) {
printOutline("Testing compiler (on files whose compilation should succeed)\n")
- for (file <- getFiles("pos")) master ! PosTest(file)
+ for (file <- posFiles) master ! PosTest(file)
}
- if (negCheck) {
+ val negFiles = getFiles("neg", negCheck)
+ if (! negFiles.isEmpty) {
printOutline("Testing compiler (on files whose compilation should fail)\n")
- for (file <- getFiles("neg")) master ! NegTest(file)
+ for (file <- negFiles) master ! NegTest(file)
}
- if (jvmCheck) {
- printOutline("Testing JVM backend\n")
- for (file <- getFiles("jvm")) master ! JVMTest(file)
- for (file <- getFiles("run")) master ! JVMTest(file)
- for (file <- getFiles("jvm5")) master ! JVMTest(file)
- } else if (runCheck) {
+ val jvmFiles = getFiles("jvm", jvmCheck) ::: getFiles("run", jvmCheck) :::
+ getFiles("jvm5", jvmCheck && isJava5)
+ if (! jvmFiles.isEmpty) {
printOutline("Testing JVM backend\n")
- for (file <- getFiles("run")) master ! JVMTest(file)
+ for (file <- jvmFiles) master ! JVMTest(file)
+ } else {
+ val runFiles = getFiles("run", runCheck)
+ if (! runFiles.isEmpty) {
+ printOutline("Testing JVM backend\n")
+ for (file <- runFiles) master ! JVMTest(file)
+ }
}
- if (shootoutCheck) {
+ val shootFiles = getFiles("shootout", shootoutCheck)
+ if (! shootFiles.isEmpty) {
printOutline("Testing shootout benchmarks\n")
- for (file <- getFiles("shootout")) master! ShootoutTest(file)
+ for (file <- shootFiles) master! ShootoutTest(createTestFile(file, "shootout"))
}
master ! ("start", conservative)
}
private def printUsage {
- println("Usage: TestRunner [<options>] <testdir> [<resfile>]")
+ println("Usage: TestRunner [<options>] [<testfile> ..] [<resfile>]")
println(" --pos next files test a compilation success")
println(" --neg next files test a compilation failure")
println(" --jvm next files test the JVM backend")
@@ -160,6 +232,11 @@ object TestRunner {
}
def main(args: Array[String]) {
+ if (!srcDir.isDirectory) {
+ println("Test directory \"" + srcDir.getAbsolutePath + "\" not found")
+ exit(1)
+ }
+ printVerbose(srcDir.getAbsolutePath)
if (args.length == 0)
printUsage
else {
@@ -174,11 +251,12 @@ object TestRunner {
case "--verbose" => verbose = true
case "--version" => printVersion
case _ =>
- if (testDir eq null) {
- val dir = new File(arg)
- if (dir.isDirectory) testDir = dir
+ if (arg endsWith ".scala") {
+ val file = new File(arg)
+ if (file.isFile)
+ testFiles += file
else {
- println("Directory \"" + arg + "\" not found")
+ println("File \"" + arg + "\" not found")
exit(1)
}
} else if (out eq con) {
diff --git a/src/partest/scala/tools/partest/WorkerActor.scala b/src/partest/scala/tools/partest/WorkerActor.scala
index a76a728f56..88bf957582 100644
--- a/src/partest/scala/tools/partest/WorkerActor.scala
+++ b/src/partest/scala/tools/partest/WorkerActor.scala
@@ -55,7 +55,12 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
private val PATH_SEP = java.io.File.pathSeparatorChar
private val CLASSPATH = System.getProperty("CLASSPATH", "")
- private val EXT_CLASSPATH = System.getProperty("JVMEXTCP", "")
+ private val EXT_CLASSPATH = System.getProperty("EXT_CLASSPATH", "")
+
+ private val GREP_COMMAND = "grep"
+ private val GREP_PATTERNS =
+ List("Console.read", "Scheduler.impl",
+ "System.exit", "System.out").foldLeft("")((x, y) => x + " -e " + y)
def act() {
var compiler = newGlobal
@@ -68,9 +73,8 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
var bypassObjectRunner = bypass
if (!bypassObjectRunner) {
// TODO check the shootout source files for "dangerous" patterns, such as: Console.read, Scheduler.impl,
- val dangerousCode = List("Console.read", "Scheduler.impl", "System.exit", "System.out").foldLeft("")((x, y) => x + " -e " + y)
- val grepCmd = "grep " + test.file.getPath + " " + dangerousCode
- TestRunner.printVerbose("grep cmd: " + grepCmd + "\n")
+ val grepCmd = GREP_COMMAND + " " + test.file.getPath + " " + GREP_PATTERNS
+ TestRunner.printVerbose(grepCmd)
val grep = Runtime.getRuntime.exec(grepCmd)
@@ -101,7 +105,7 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
compiler = newGlobal(test.logFile)
case JVMTest(_) =>
- //println(test.file.getPath + ": " + test.checkFile.exists + " / " + test.logFile.exists)
+ TestRunner.printVerbose(test.file.getPath + ": " + test.checkFile.exists + " / " + test.logFile.exists)
if (test.checkFile.exists) {
var checkReader = new BufferedReader(new FileReader(test.checkFile))
var firstLine = checkReader.readLine
@@ -164,24 +168,25 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
case _ =>
}
- var result = test match {
+ var success = test match {
case NegTest(_) => reporter.hasErrors
case _ => !reporter.hasErrors
}
- (bypassObjectRunner, result, test) match {
+ (bypassObjectRunner, success, test) match {
case (_, _, PosTest(_)) =>
case (_, _, NegTest(_)) =>
case (false, true, _) =>
+ /*
System.setProperty("scalatest.output", outDir.toString)
test match {
case ShootoutTest(_) => System.setProperty("scalatest.cwd", test.dir)
case _ => {}
}
-
+ */
var classpath: List[URL] =
outDir.toURL ::
- List((new File(test.dir)).toURL) :::
+ List(test.dir.toURL) :::
(List.fromString(CLASSPATH, PATH_SEP) map { x => (new File(x)).toURL }) :::
(List.fromString(EXT_CLASSPATH, PATH_SEP) map { x => (new File(x)).toURL })
@@ -194,18 +199,21 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
out.flush
out.close
//println(this.toString + " " + "Finished running " + test.fileBase)
- } catch { case t => println(t) }
+ } catch {
+ case e =>
+ println(e + " (" + test.file.getPath + ")")
+ }
case _ =>
}
- (!bypassObjectRunner && result, test.checkFile.exists, test) match {
+ (!bypassObjectRunner && success, test.checkFile.exists, test) match {
case (_, _, PosTest(_)) =>
case (true, true, _) =>
/*var cmd: String = "diff " + test.logFile + " " + test.checkFile
//println(this.toString + " Comparing files " + test.fileBase)
var proc: Process = Runtime.getRuntime.exec(cmd)
proc.waitFor
- result = (proc.exitValue == 0)*/
+ success = (proc.exitValue == 0)*/
var equalNow = true
if (test.checkFile.canRead) {
val originStream = new FileInputStream(test.logFile)
@@ -216,43 +224,43 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
for (idx <- 0 until originSize)
equalNow = equalNow && (originBuffer(idx) == destBuffer(idx))
if (!equalNow) {
- result = false
+ success = false
//println("Diff1: diffs found")
}
}
else {
- result = false
+ success = false
//println("Diff1: diffs found")
}
originSize = originStream.read(originBuffer)
}
- if (destStream.read(destBuffer) >= 0) result = false
+ if (destStream.read(destBuffer) >= 0) success = false
}
case _ =>
//println("Not testing diff... " + test.test)
}
- (bypassObjectRunner || !result, test) match {
+ (bypassObjectRunner || !success, test) match {
case (_, PosTest(_)) =>
case (_, NegTest(_)) =>
case (true, _) =>
- result = true
+ success = true
//var javaoptsFile = new File(test.dir, test.fileBase + ".javaopts")
//var javaNewOpts = (new BufferedFileReader(javaoptsFile)).readLine
//if (javaoptsFile.exists && javaNewOpts != null) {}
//Use Runtime.exec to execute the compiled file and pipe the standard system
//out and the console out to the logfile
- var cmd =
- "env JAVACMD=java JAVA_OPTS=-Djava.library.path=\"" + test.dir + "\" " +
+ val cmd =
+ "env JAVACMD=java JAVA_OPTS=-Djava.library.path=\"" + test.dirpath + "\" " +
System.getProperty("SCALA")+
" -Dscalatest.lib=\"" + System.getProperty("scalatest.lib") + "\" " +
- "-Dscalatest.cwd=\"" + test.dir + "\" " +
+ "-Dscalatest.cwd=\"" + test.dirpath + "\" " +
"-Dscalatest.output=" + outDir +
" -classpath " + outDir + PATH_SEP + CLASSPATH + PATH_SEP + EXT_CLASSPATH +
" Test jvm"
- TestRunner.printVerbose("Worker command: " + cmd)
+ TestRunner.printVerbose(cmd)
var execution = Runtime.getRuntime.exec(cmd)
@@ -273,7 +281,7 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
/*var diff = Runtime.getRuntime.exec("diff " + test.logFile + " " + test.checkFile)
diff.waitFor
- result = (diff.exitValue == 0)*/
+ success = (diff.exitValue == 0)*/
var equalNow = true
if (test.checkFile.canRead) {
val originStream = new FileInputStream(test.logFile)
@@ -284,33 +292,33 @@ class WorkerActor(val master: MasterActor, val settings: Settings, var reporter:
for (idx <- 0 until originSize)
equalNow = equalNow && (originBuffer(idx) == destBuffer(idx))
if (!equalNow) {
- result = false
+ success = false
//println("Differences found between the log and check files..")
}
}
else {
- result = false
+ success = false
//println("Differences found between the log and check files..")
}
originSize = originStream.read(originBuffer)
}
- if (destStream.read(destBuffer) >= 0) result = false
+ if (destStream.read(destBuffer) >= 0) success = false
}
//else reportMissing(originFile)
case _ =>
//println("Not Using runtime... " + test.test)
}
- test.logFile.delete
+ if (success) test.logFile.delete
var end = System.currentTimeMillis
//println(test.test + ": " + (end - start))
- //printSuccess(this.toString + " " + fileBase + ": "+ result + "\n")
- master ! (test.kind, result, test.file)
- dirDelete(outDir)
+ //println(this.toString + ": "+ success)
+ master ! (test.kind, success, test.file)
+ if (success) dirDelete(outDir)
}
case false =>
exit