Skip to content

Commit 7925ec9

Browse files
authored
Added setting for suppressing child process errors (#337)
1 parent f8569df commit 7925ec9

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ object UtSettings {
274274
DEFAULT_CONCRETE_EXECUTION_TIMEOUT_IN_CHILD_PROCESS_MS
275275
)
276276

277+
/**
278+
* Determines whether should errors from a child process be written to a log file or suppressed.
279+
* Note: being enabled, this option can highly increase disk usage when using ContestEstimator.
280+
*
281+
* False by default (for saving disk space).
282+
*/
283+
var logConcreteExecutionErrors by getBooleanProperty(false)
284+
277285
/**
278286
* Number of branch instructions using for clustering executions in the test minimization phase.
279287
*/

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcessRunner.kt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.instrumentation.process
22

3+
import mu.KotlinLogging
34
import org.utbot.common.bracket
45
import org.utbot.common.debug
56
import org.utbot.common.firstOrNullResourceIS
@@ -9,11 +10,11 @@ import org.utbot.common.pid
910
import org.utbot.common.scanForResourcesContaining
1011
import org.utbot.common.utBotTempDirectory
1112
import org.utbot.framework.JdkPathService
13+
import org.utbot.framework.UtSettings
1214
import org.utbot.instrumentation.Settings
1315
import org.utbot.instrumentation.agent.DynamicClassTransformer
1416
import java.io.File
1517
import java.nio.file.Paths
16-
import mu.KotlinLogging
1718

1819
private val logger = KotlinLogging.logger {}
1920
private var processSeqN = 0
@@ -30,19 +31,24 @@ class ChildProcessRunner {
3031
debugCmd + listOf("-javaagent:$jarFile", "-ea", "-jar", "$jarFile")
3132
}
3233

33-
lateinit var errorLogFile: File
34+
var errorLogFile: File = NULL_FILE
3435

3536
fun start(): Process {
3637
logger.debug { "Starting child process: ${cmds.joinToString(" ")}" }
3738
processSeqN++
3839

39-
val dir = File(utBotTempDirectory.toFile(), ERRORS_FILE_PREFIX)
40-
dir.mkdirs()
41-
errorLogFile = File(dir, "${hashCode()}-${processSeqN}.log")
40+
if (UtSettings.logConcreteExecutionErrors) {
41+
UT_BOT_TEMP_DIR.mkdirs()
42+
errorLogFile = File(UT_BOT_TEMP_DIR, "${hashCode()}-${processSeqN}.log")
43+
}
4244

4345
val processBuilder = ProcessBuilder(cmds).redirectError(errorLogFile)
4446
return processBuilder.start().also {
45-
logger.debug { "Process started with PID=${it.pid} , error log: ${errorLogFile.absolutePath}" }
47+
logger.debug { "Process started with PID=${it.pid}" }
48+
49+
if (UtSettings.logConcreteExecutionErrors) {
50+
logger.debug { "Child process error log: ${errorLogFile.absolutePath}" }
51+
}
4652
}
4753
}
4854

@@ -53,6 +59,16 @@ class ChildProcessRunner {
5359

5460
private const val DEBUG_RUN_CMD = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=5005"
5561

62+
private val UT_BOT_TEMP_DIR: File = File(utBotTempDirectory.toFile(), ERRORS_FILE_PREFIX)
63+
64+
private val NULL_FILE_PATH: String = if (System.getProperty("os.name").startsWith("Windows")) {
65+
"NUL"
66+
} else {
67+
"/dev/null"
68+
}
69+
70+
private val NULL_FILE = File(NULL_FILE_PATH)
71+
5672
/**
5773
* * Firstly, searches for utbot-instrumentation jar in the classpath.
5874
*

0 commit comments

Comments
 (0)