aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2017-03-31 11:50:07 +0200
committerFelix Mulder <felix.mulder@gmail.com>2017-03-31 16:45:12 +0200
commited10ef0208f794060b5351cc601a915177e0a1c5 (patch)
treeff68342c68381cbb693995f3043d03a7d7546229
parent57a11776480ab5259281dd29777c45af9ea3ca78 (diff)
downloaddotty-ed10ef0208f794060b5351cc601a915177e0a1c5.tar.gz
dotty-ed10ef0208f794060b5351cc601a915177e0a1c5.tar.bz2
dotty-ed10ef0208f794060b5351cc601a915177e0a1c5.zip
Fix deadlock in `runAll`
-rw-r--r--compiler/test/dotty/tools/dotc/ParallelSummaryReport.java4
-rw-r--r--compiler/test/dotty/tools/dotc/ParallelTesting.scala45
-rw-r--r--compiler/test/dotty/tools/dotc/reporting/TestReporter.scala51
3 files changed, 51 insertions, 49 deletions
diff --git a/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java b/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java
index d32cda974..5608b3656 100644
--- a/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java
+++ b/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java
@@ -13,7 +13,7 @@ import dotty.tools.dotc.reporting.TestReporter$;
public class ParallelSummaryReport {
public final static boolean isInteractive = !System.getenv().containsKey("DRONE");
- private static TestReporter rep = TestReporter.reporter(-1);
+ private static TestReporter rep = TestReporter.reporter(System.out, -1);
private static ArrayDeque<String> failedTests = new ArrayDeque<>();
private static ArrayDeque<String> reproduceInstructions = new ArrayDeque<>();
private static int passed;
@@ -36,7 +36,7 @@ public class ParallelSummaryReport {
}
@BeforeClass public final static void setup() {
- rep = TestReporter.reporter(-1);
+ rep = TestReporter.reporter(System.out, -1);
failedTests = new ArrayDeque<>();
reproduceInstructions = new ArrayDeque<>();
}
diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
index 990a856ca..c1da7807b 100644
--- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala
+++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala
@@ -174,6 +174,8 @@ trait ParallelTesting { self =>
* according to the implementing class "neg", "run" or "pos".
*/
private abstract class Test(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean) {
+ protected final val realStdout = System.out
+ protected final val realStderr = System.err
/** Actual compilation run logic, the test behaviour is defined here */
protected def compilationRunnable(testSource: TestSource): Runnable
@@ -192,10 +194,10 @@ trait ParallelTesting { self =>
val sourceCount = filteredSources.length
private[this] var _errorCount = 0
- def errorCount: Int = synchronized { _errorCount }
+ def errorCount: Int = _errorCount
private[this] var _testSourcesCompiled = 0
- private def testSourcesCompiled : Int = synchronized { _testSourcesCompiled }
+ private def testSourcesCompiled: Int = _testSourcesCompiled
/** Complete the current compilation with the amount of errors encountered */
protected final def registerCompilation(errors: Int) = synchronized {
@@ -228,7 +230,7 @@ trait ParallelTesting { self =>
/** Prints to `System.err` if we're not suppressing all output */
protected def echo(msg: String): Unit =
- if (!suppressAllOutput) System.err.println(msg)
+ if (!suppressAllOutput) realStderr.println(msg)
/** A single `Runnable` that prints a progress bar for the curent `Test` */
private def createProgressMonitor: Runnable = new Runnable {
@@ -238,17 +240,19 @@ trait ParallelTesting { self =>
while (tCompiled < sourceCount) {
val timestamp = (System.currentTimeMillis - start) / 1000
val progress = (tCompiled.toDouble / sourceCount * 40).toInt
- print(
+
+ realStdout.print(
"[" + ("=" * (math.max(progress - 1, 0))) +
(if (progress > 0) ">" else "") +
(" " * (39 - progress)) +
s"] compiling ($tCompiled/$sourceCount, ${timestamp}s)\r"
)
+
Thread.sleep(100)
tCompiled = testSourcesCompiled
}
// println, otherwise no newline and cursor at start of line
- println(
+ realStdout.println(
s"[=======================================] compiled ($sourceCount/$sourceCount, " +
s"${(System.currentTimeMillis - start) / 1000}s) "
)
@@ -259,7 +263,10 @@ trait ParallelTesting { self =>
* if it did, the test should automatically fail.
*/
protected def tryCompile(testSource: TestSource)(op: => Unit): Unit =
- try op catch {
+ try {
+ if (!isInteractive) realStdout.println(s"Testing ${testSource.title}")
+ op
+ } catch {
case NonFatal(e) => {
// if an exception is thrown during compilation, the complete test
// run should fail
@@ -309,8 +316,10 @@ trait ParallelTesting { self =>
Runtime.getRuntime.exec(fullArgs).waitFor() == 0
} else true
- val reporter = TestReporter.parallelReporter(this, logLevel =
- if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
+ val reporter =
+ TestReporter.reporter(realStdout, logLevel =
+ if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
+
val driver =
if (times == 1) new Driver { def newCompiler(implicit ctx: Context) = new Compiler }
else new Driver {
@@ -353,8 +362,12 @@ trait ParallelTesting { self =>
}
pool.shutdown()
- if (!pool.awaitTermination(10, TimeUnit.MINUTES))
+ if (!pool.awaitTermination(20, TimeUnit.MINUTES)) {
+ pool.shutdownNow()
+ System.setOut(realStdout)
+ System.setErr(realStderr)
throw new TimeoutException("Compiling targets timed out")
+ }
if (didFail) {
reportFailed()
@@ -417,8 +430,6 @@ trait ParallelTesting { self =>
import java.net.{ URL, URLClassLoader }
val printStream = new ByteArrayOutputStream
- val oldOut = System.out
- val oldErr = System.err
try {
// Do classloading magic and running here:
@@ -426,7 +437,7 @@ trait ParallelTesting { self =>
val cls = ucl.loadClass("Test")
val meth = cls.getMethod("main", classOf[Array[String]])
- self.synchronized {
+ synchronized {
try {
val ps = new PrintStream(printStream)
System.setOut(ps)
@@ -436,9 +447,13 @@ trait ParallelTesting { self =>
meth.invoke(null, Array("jvm")) // partest passes at least "jvm" as an arg
}
}
- } finally {
- System.setOut(oldOut)
- System.setErr(oldErr)
+ System.setOut(realStdout)
+ System.setErr(realStderr)
+ } catch {
+ case t: Throwable =>
+ System.setOut(realStdout)
+ System.setErr(realStderr)
+ throw t
}
}
}
diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
index 2d7e6c70a..5641240a7 100644
--- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
+++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala
@@ -2,7 +2,7 @@ package dotty.tools
package dotc
package reporting
-import java.io.{ PrintWriter, File => JFile, FileOutputStream }
+import java.io.{ PrintStream, PrintWriter, File => JFile, FileOutputStream }
import java.text.SimpleDateFormat
import java.util.Date
@@ -93,38 +93,25 @@ object TestReporter {
logWriter.flush()
}
- def parallelReporter(lock: AnyRef, logLevel: Int): TestReporter = new TestReporter(
- new PrintWriter(Console.err, true),
- str => lock.synchronized {
- logWriter.println(str)
- logWriter.flush()
- },
- logLevel
- )
-
- def reporter(logLevel: Int): TestReporter = new TestReporter(
- new PrintWriter(Console.err, true),
- writeToLog,
- logLevel
- )
-
- def simplifiedReporter(writer: PrintWriter): TestReporter = new TestReporter(
- writer,
- writeToLog,
- WARNING
- ) {
- /** Prints the message with the given position indication in a simplified manner */
- override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
- val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
- val extraInfo = inlineInfo(m.pos)
-
- writer.println(msg)
- _messageBuf.append(msg)
-
- if (extraInfo.nonEmpty) {
- writer.println(extraInfo)
- _messageBuf.append(extraInfo)
+ def reporter(ps: PrintStream, logLevel: Int): TestReporter =
+ new TestReporter(new PrintWriter(ps, true), writeToLog, logLevel)
+
+ def simplifiedReporter(writer: PrintWriter): TestReporter = {
+ val rep = new TestReporter(writer, writeToLog, WARNING) {
+ /** Prints the message with the given position indication in a simplified manner */
+ override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = {
+ val msg = s"${m.pos.line + 1}: " + m.contained.kind + extra
+ val extraInfo = inlineInfo(m.pos)
+
+ writer.println(msg)
+ _messageBuf.append(msg)
+
+ if (extraInfo.nonEmpty) {
+ writer.println(extraInfo)
+ _messageBuf.append(extraInfo)
+ }
}
}
+ rep
}
}