Skip to content

Commit 6cecfef

Browse files
committed
[rd-factoring]
review fix
1 parent 5e0685a commit 6cecfef

File tree

15 files changed

+49
-38
lines changed

15 files changed

+49
-38
lines changed

docs/RD for UnitTestBot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Other processes ask this process for settings via RD RPC.
138138

139139
### Engine process
140140

141-
`TestCaseGenerator` and `UtBotSymbolicEngine` runs here. Process classpath contains all plugin jars(more precisely - it uses plugin classpath).
141+
`TestCaseGenerator` and `UtBotSymbolicEngine` run here. Process classpath contains all plugin jars(more precisely - it uses plugin classpath).
142142

143143
___Must___ run on JDK, which uses project we analyze. Otherwise there will be numerous problems with code analysis, soot, reflection and
144144
devirgention of generated code Java API.

docs/contributing/InterProcessDebugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ For engine and instrumented processes you need to enable some options:
3232
4. Additionally, you can set additional options for JDWP agent if debug is enabled:
3333
* `engineProcessDebugPort` and `instrumentedProcessDebugPort` - port for debugging.
3434
Default values - 5005 for Engine and 5006 for Instrumented processes.
35-
* `engineProcessDebugSuspendPolicy` and `instrumentedProcessSuspendPolicy` - whether JDWP agent should
35+
* `suspendEngineProcessExecutionInDebugMode` and `suspendInstrumentedProcessExecutionInDebugMode` - whether JDWP agent should
3636
suspend process until debugger is connected.
3737

