Skip to content

Commit fb4b6a3

Browse files
committed
[engine-process]
Moved engine process out of the main idea process. Changes include: 1. Reactive settings 2. Removing all JDK9+ api calls to support out-of-the process execution on JDK8 3. Refactored client protocol initialization, ClientProcessBuilder introduced 4. Big refactoring
1 parent 560ac03 commit fb4b6a3

File tree

55 files changed

+2735
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2735
-703
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mock-maker-inline

utbot-core/src/main/kotlin/org/utbot/common/AbstractSettings.kt

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,33 @@ import java.util.*
66
import mu.KLogger
77
import org.utbot.common.PathUtil.toPath
88
import kotlin.properties.PropertyDelegateProvider
9+
import kotlin.properties.ReadWriteProperty
910
import kotlin.reflect.KProperty
1011

11-
abstract class AbstractSettings(
12+
interface SettingsContainer {
13+
fun <T> settingFor(defaultValue: T, converter: (String) -> T): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>>
14+
}
15+
16+
interface SettingsContainerFactory {
17+
fun createSettingsContainer(
18+
logger: KLogger,
19+
defaultKeyForSettingsPath: String,
20+
defaultSettingsPath: String? = null) : SettingsContainer
21+
}
22+
23+
class PropertiesSettingsContainer(
1224
private val logger: KLogger,
1325
defaultKeyForSettingsPath: String,
14-
defaultSettingsPath: String? = null
15-
) {
16-
protected val properties = Properties().also { props ->
26+
defaultSettingsPath: String? = null): SettingsContainer {
27+
companion object: SettingsContainerFactory {
28+
override fun createSettingsContainer(
29+
logger: KLogger,
30+
defaultKeyForSettingsPath: String,
31+
defaultSettingsPath: String?
32+
): SettingsContainer = PropertiesSettingsContainer(logger, defaultKeyForSettingsPath, defaultSettingsPath)
33+
}
34+
35+
private val properties = Properties().also { props ->
1736
val settingsPath = System.getProperty(defaultKeyForSettingsPath) ?: defaultSettingsPath
1837
val settingsPathFile = settingsPath?.toPath()?.toFile()
1938
if (settingsPathFile?.exists() == true) {
@@ -27,18 +46,18 @@ abstract class AbstractSettings(
2746
}
2847
}
2948

30-
protected val settingsValues: MutableMap<KProperty<*>, Any?> = mutableMapOf()
49+
private val settingsValues: MutableMap<KProperty<*>, Any?> = mutableMapOf()
3150

32-
inner class SettingDelegate<T>(val property: KProperty<*>, val initializer: () -> T) {
51+
inner class SettingDelegate<T>(val property: KProperty<*>, val initializer: () -> T): ReadWriteProperty<Any?, T> {
3352
private var value = initializer()
3453

3554
init {
3655
updateSettingValue()
3756
}
3857

39-
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = value
58+
override operator fun getValue(thisRef: Any?, property: KProperty<*>): T = value
4059

41-
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
60+
override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
4261
this.value = value
4362
updateSettingValue()
4463
}
@@ -48,10 +67,10 @@ abstract class AbstractSettings(
4867
}
4968
}
5069

51-
protected fun <T> getProperty(
70+
override fun <T> settingFor(
5271
defaultValue: T,
5372
converter: (String) -> T
54-
): PropertyDelegateProvider<Any?, SettingDelegate<T>> {
73+
): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>> {
5574
return PropertyDelegateProvider { _, property ->
5675
SettingDelegate(property) {
5776
try {
@@ -64,17 +83,51 @@ abstract class AbstractSettings(
6483
}
6584
}
6685

86+
override fun toString(): String =
87+
settingsValues
88+
.mapKeys { it.key.name }
89+
.entries
90+
.sortedBy { it.key }
91+
.joinToString(separator = System.lineSeparator()) { "\t${it.key}=${it.value}" }
92+
}
93+
94+
abstract class AbstractSettings(
95+
logger: KLogger,
96+
defaultKeyForSettingsPath: String,
97+
defaultSettingsPath: String? = null) {
98+
private val container: SettingsContainer = createSettingsContainer(logger, defaultKeyForSettingsPath, defaultSettingsPath)
99+
init {
100+
allSettings[defaultKeyForSettingsPath] = this
101+
}
102+
companion object : SettingsContainerFactory {
103+
val allSettings = mutableMapOf<String, AbstractSettings>()
104+
private var factory: SettingsContainerFactory? = null
105+
override fun createSettingsContainer(
106+
logger: KLogger,
107+
defaultKeyForSettingsPath: String,
108+
defaultSettingsPath: String?
109+
): SettingsContainer {
110+
return (factory ?: PropertiesSettingsContainer).createSettingsContainer(logger, defaultKeyForSettingsPath, defaultSettingsPath)
111+
}
112+
113+
fun setupFactory(factory: SettingsContainerFactory) {
114+
this.factory = factory
115+
}
116+
}
117+
118+
protected fun <T> getProperty(
119+
defaultValue: T,
120+
converter: (String) -> T
121+
): PropertyDelegateProvider<Any?, ReadWriteProperty<Any?, T>> {
122+
return container.settingFor(defaultValue, converter)
123+
}
124+
67125
protected fun getBooleanProperty(defaultValue: Boolean) = getProperty(defaultValue, String::toBoolean)
68126
protected fun getIntProperty(defaultValue: Int) = getProperty(defaultValue, String::toInt)
69127
protected fun getLongProperty(defaultValue: Long) = getProperty(defaultValue, String::toLong)
70128
protected fun getStringProperty(defaultValue: String) = getProperty(defaultValue) { it }
71129
protected inline fun <reified T : Enum<T>> getEnumProperty(defaultValue: T) =
72130
getProperty(defaultValue) { enumValueOf(it) }
73131

74-
override fun toString(): String =
75-
settingsValues
76-
.mapKeys { it.key.name }
77-
.entries
78-
.sortedBy { it.key }
79-
.joinToString(separator = System.lineSeparator()) { "\t${it.key}=${it.value}" }
132+
override fun toString(): String = container.toString()
80133
}

utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.lang.reflect.InvocationTargetException
44
import java.lang.reflect.Method
55
import kotlin.reflect.KClass
66

7-
val Class<*>.packageName: String get() = `package`?.name?:""
7+
val Class<*>.nameOfPackage: String get() = `package`?.name?:""
88

99
fun Method.invokeCatching(obj: Any?, args: List<Any?>) = try {
1010
Result.success(invoke(obj, *args.toTypedArray()))

utbot-core/src/main/kotlin/org/utbot/common/Logging.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.utbot.common
22

33
import mu.KLogger
4+
import java.time.format.DateTimeFormatter
45

6+
val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
57

68
class LoggerWithLogMethod(val logger: KLogger, val logMethod: (() -> Any?) -> Unit)
79

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

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.framework
22

33
import mu.KotlinLogging
44
import org.utbot.common.AbstractSettings
5+
import org.utbot.common.PropertiesSettingsContainer
56
import kotlin.reflect.KProperty
67

78
private val logger = KotlinLogging.logger {}
@@ -17,30 +18,6 @@ internal val utbotHomePath = "${System.getProperty("user.home")}/.utbot"
1718
private val defaultSettingsPath = "$utbotHomePath/settings.properties"
1819
private const val defaultKeyForSettingsPath = "utbot.settings.path"
1920

20-
/**
21-
* Stores current values for each setting from [UtSettings].
22-
*/
23-
private val settingsValues: MutableMap<KProperty<*>, Any?> = mutableMapOf()
24-
25-
internal class SettingDelegate<T>(val property: KProperty<*>, val initializer: () -> T) {
26-
private var value = initializer()
27-
28-
init {
29-
updateSettingValue()
30-
}
31-
32-
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = value
33-
34-
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
35-
this.value = value
36-
updateSettingValue()
37-
}
38-
39-
private fun updateSettingValue() {
40-
settingsValues[property] = value
41-
}
42-
}
43-
4421
/**
4522
* Default concrete execution timeout (in milliseconds).
4623
*/
@@ -282,12 +259,12 @@ object UtSettings : AbstractSettings(
282259
)
283260

284261
/**
285-
* Determines whether should errors from a child process be written to a log file or suppressed.
262+
* Determines whether should errors from a child process and idea engine process be written to a log file or suppressed.
286263
* Note: being enabled, this option can highly increase disk usage when using ContestEstimator.
287264
*
288265
* False by default (for saving disk space).
289266
*/
290-
var logConcreteExecutionErrors by getBooleanProperty(false)
267+
var logConcreteExecutionErrors by getBooleanProperty(true)
291268

292269
/**
293270
* Number of branch instructions using for clustering executions in the test minimization phase.

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,7 @@ import org.utbot.framework.plugin.api.util.shortClassId
3333
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
3434
import org.utbot.framework.plugin.api.util.toReferenceTypeBytecodeSignature
3535
import org.utbot.framework.plugin.api.util.voidClassId
36-
import soot.ArrayType
37-
import soot.BooleanType
38-
import soot.ByteType
39-
import soot.CharType
40-
import soot.DoubleType
41-
import soot.FloatType
42-
import soot.IntType
43-
import soot.LongType
44-
import soot.RefType
45-
import soot.ShortType
46-
import soot.SootClass
47-
import soot.Type
48-
import soot.VoidType
36+
import soot.*
4937
import soot.jimple.JimpleBody
5038
import soot.jimple.Stmt
5139
import java.io.File
@@ -131,8 +119,8 @@ class UtSymbolicExecution(
131119
stateAfter: EnvironmentModels,
132120
result: UtExecutionResult,
133121
val instrumentation: List<UtInstrumentation>,
134-
val path: MutableList<Step>,
135-
val fullPath: List<Step>,
122+
var path: MutableList<Step>,
123+
var fullPath: List<Step>,
136124
coverage: Coverage? = null,
137125
summary: List<DocStatement>? = null,
138126
testMethodName: String? = null,

utbot-framework/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ dependencies {
1414
api project(':utbot-instrumentation')
1515
api project(':utbot-summary')
1616
api project(':utbot-framework-api')
17+
api project(':utbot-rd')
1718

1819
implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: '2022.3.1'
1920
implementation group: 'com.jetbrains.rd', name: 'rd-core', version: '2022.3.1'
2021

2122
implementation "com.github.UnitTestBot:soot:${sootCommitHash}"
23+
implementation group: 'com.esotericsoftware.kryo', name: 'kryo5', version: kryoVersion
24+
// this is necessary for serialization of some collections
25+
implementation group: 'de.javakaffee', name: 'kryo-serializers', version: kryoSerializersVersion
2226

2327
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: jacksonVersion
2428
implementation group: 'org.sosy-lab', name: 'javasmt-solver-z3', version: javasmtSolverZ3Version
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.utbot.analytics
2+
3+
import mu.KotlinLogging
4+
import org.utbot.framework.PathSelectorType
5+
import org.utbot.framework.UtSettings
6+
7+
private val logger = KotlinLogging.logger {}
8+
9+
object AnalyticsConfigureUtil {
10+
/**
11+
* Configures utbot-analytics models for the better path selection.
12+
*
13+
* NOTE: If analytics configuration for the NN Path Selector could not be loaded,
14+
* it switches to the [PathSelectorType.INHERITORS_SELECTOR].
15+
*/
16+
fun configureML() {
17+
logger.info { "PathSelectorType: ${UtSettings.pathSelectorType}" }
18+
19+
if (UtSettings.pathSelectorType == PathSelectorType.ML_SELECTOR) {
20+
val analyticsConfigurationClassPath = UtSettings.analyticsConfigurationClassPath
21+
tryToSetUpMLSelector(analyticsConfigurationClassPath)
22+
}
23+
24+
if (UtSettings.pathSelectorType == PathSelectorType.TORCH_SELECTOR) {
25+
val analyticsConfigurationClassPath = UtSettings.analyticsTorchConfigurationClassPath
26+
tryToSetUpMLSelector(analyticsConfigurationClassPath)
27+
}
28+
}
29+
30+
private fun tryToSetUpMLSelector(analyticsConfigurationClassPath: String) {
31+
try {
32+
Class.forName(analyticsConfigurationClassPath)
33+
Predictors.stateRewardPredictor = EngineAnalyticsContext.mlPredictorFactory()
34+
35+
logger.info { "RewardModelPath: ${UtSettings.modelPath}" }
36+
} catch (e: ClassNotFoundException) {
37+
logger.error {
38+
"Configuration of the predictors from the utbot-analytics module described in the class: " +
39+
"$analyticsConfigurationClassPath is not found!"
40+
}
41+
42+
logger.info(e) {
43+
"Error while initialization of ${UtSettings.pathSelectorType}. Changing pathSelectorType on INHERITORS_SELECTOR"
44+
}
45+
UtSettings.pathSelectorType = PathSelectorType.INHERITORS_SELECTOR
46+
}
47+
catch (e: Exception) { // engine not found, for example
48+
logger.error { e.message }
49+
UtSettings.pathSelectorType = PathSelectorType.INHERITORS_SELECTOR
50+
}
51+
}
52+
53+
}

utbot-framework/src/main/kotlin/org/utbot/engine/Mocks.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utbot.engine
22

33
import org.utbot.api.mock.UtMock
4-
import org.utbot.common.packageName
54
import org.utbot.engine.overrides.UtArrayMock
65
import org.utbot.engine.overrides.UtLogicMock
76
import org.utbot.engine.overrides.UtOverrideMock

utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.external.api
22

33
import org.utbot.common.FileUtil
4+
import org.utbot.common.nameOfPackage
45
import org.utbot.framework.UtSettings
56
import org.utbot.framework.codegen.ForceStaticMocking
67
import org.utbot.framework.codegen.Junit5
@@ -57,7 +58,7 @@ object UtBotJavaApi {
5758
staticsMocking: StaticsMocking = NoStaticMocking,
5859
generateWarningsForStaticMocking: Boolean = false,
5960
forceStaticMocking: ForceStaticMocking = ForceStaticMocking.DO_NOT_FORCE,
60-
testClassPackageName: String = classUnderTest.packageName
61+
testClassPackageName: String = classUnderTest.nameOfPackage
6162
): String {
6263

6364
val utContext = UtContext(classUnderTest.classLoader)

utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.external.api
22

3+
import org.utbot.common.nameOfPackage
34
import org.utbot.framework.assemble.AssembleModelGenerator
45
import org.utbot.framework.plugin.api.ClassId
56
import org.utbot.framework.plugin.api.ExecutableId
@@ -48,7 +49,7 @@ class UtModelFactory(
4849
classUnderTest: Class<*>,
4950
models: List<UtModel>
5051
): IdentityHashMap<UtModel, UtModel> =
51-
AssembleModelGenerator(classUnderTest.packageName)
52+
AssembleModelGenerator(classUnderTest.nameOfPackage)
5253
.createAssembleModels(models)
5354

5455
@JvmOverloads

utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.framework.assemble
22

33
import org.utbot.common.isPrivate
44
import org.utbot.common.isPublic
5+
import org.utbot.common.nameOfPackage
56
import org.utbot.engine.ResolvedExecution
67
import org.utbot.engine.ResolvedModels
78
import org.utbot.framework.UtSettings
@@ -400,7 +401,7 @@ class AssembleModelGenerator(private val methodPackageName: String) {
400401
get() = this.isPublic || !this.isPrivate && this.packageName.startsWith(methodPackageName)
401402

402403
private val Constructor<*>.isVisible : Boolean
403-
get() = this.isPublic || !this.isPrivate && this.declaringClass.packageName.startsWith(methodPackageName)
404+
get() = this.isPublic || !this.isPrivate && this.declaringClass.nameOfPackage.startsWith(methodPackageName)
404405

405406
/**
406407
* Creates setter or direct setter call to set a field.

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ data class CodeGeneratorResult(
121121
val generatedCode: String,
122122
// null if no util class needed, e.g. when we are generating utils directly into test class
123123
val utilClassKind: UtilClassKind?,
124-
val testsGenerationReport: TestsGenerationReport,
124+
val testsGenerationReport: TestsGenerationReport?,
125125
)
126126

127127
/**

0 commit comments

Comments
 (0)