From 47d64b7980080083b97e5fe89bdbf53f19002030 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 27 Apr 2017 15:12:31 +0200 Subject: [PATCH] Abort compilation after `maxCompileTime` --- compiler/test/dotc/comptest.scala | 1 + .../test/dotty/tools/dotc/CompilationTests.scala | 1 + .../test/dotty/tools/vulpix/ParallelTesting.scala | 13 ++++++++++++- compiler/test/dotty/tools/vulpix/VulpixTests.scala | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler/test/dotc/comptest.scala b/compiler/test/dotc/comptest.scala index 8737ef165f94..87058b12e559 100644 --- a/compiler/test/dotc/comptest.scala +++ b/compiler/test/dotc/comptest.scala @@ -7,6 +7,7 @@ import scala.concurrent.duration._ object comptest extends ParallelTesting { def maxDuration = 3.seconds + def maxCompileTime = 1.minute def numberOfSlaves = 5 def safeMode = false def isInteractive = true diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 91a453494760..391c47bfe599 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -19,6 +19,7 @@ class CompilationTests extends ParallelTesting { // Test suite configuration -------------------------------------------------- + def maxCompileTime = 9.minutes def maxDuration = 30.seconds def numberOfSlaves = 5 def safeMode = Properties.testsSafeMode diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index b0312523d892..4178446e946e 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -15,6 +15,9 @@ import scala.util.Try import scala.collection.mutable import scala.util.matching.Regex import scala.util.Random +import scala.concurrent.duration.Duration +import scala.concurrent.{ Await, Future } +import scala.concurrent.ExecutionContext.Implicits.global import dotc.core.Contexts._ import dotc.reporting.{ Reporter, TestReporter } @@ -44,6 +47,11 @@ trait ParallelTesting extends RunnerOrchestration { self => */ def testFilter: Option[String] + /** To ensure that compilation is not run infinitely, we await it for this + * duration + */ + def maxCompileTime: Duration + /** A test source whose files or directory of files is to be compiled * in a specific way defined by the `Test` */ @@ -373,13 +381,16 @@ trait ParallelTesting extends RunnerOrchestration { self => val allArgs = addOutDir(flags) // Compile with a try to catch any StackTrace generated by the compiler: - try { + val compilation = Future { driver.process(allArgs ++ files.map(_.getAbsolutePath), reporter = reporter) val javaFiles = files.filter(_.getName.endsWith(".java")).map(_.getAbsolutePath) assert(compileWithJavac(javaFiles), s"java compilation failed for ${javaFiles.mkString(", ")}") } + + try Await.result(compilation, maxCompileTime) catch { + case ex: TimeoutException => throw ex case NonFatal(ex) => reporter.logStackTrace(ex) } diff --git a/compiler/test/dotty/tools/vulpix/VulpixTests.scala b/compiler/test/dotty/tools/vulpix/VulpixTests.scala index f875e7c13232..886a24cd5c0f 100644 --- a/compiler/test/dotty/tools/vulpix/VulpixTests.scala +++ b/compiler/test/dotty/tools/vulpix/VulpixTests.scala @@ -14,6 +14,7 @@ class VulpixTests extends ParallelTesting { implicit val _: SummaryReporting = new NoSummaryReport def maxDuration = 3.seconds + def maxCompileTime= 10.seconds def numberOfSlaves = 5 def safeMode = sys.env.get("SAFEMODE").isDefined def isInteractive = !sys.env.contains("DRONE") @@ -73,4 +74,10 @@ class VulpixTests extends ParallelTesting { @Test def deadlock: Unit = compileFile("../tests/partest-test/deadlock.scala", defaultOptions).expectFailure.checkRuns() + + /** We alow for maximum 10 seconds of compile time, compiling the standard + * library takes a biiiit longer (> 30 seconds) + */ + @Test def infiniteCompile: Unit = + compileList("compileStdLib", StdLibSources.whitelisted, scala2Mode.and("-migration", "-Yno-inline")).expectFailure.checkCompile() }