Skip to content

Commit 3345c82

Browse files
committed
Implement meta tests suggested by @DarkDimius
Note that merging this as-is will not protect us against fork bombs. This is because the timeout of tests is currently 180 seconds. A forkbomb that is allowed to run for that long...
1 parent a3d8112 commit 3345c82

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed

compiler/test/dotty/tools/vulpix/VulpixTests.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ class VulpixTests extends ParallelTesting {
5959

6060
@Test def runOutRedirects: Unit =
6161
compileFile("../tests/partest-test/i2147.scala", defaultOptions).expectFailure.checkRuns()
62+
63+
@Test def infiteNonRec: Unit =
64+
compileFile("../tests/partest-test/infinite.scala", defaultOptions).expectFailure.checkRuns()
65+
66+
@Test def infiteTailRec: Unit =
67+
compileFile("../tests/partest-test/infiniteTail.scala", defaultOptions).expectFailure.checkRuns()
68+
69+
@Test def infiteAlloc: Unit =
70+
compileFile("../tests/partest-test/infiniteAlloc.scala", defaultOptions).expectFailure.checkRuns()
71+
72+
@Test def deadlock: Unit =
73+
compileFile("../tests/partest-test/deadlock.scala", defaultOptions).expectFailure.checkRuns()
74+
75+
@Test def forkbomb: Unit =
76+
compileFile("../tests/partest-test/forkbomb.scala", defaultOptions).expectFailure.checkRuns()
6277
}

tests/partest-test/deadlock.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
object Test {
2+
class Lock
3+
val lock1 = new Lock
4+
val lock2 = new Lock
5+
6+
private[this] var took2: Boolean = false
7+
def lock2Taken(): Unit = synchronized {
8+
took2 = true
9+
notify()
10+
}
11+
def tookLock2: Boolean = synchronized(took2)
12+
13+
val thread1 = new Thread {
14+
override def run(): Unit = synchronized {
15+
lock1.synchronized {
16+
while (!tookLock2) wait()
17+
lock2.synchronized {
18+
println("thread1 in lock2!")
19+
}
20+
}
21+
println("thread1, done!")
22+
}
23+
}
24+
25+
val thread2 = new Thread {
26+
override def run(): Unit = synchronized {
27+
lock2.synchronized {
28+
lock2Taken()
29+
lock1.synchronized {
30+
println("thread2 in lock1!")
31+
}
32+
}
33+
println("thread2, done!")
34+
}
35+
}
36+
37+
def main(args: Array[String]): Unit = {
38+
thread1.start() // takes lock1 then sleeps 1s - tries to take lock2
39+
thread2.start() // takes lock2 then sleeps 1s - tries to take lock1
40+
41+
thread1.join() // wait for threads to complete, can't because deadlock!
42+
thread2.join()
43+
}
44+
}

tests/partest-test/forkbomb.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def main(args: Array[String]): Unit =
3+
while(true)
4+
Runtime
5+
.getRuntime()
6+
.exec(Array("java", "-cp", System.getProperty("java.class.path"), "Test"));
7+
}

tests/partest-test/infinite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
def main(args: Array[String]): Unit = {
3+
var sum = 0
4+
while(true) {
5+
sum += 1
6+
}
7+
println(sum)
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.collection.mutable
2+
object Test {
3+
val map = mutable.Map.empty[String, String]
4+
5+
def main(args: Array[String]): Unit = while (true) {
6+
val time = System.currentTimeMillis.toString
7+
map += (time -> time)
8+
}
9+
}

tests/partest-test/infiniteTail.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
def foo: Int = bar
3+
def bar: Int = foo
4+
5+
def main(args: Array[String]): Unit =
6+
println(foo)
7+
}

0 commit comments

Comments
 (0)