[Native][tests] Read stdout/stderr of test process in separate threads

Sometimes, the launched test process can't finish on Windows if stdout and stderr threads are not read completely. The proper approach here would be to spawn two threads for constantly reading stdout & stderr while the process in being executed.
This commit is contained in:
Dmitriy Dolovov
2021-12-07 12:06:43 +03:00
parent 50d766166b
commit 8e98deb3b0
5 changed files with 146 additions and 71 deletions
@@ -0,0 +1,31 @@
// KIND: STANDALONE_NO_TR
import kotlin.math.E
import kotlin.math.sqrt
import kotlin.system.getTimeMillis
import kotlin.test.assertTrue
// Runs for ~60 seconds. Prints a short message to stdout every second.
fun main() {
for (i in 0..60) {
println("Iteration $i")
sleep(1000)
}
println("Done.")
}
private fun sleep(millis: Int) {
assertTrue(millis > 0)
val endTimeMillis = getTimeMillis() + millis
do {
// Emulate intensive computations to spend CPU time.
for (i in 1..100) {
for (j in 1..100) {
storage = if (storage.toLong() % 2 == 0L) sqrt(i.toDouble() * j.toDouble()) else E * i / j
}
}
} while (getTimeMillis() < endTimeMillis)
}
private var storage: Double = 0.0
@@ -0,0 +1,40 @@
// KIND: STANDALONE_NO_TR
import kotlin.math.E
import kotlin.math.sqrt
import kotlin.system.getTimeMillis
import kotlin.test.assertEquals
import kotlin.test.assertTrue
// Runs for ~60 seconds. Prints 200 thousand bytes to stdout every second.
fun main() {
assertEquals(10, TEN_BYTES_STRING.length)
for (i in 0..60) {
repeat(200) { print1000Bytes() }
sleep(1000)
}
println("Done.")
}
private fun sleep(millis: Int) {
assertTrue(millis > 0)
val endTimeMillis = getTimeMillis() + millis
do {
// Emulate intensive computations to spend CPU time.
for (i in 1..100) {
for (j in 1..100) {
storage = if (storage.toLong() % 2 == 0L) sqrt(i.toDouble() * j.toDouble()) else E * i / j
}
}
} while (getTimeMillis() < endTimeMillis)
}
private fun print1000Bytes() {
// Print 1000 bytes.
repeat(100) { print(TEN_BYTES_STRING) }
}
private var storage: Double = 0.0
private const val TEN_BYTES_STRING = "Hi, test!\n"
@@ -0,0 +1,16 @@
// KIND: STANDALONE_NO_TR
import kotlin.test.assertEquals
// Prints 1_000_000 bytes to stdout and exits.
fun main() {
assertEquals(10, TEN_BYTES_STRING.length)
repeat(1000) { print1000Bytes() }
}
private fun print1000Bytes() {
// Print 1000 bytes.
repeat(100) { print(TEN_BYTES_STRING) }
}
private const val TEN_BYTES_STRING = "Hi, test!\n"