Skip to content

Commit 61ece8e

Browse files
authored
Engine process #2 (#1067)
[utbot-rd] 1. engine out-of-process 2. removed jdk8+ api calls in engine-related code 3. removed reflection in utbot-intellij to support idea 2022 4. bumped idea version and plugin sdk 5. reactive settings 6. ClientProcessBuilder to support out-of-process 7. moved sarifs, test generation, code generation and TestGenerationReport to another process
1 parent 1260c8f commit 61ece8e

File tree

62 files changed

+3851
-1009
lines changed

Some content is hidden

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

62 files changed

+3851
-1009
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ allprojects {
6565
override fun beforeSuite(suite: TestDescriptor) {}
6666
override fun beforeTest(testDescriptor: TestDescriptor) {}
6767
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
68-
println("[$testDescriptor.classDisplayName] [$testDescriptor.displayName]: $result.resultType")
68+
println("[$testDescriptor.classDisplayName] [$testDescriptor.displayName]: $result.resultType, length - ${(result.endTime - result.startTime) / 1000.0} sec")
6969
}
7070

7171
override fun afterSuite(testDescriptor: TestDescriptor, result: TestResult) {

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ kotlin.code.style=official
33
# IU, IC, PC, PY, WS...
44
ideType=IC
55

6-
pythonCommunityPluginVersion=212.5457.59
6+
pythonCommunityPluginVersion=222.4167.37
77
#Version numbers: https://plugins.jetbrains.com/plugin/631-python/versions
8-
pythonUltimatePluginVersion=212.5457.59
8+
pythonUltimatePluginVersion=222.4167.37
99

1010
junit5Version=5.8.0-RC1
1111
junit4Version=4.13.2
@@ -14,7 +14,7 @@ mockitoVersion=3.5.13
1414
z3Version=4.8.9.1
1515
z3JavaApiVersion=4.8.9
1616
sootCommitHash=1f34746
17-
kotlinVersion=1.7.10
17+
kotlinVersion=1.7.20
1818
log4j2Version=2.13.3
1919
coroutinesVersion=1.6.3
2020
collectionsVersion=0.3.4

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

+69-16
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

+1-1
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

+2
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

+2-25
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,7 +259,7 @@ 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).

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

+2-13
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
@@ -58,6 +46,7 @@ const val SYMBOLIC_NULL_ADDR: Int = 0
5846
data class UtMethodTestSet(
5947
val method: ExecutableId,
6048
val executions: List<UtExecution> = emptyList(),
49+
// in idea process this property is null
6150
val jimpleBody: JimpleBody? = null,
6251
val errors: Map<String, Int> = emptyMap(),
6352
val clustersInfo: List<Pair<UtClusterInfo?, IntRange>> = listOf(null to executions.indices)

utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
2424
import org.junit.jupiter.api.Assertions.assertTrue
2525
import org.junit.jupiter.api.BeforeEach
2626
import org.junit.jupiter.api.Test
27+
import org.utbot.common.nameOfPackage
2728
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
2829
import org.utbot.framework.util.SootUtils
2930

utbot-framework/build.gradle

+4
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
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

+2-2
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
@@ -18,6 +17,7 @@ import java.util.concurrent.atomic.AtomicInteger
1817
import kotlin.reflect.KFunction2
1918
import kotlin.reflect.KFunction5
2019
import kotlinx.collections.immutable.persistentListOf
20+
import org.utbot.common.nameOfPackage
2121
import org.utbot.engine.util.mockListeners.MockListenerController
2222
import org.utbot.framework.util.isInaccessibleViaReflection
2323
import soot.BooleanType
@@ -361,7 +361,7 @@ val assumeOrExecuteConcretelyBytecodeSignature: String
361361
val disableClassCastExceptionCheckBytecodeSignature: String
362362
get() = disableClassCastExceptionCheckMethod.executableId.signature
363363

364-
internal val UTBOT_OVERRIDE_PACKAGE_NAME = UtOverrideMock::class.java.packageName
364+
internal val UTBOT_OVERRIDE_PACKAGE_NAME = UtOverrideMock::class.java.nameOfPackage
365365

366366
private val arraycopyMethod : KFunction5<Array<out Any>, Int, Array<out Any>, Int, Int, Unit> = UtArrayMock::arraycopy
367367
internal val utArrayMockArraycopyMethodName = arraycopyMethod.name

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

+2-1
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)

0 commit comments

Comments
 (0)