3838
More formally, if debug is enabled following switch is added to engine process JVM at start by default:
@@ -44,7 +44,7 @@ For engine and instrumented processes you need to enable some options:
4444
```
4545
runEngineProcessWithDebug=true
4646
engineProcessDebugPort=12345
47-
engineProcessDebugSuspendPolicy=false
47+
suspendEngineProcessExecutionInDebugMode=false
4848
```
4949
result switch will be:
5050
```

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private const val defaultKeyForSettingsPath = "utbot.settings.path"
2020
/**
2121
* Default concrete execution timeout (in milliseconds).
2222
*/
23-
const val DEFAULT_CONCRETE_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS = 1000L
23+
const val DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS = 1000L
2424

2525
object UtSettings : AbstractSettings(
2626
logger, defaultKeyForSettingsPath, defaultSettingsPath
@@ -261,7 +261,7 @@ object UtSettings : AbstractSettings(
261261
* Timeout for specific concrete execution (in milliseconds).
262262
*/
263263
var concreteExecutionTimeoutInInstrumentedProcess: Long by getLongProperty(
264-
DEFAULT_CONCRETE_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
264+
DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
265265
)
266266

267267
// region engine process debug
@@ -274,35 +274,39 @@ object UtSettings : AbstractSettings(
274274
var engineProcessLogConfigFile by getStringProperty("")
275275

276276
/**
277-
* Property useful only for idea
278-
* If true - runs engine process with the ability to attach a debugger
277+
* The property is useful only for the IntelliJ IDEs.
278+
* If the property is set in true the engine process opens a debug port.
279279
* @see runInstrumentedProcessWithDebug
280280
* @see org.utbot.intellij.plugin.process.EngineProcess
281281
*/
282282
var runEngineProcessWithDebug by getBooleanProperty(false)
283283

284284
/**
285-
* Port which will be used for debugging engine process
285+
* The engine process JDWP agent's port of the instrumented process.
286+
* A debugger attaches to the port in order to debug the process.
286287
*/
287288
var engineProcessDebugPort by getIntProperty(5005)
288289

289290
/**
290-
* Whether engine process should suspend until debugger attached
291+
* Value of the suspend mode for the JDWP agent of the engine process.
292+
* If the value is true, the engine process will suspend until a debugger attaches to it.
291293
*/
292-
var engineProcessDebugSuspendPolicy by getBooleanProperty(true)
294+
var suspendEngineProcessExecutionInDebugMode by getBooleanProperty(true)
293295

294296
// endregion
295297

296298
// region instrumented process debug
297299
/**
298-
* Port which will be used for debugging instrumented process
300+
* The instrumented process JDWP agent's port of the instrumented process.
301+
* A debugger attaches to the port in order to debug the process.
299302
*/
300303
var instrumentedProcessDebugPort by getIntProperty(5006)
301304

302305
/**
303-
* Whether instrumented process should suspend until debugger attached
306+
* Value of the suspend mode for the JDWP agent of the instrumented process.
307+
* If the value is true, the instrumented process will suspend until a debugger attaches to it.
304308
*/
305-
var instrumentedProcessSuspendPolicy by getBooleanProperty(true)
309+
var suspendInstrumentedProcessExecutionInDebugMode by getBooleanProperty(true)
306310

307311
/**
308312
* If true, runs the instrumented process with the ability to attach a debugger.

utbot-framework-api/src/main/kotlin/org/utbot/framework/process/OpenModulesContainer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import org.utbot.framework.plugin.services.JdkInfoService
44

55
object OpenModulesContainer {
66
private val modulesContainer: List<String>
7-
val javaVersionSpecificArguments: List<String>?
7+
val javaVersionSpecificArguments: List<String>
88
get() = modulesContainer
9-
.takeIf { JdkInfoService.provide().version > 8 }
9+
.takeIf { JdkInfoService.provide().version > 8 } ?: emptyList()
1010

1111
init {
1212
modulesContainer = buildList {

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.framework.codegen.domain
22

3-
import org.utbot.framework.DEFAULT_CONCRETE_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
3+
import org.utbot.framework.DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
44
import org.utbot.framework.codegen.domain.builtin.mockitoClassId
55
import org.utbot.framework.codegen.domain.builtin.ongoingStubbingClassId
66
import org.utbot.framework.codegen.domain.models.CgClassId
@@ -581,7 +581,7 @@ data class HangingTestsTimeout(val timeoutMs: Long) {
581581
constructor() : this(DEFAULT_TIMEOUT_MS)
582582

583583
companion object {
584-
const val DEFAULT_TIMEOUT_MS = DEFAULT_CONCRETE_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
584+
const val DEFAULT_TIMEOUT_MS = DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS
585585
const val MIN_TIMEOUT_MS = 100L
586586
const val MAX_TIMEOUT_MS = 1_000_000L
587587
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ConcreteExecutor<TIResult, TInstrumentation : Instrumentation<TIResult>> p
242242
val parametersByteArray = kryoHelper.writeObject(parameters)
243243
val params = InvokeMethodCommandParams(className, signature, argumentsByteArray, parametersByteArray)
244244

245-
val ba = chidlProcessModel.invokeMethodCommand.startSuspending(lifetime, params).result
245+
val ba = instrumentedProcessModel.invokeMethodCommand.startSuspending(lifetime, params).result
246246
kryoHelper.readObject(ba)
247247
}
248248
} catch (e: Throwable) {
@@ -282,7 +282,7 @@ class ConcreteExecutor<TIResult, TInstrumentation : Instrumentation<TIResult>> p
282282
if (alive) {
283283
try {
284284
processInstance?.run {
285-
chidlProcessModel.stopProcess.start(lifetime, Unit)
285+
instrumentedProcessModel.stopProcess.start(lifetime, Unit)
286286
}
287287
} catch (_: Exception) {}
288288
processInstance = null
@@ -296,7 +296,7 @@ class ConcreteExecutor<TIResult, TInstrumentation : Instrumentation<TIResult>> p
296296

297297
fun ConcreteExecutor<*,*>.warmup() = runBlocking {
298298
withProcess {
299-
chidlProcessModel.warmup.start(lifetime, Unit)
299+
instrumentedProcessModel.warmup.start(lifetime, Unit)
300300
}
301301
}
302302

@@ -308,7 +308,7 @@ fun <T> ConcreteExecutor<*, *>.computeStaticField(fieldId: FieldId): Result<T> =
308308
val fieldIdSerialized = kryoHelper.writeObject(fieldId)
309309
val params = ComputeStaticFieldParams(fieldIdSerialized)
310310

311-
val result = chidlProcessModel.computeStaticField.startSuspending(lifetime, params)
311+
val result = instrumentedProcessModel.computeStaticField.startSuspending(lifetime, params)
312312

313313
kryoHelper.readObject(result.result)
314314
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/coverage/CoverageInstrumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ fun ConcreteExecutor<Result<*>, CoverageInstrumentation>.collectCoverage(clazz:
103103
withProcess {
104104
val clazzByteArray = kryoHelper.writeObject(clazz)
105105

106-
kryoHelper.readObject(chidlProcessModel.collectCoverage.startSuspending(lifetime, CollectCoverageParams(clazzByteArray)).coverageInfo)
106+
kryoHelper.readObject(instrumentedProcessModel.collectCoverage.startSuspending(lifetime, CollectCoverageParams(clazzByteArray)).coverageInfo)
107107
}
108108
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private val logger = KotlinLogging.logger {}
1818
class InstrumentedProcessRunner {
1919
private val cmds: List<String> by lazy {
2020
val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { UtSettings.runInstrumentedProcessWithDebug })
21-
val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments ?: emptyList()
21+
val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments
2222
val pathToJava = JdkInfoService.provide().path
2323

2424
listOf(pathToJava.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}").toString()) +
@@ -59,7 +59,7 @@ class InstrumentedProcessRunner {
5959
}
6060

6161
companion object {
62-
private fun suspendValue(): String = if (UtSettings.engineProcessDebugSuspendPolicy) "y" else "n"
62+
private fun suspendValue(): String = if (UtSettings.suspendInstrumentedProcessExecutionInDebugMode) "y" else "n"
6363

6464
private const val UTBOT_INSTRUMENTATION = "utbot-instrumentation"
6565
private const val ERRORS_FILE_PREFIX = "utbot-instrumentedprocess-errors"

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/InstrumentedProcess.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class InstrumentedProcess private constructor(
3232
val kryoHelper = KryoHelper(lifetime.createNested()).apply {
3333
classLoader?.let { setKryoClassLoader(it) }
3434
}
35-
val chidlProcessModel: InstrumentedProcessModel = onSchedulerBlocking { protocol.instrumentedProcessModel }
35+
val instrumentedProcessModel: InstrumentedProcessModel = onSchedulerBlocking { protocol.instrumentedProcessModel }
3636

3737
companion object {
3838
suspend operator fun <TIResult, TInstrumentation : Instrumentation<TIResult>> invoke(
@@ -65,15 +65,15 @@ class InstrumentedProcess private constructor(
6565
}
6666

6767
logger.trace("sending add paths")
68-
proc.chidlProcessModel.addPaths.startSuspending(
68+
proc.instrumentedProcessModel.addPaths.startSuspending(
6969
proc.lifetime, AddPathsParams(
7070
pathsToUserClasses,
7171
pathsToDependencyClasses
7272
)
7373
)
7474

7575
logger.trace("sending instrumentation")
76-
proc.chidlProcessModel.setInstrumentation.startSuspending(
76+
proc.instrumentedProcessModel.setInstrumentation.startSuspending(
7777
proc.lifetime, SetInstrumentationParams(
7878
proc.kryoHelper.writeObject(instrumentation)
7979
)

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/process/EngineProcess.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
9090

9191
private val log4j2ConfigSwitch = "-Dlog4j2.configurationFile=${log4j2ConfigFile.canonicalPath}"
9292

93-
private fun suspendValue(): String = if (UtSettings.engineProcessDebugSuspendPolicy) "y" else "n"
93+
private fun suspendValue(): String = if (UtSettings.suspendEngineProcessExecutionInDebugMode) "y" else "n"
9494

9595
private val debugArgument: String?
9696
get() = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=${suspendValue()},quiet=y,address=${UtSettings.engineProcessDebugPort}"
@@ -111,7 +111,10 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
111111
private fun obtainEngineProcessCommandLine(port: Int) = buildList {
112112
add(javaExecutablePathString.pathString)
113113
add("-ea")
114-
OpenModulesContainer.javaVersionSpecificArguments?.let { addAll(it) }
114+
val javaVersionSpecificArgs = vaOpenModulesContainer.javaVersionSpecificArguments
115+
if (javaVersionSpecificArgs.isNotEmpty()) {
116+
addAll(it)
117+
}
115118
debugArgument?.let { add(it) }
116119
add(log4j2ConfigSwitch)
117120
add("-cp")

utbot-rd/src/main/kotlin/org/utbot/rd/ClientProcessUtil.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal fun childCreatedFileName(port: Int): String {
3030
return "$port.created"
3131
}
3232

33-
internal fun signalInstrumentedReady(port: Int) {
33+
internal fun signalProcessReady(port: Int) {
3434
processSyncDirectory.mkdirs()
3535

3636
val signalFile = File(processSyncDirectory, childCreatedFileName(port))
@@ -161,7 +161,7 @@ class ClientProtocolBuilder {
161161
clientProtocol.block(synchronizer)
162162
}
163163

164-
signalInstrumentedReady(port)
164+
signalProcessReady(port)
165165
logger.info { "signalled" }
166166
clientProtocol.synchronizationModel.synchronizationSignal.let { sync ->
167167
val answerFromMainProcess = sync.adviseForConditionAsync(ldef) {

utbot-rd/src/main/kotlin/org/utbot/rd/RdSettingsContainer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RdSettingsContainer(val logger: KLogger, val key: String, val settingsMode
3535
}
3636

3737
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
38-
throw NotImplementedError("Setting properties allowed only from plugin process")
38+
throw IllegalStateException("Setting properties allowed only from plugin process")
3939
}
4040
}
4141
}

utbot-rd/src/main/kotlin/org/utbot/rd/UtRdCoroutineScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class UtRdCoroutineScope(lifetime: Lifetime) : RdCoroutineScope(lifetime) {
1111
companion object {
1212
val current = UtRdCoroutineScope(Lifetime.Eternal)
1313
fun initialize() {
14-
// only to initialize load and initialize class
14+
// only to load and initialize class
1515
}
1616
}
1717

utbot-rd/src/main/kotlin/org/utbot/rd/UtRdUtil.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ suspend fun <T> ProcessWithRdServer.onScheduler(block: () -> T): T {
2222

2323
fun <T> ProcessWithRdServer.onSchedulerBlocking(block: () -> T): T = runBlocking { onScheduler(block) }
2424

25-
2625
fun <TReq, TRes> IRdCall<TReq, TRes>.startBlocking(req: TReq): TRes {
2726
val call = this
2827
// We do not use RdCall.sync because it requires timeouts for execution, after which request will be stopped.
@@ -75,11 +74,12 @@ suspend fun <T> IScheduler.pump(lifetime: Lifetime, block: (Lifetime) -> T): T {
7574
suspend fun <T> IScheduler.pump(block: (Lifetime) -> T): T = this.pump(Lifetime.Eternal, block)
7675

7776
/**
78-
* Advises provided condition on source and returns Deferred,
79-
* which will be completed when condition satisfied, or cancelled when provided lifetime terminated.
80-
* If you don't need this condition no more - you can cancel deferred.
77+
* Asynchronously checks the condition.
78+
* The condition can be satisfied or canceled.
79+
* As soon as the condition is checked, the lifetime is terminated.
80+
* In order to cancel the calculation, use the function return value of Deferred type.
8181
*
82-
* N.B. in case you need timeout - wrap deferred in withTimeout coroutine builder
82+
* @see kotlinx.coroutines.withTimeout coroutine builder in case you need cancel the calculation by timeout.
8383
*/
8484
fun <T> ISource<T>.adviseForConditionAsync(lifetime: Lifetime, condition: (T) -> Boolean): Deferred<Unit> {
8585
val ldef = lifetime.createNested()

utbot-rd/src/main/kotlin/org/utbot/rd/exceptions/InstantProcessDeathException.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package org.utbot.rd.exceptions
22

3+
/**
4+
* This exception is designed to be thrown any time you start child process,
5+
* but
6+
*/
37
abstract class InstantProcessDeathException(private val debugPort: Int, private val isProcessDebug: Boolean) : Exception() {
48
override val message: String?
59
get() {

0 commit comments

Comments
 (0)