From 03b36a83d34cc09fb5614b7aa4803cc8818d3b78 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Fri, 28 Jul 2023 15:16:36 +0300 Subject: [PATCH 1/7] Add way to get instrumentation result --- .../org/utbot/engine/UtBotSymbolicEngine.kt | 5 +- .../utbot/instrumentation/ConcreteExecutor.kt | 17 +- .../instrumentation/et/TraceHandler.kt | 23 ++- .../instrumentation/et/TraceListStrategy.kt | 2 +- .../SimpleUtExecutionInstrumentation.kt | 3 + .../execution/UtExecutionInstrumentation.kt | 4 + .../SpringUtExecutionInstrumentation.kt | 18 +- .../process/InstrumentedProcessMain.kt | 17 +- .../InstrumentedProcessModel.Generated.kt | 157 ++++++++++++++++-- .../rd/models/InstrumentedProcessModel.kt | 14 ++ 10 files changed, 218 insertions(+), 42 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 5e88f312c6..89de2c1f67 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -45,17 +45,16 @@ import org.utbot.fuzzer.* import org.utbot.fuzzing.* import org.utbot.fuzzing.utils.Trie import org.utbot.instrumentation.ConcreteExecutor +import org.utbot.instrumentation.getInstrumentationResult import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult -import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation import org.utbot.taint.* import org.utbot.taint.model.TaintConfiguration import soot.jimple.Stmt import soot.tagkit.ParamNamesTag import java.lang.reflect.Method import java.util.function.Consumer -import java.util.function.Predicate import kotlin.math.min import kotlin.system.measureTimeMillis @@ -452,6 +451,8 @@ class UtBotSymbolicEngine( }.let(transform) val coverageToMinStateBeforeSize = mutableMapOf, Int>() + val instrumentationResult = concreteExecutor.getInstrumentationResult(methodUnderTest) + val needToCoverInstructionsIds = instrumentationResult.instructionsIds runJavaFuzzing( defaultIdGenerator, diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt index 5f80edec97..35e24e53d6 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt @@ -16,22 +16,21 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import mu.KotlinLogging -import org.utbot.framework.plugin.api.InstrumentedProcessDeathException import org.utbot.common.logException -import org.utbot.framework.plugin.api.ClassId -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.ConcreteContextLoadingResult -import org.utbot.framework.plugin.api.SpringRepositoryId +import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.signature import org.utbot.instrumentation.instrumentation.Instrumentation +import org.utbot.instrumentation.instrumentation.execution.ResultOfInstrumentation import org.utbot.instrumentation.process.generated.ComputeStaticFieldParams +import org.utbot.instrumentation.process.generated.GetResultOfInstrumentationParams import org.utbot.instrumentation.process.generated.GetSpringRepositoriesParams import org.utbot.instrumentation.process.generated.InvokeMethodCommandParams import org.utbot.instrumentation.rd.InstrumentedProcess import org.utbot.instrumentation.util.InstrumentedProcessError import org.utbot.rd.generated.synchronizationModel import org.utbot.rd.loggers.overrideDefaultRdLoggerFactoryWithKLogger +import org.utbot.rd.startBlocking private val logger = KotlinLogging.logger {} @@ -313,3 +312,11 @@ fun ConcreteExecutor<*, *>.computeStaticField(fieldId: FieldId): Result = kryoHelper.readObject(result.result) } } + +fun ConcreteExecutor<*, *>.getInstrumentationResult(methodUnderTest: ExecutableId): ResultOfInstrumentation = runBlocking { + withProcess { + val params = GetResultOfInstrumentationParams(methodUnderTest.classId.name, methodUnderTest.name) + val result = instrumentedProcessModel.getResultOfInstrumentation.startBlocking(params) + kryoHelper.readObject(result.result) + } +} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index 6676be0da4..8fcb906c18 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -2,15 +2,15 @@ package org.utbot.instrumentation.instrumentation.et import com.jetbrains.rd.util.error import com.jetbrains.rd.util.getLogger +import org.objectweb.asm.MethodVisitor +import org.objectweb.asm.Opcodes +import org.objectweb.asm.Type +import org.objectweb.asm.commons.LocalVariablesSorter import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.FieldId import org.utbot.instrumentation.Settings import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.javaMethod -import org.objectweb.asm.MethodVisitor -import org.objectweb.asm.Opcodes -import org.objectweb.asm.Type -import org.objectweb.asm.commons.LocalVariablesSorter sealed class InstructionData { abstract val line: Int @@ -65,6 +65,8 @@ class ProcessingStorage { private val instructionsData = mutableMapOf() private val classToInstructionsCount = mutableMapOf() + private val methodIdToInstructionsIds = mutableMapOf>() + fun addClass(className: String): Int { val id = classToId.getOrPut(className) { classToId.size } idToClass.putIfAbsent(id, className) @@ -88,10 +90,16 @@ class ProcessingStorage { return className to localId } - fun addInstruction(id: Long, instructionData: InstructionData) { + fun addInstruction(id: Long, methodId: Int, instructionData: InstructionData) { instructionsData.computeIfAbsent(id) { val (className, _) = computeClassNameAndLocalId(id) classToInstructionsCount.merge(className, 1, Long::plus) + // TODO refactor this + if (methodId !in methodIdToInstructionsIds) { + methodIdToInstructionsIds[methodId] = mutableListOf(id) + } else { + methodIdToInstructionsIds[methodId]!!.add(id) + } instructionData } } @@ -103,6 +111,11 @@ class ProcessingStorage { return instructionsData.getValue(id) } + fun getInstructionsIds(className: String, methodName: String): List { + val methodId = classMethodToId[ClassToMethod(className, methodName)] + return methodIdToInstructionsIds[methodId]!! + } + companion object { private const val SHIFT = 1.toLong().shl(32) // 2 ^ 32 } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt index 157ea89605..69364b43aa 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt @@ -74,7 +74,7 @@ class TraceListStrategy( private fun processNewInstruction(mv: MethodVisitor, instructionData: InstructionData): MethodVisitor { val id = nextId() - storage.addInstruction(id, instructionData) + storage.addInstruction(id, currentClassMethodId, instructionData) return inserter.insertUtilityInstructions(mv, id) } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt index 7c21311731..d40f40285d 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt @@ -112,6 +112,9 @@ class SimpleUtExecutionInstrumentation( } } + override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = + ResultOfInstrumentation(traceHandler.processingStorage.getInstructionsIds(className, methodName)) + override fun getStaticField(fieldId: FieldId): Result = delegateInstrumentation.getStaticField(fieldId).map { value -> UtModelConstructor.createOnlyUserClassesConstructor(pathsToUserClasses) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt index adc9c180f9..da85e5a4fb 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt @@ -36,6 +36,8 @@ data class UtConcreteExecutionResult( } } +data class ResultOfInstrumentation(val instructionsIds: List) + interface UtExecutionInstrumentation : Instrumentation { override fun invoke( clazz: Class<*>, @@ -54,6 +56,8 @@ interface UtExecutionInstrumentation : Instrumentation UtConcreteExecutionResult) -> UtConcreteExecutionResult ): UtConcreteExecutionResult + fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation + interface Factory : Instrumentation.Factory { override fun create(): TInstrumentation = create(SimpleInstrumentationContext()) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt index b30c60d931..f2ee82ffc4 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt @@ -4,14 +4,11 @@ import com.jetbrains.rd.util.getLogger import com.jetbrains.rd.util.info import org.utbot.common.JarUtils import org.utbot.common.hasOnClasspath -import org.utbot.framework.plugin.api.BeanDefinitionData -import org.utbot.framework.plugin.api.ClassId -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.ConcreteContextLoadingResult -import org.utbot.framework.plugin.api.SpringRepositoryId -import org.utbot.framework.plugin.api.SpringSettings.* +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.SpringSettings.PresentSpringSettings import org.utbot.framework.plugin.api.util.jClass import org.utbot.instrumentation.instrumentation.ArgumentList +import org.utbot.instrumentation.instrumentation.execution.ResultOfInstrumentation import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation import org.utbot.instrumentation.instrumentation.execution.context.InstrumentationContext @@ -116,10 +113,10 @@ class SpringUtExecutionInstrumentation( protectionDomain: ProtectionDomain, classfileBuffer: ByteArray ): ByteArray? = - // we do not transform Spring classes as it takes too much time + // we do not transform Spring classes as it takes too much time - // maybe we should still transform classes related to data validation - // (e.g. from packages "javax/persistence" and "jakarta/persistence"), + // maybe we should still transform classes related to data validation + // (e.g. from packages "javax/persistence" and "jakarta/persistence"), // since traces from such classes can be particularly useful for feedback to fuzzer if (userSourcesClassLoader.hasOnClasspath(className.replace("/", "."))) { delegateInstrumentation.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer) @@ -127,6 +124,9 @@ class SpringUtExecutionInstrumentation( null } + override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = + delegateInstrumentation.getResultOfInstrumentation(className, methodName) + class Factory( private val delegateInstrumentationFactory: UtExecutionInstrumentation.Factory<*>, private val springSettings: PresentSpringSettings, diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt index 58618ac593..7c55e701af 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt @@ -12,15 +12,10 @@ import org.utbot.framework.process.kryo.KryoHelper import org.utbot.instrumentation.agent.Agent import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.coverage.CoverageInstrumentation -import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation +import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor -import org.utbot.instrumentation.process.generated.CollectCoverageResult -import org.utbot.instrumentation.process.generated.GetSpringBeanResult -import org.utbot.instrumentation.process.generated.GetSpringRepositoriesResult -import org.utbot.instrumentation.process.generated.InstrumentedProcessModel -import org.utbot.instrumentation.process.generated.InvokeMethodCommandResult -import org.utbot.instrumentation.process.generated.TryLoadingSpringContextResult -import org.utbot.instrumentation.process.generated.instrumentedProcessModel +import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation +import org.utbot.instrumentation.process.generated.* import org.utbot.rd.IdleWatchdog import org.utbot.rd.ClientProtocolBuilder import org.utbot.rd.RdSettingsContainerFactory @@ -151,6 +146,12 @@ private fun InstrumentedProcessModel.setup(kryoHelper: KryoHelper, watchdog: Idl Agent.dynamicClassTransformer.transformer = instrumentation Agent.dynamicClassTransformer.addUserPaths(pathsToUserClasses) } + watchdog.measureTimeForActiveCall(getResultOfInstrumentation, "Getting instrumentation result") { params -> + HandlerClassesLoader.loadClass(params.className) + val result = (instrumentation as UtExecutionInstrumentation) + .getResultOfInstrumentation(params.className, params.methodName) + GetResultOfInstrumentationResult(kryoHelper.writeObject(result)) + } watchdog.measureTimeForActiveCall(addPaths, "User and dependency classpath setup") { params -> pathsToUserClasses = params.pathsToUserClasses.split(File.pathSeparatorChar).toSet() HandlerClassesLoader.addUrls(pathsToUserClasses) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt index e08ed48ba6..7566958fce 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt @@ -22,6 +22,7 @@ class InstrumentedProcessModel private constructor( private val _addPaths: RdCall, private val _warmup: RdCall, private val _setInstrumentation: RdCall, + private val _getResultOfInstrumentation: RdCall, private val _invokeMethodCommand: RdCall, private val _collectCoverage: RdCall, private val _computeStaticField: RdCall, @@ -36,6 +37,8 @@ class InstrumentedProcessModel private constructor( override fun registerSerializersCore(serializers: ISerializers) { serializers.register(AddPathsParams) serializers.register(SetInstrumentationParams) + serializers.register(GetResultOfInstrumentationParams) + serializers.register(GetResultOfInstrumentationResult) serializers.register(InvokeMethodCommandParams) serializers.register(InvokeMethodCommandResult) serializers.register(CollectCoverageParams) @@ -67,7 +70,7 @@ class InstrumentedProcessModel private constructor( } - const val serializationHash = -3572666434834334555L + const val serializationHash = -3017420695404190342L } override val serializersOwner: ISerializersOwner get() = InstrumentedProcessModel @@ -90,6 +93,11 @@ class InstrumentedProcessModel private constructor( */ val setInstrumentation: RdCall get() = _setInstrumentation + /** + * This command is sent to the instrumented process from the [ConcreteExecutor] to get instrumentation result + */ + val getResultOfInstrumentation: RdCall get() = _getResultOfInstrumentation + /** * The main process requests the instrumented process to execute a method with the given [signature], which declaring class's name is [className]. @@ -130,6 +138,7 @@ class InstrumentedProcessModel private constructor( _addPaths.async = true _warmup.async = true _setInstrumentation.async = true + _getResultOfInstrumentation.async = true _invokeMethodCommand.async = true _collectCoverage.async = true _computeStaticField.async = true @@ -142,6 +151,7 @@ class InstrumentedProcessModel private constructor( bindableChildren.add("addPaths" to _addPaths) bindableChildren.add("warmup" to _warmup) bindableChildren.add("setInstrumentation" to _setInstrumentation) + bindableChildren.add("getResultOfInstrumentation" to _getResultOfInstrumentation) bindableChildren.add("invokeMethodCommand" to _invokeMethodCommand) bindableChildren.add("collectCoverage" to _collectCoverage) bindableChildren.add("computeStaticField" to _computeStaticField) @@ -156,6 +166,7 @@ class InstrumentedProcessModel private constructor( RdCall(AddPathsParams, FrameworkMarshallers.Void), RdCall(FrameworkMarshallers.Void, FrameworkMarshallers.Void), RdCall(SetInstrumentationParams, FrameworkMarshallers.Void), + RdCall(GetResultOfInstrumentationParams, GetResultOfInstrumentationResult), RdCall(InvokeMethodCommandParams, InvokeMethodCommandResult), RdCall(CollectCoverageParams, CollectCoverageResult), RdCall(ComputeStaticFieldParams, ComputeStaticFieldResult), @@ -173,6 +184,7 @@ class InstrumentedProcessModel private constructor( print("addPaths = "); _addPaths.print(printer); println() print("warmup = "); _warmup.print(printer); println() print("setInstrumentation = "); _setInstrumentation.print(printer); println() + print("getResultOfInstrumentation = "); _getResultOfInstrumentation.print(printer); println() print("invokeMethodCommand = "); _invokeMethodCommand.print(printer); println() print("collectCoverage = "); _collectCoverage.print(printer); println() print("computeStaticField = "); _computeStaticField.print(printer); println() @@ -188,6 +200,7 @@ class InstrumentedProcessModel private constructor( _addPaths.deepClonePolymorphic(), _warmup.deepClonePolymorphic(), _setInstrumentation.deepClonePolymorphic(), + _getResultOfInstrumentation.deepClonePolymorphic(), _invokeMethodCommand.deepClonePolymorphic(), _collectCoverage.deepClonePolymorphic(), _computeStaticField.deepClonePolymorphic(), @@ -260,7 +273,7 @@ data class AddPathsParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:28] + * #### Generated from [InstrumentedProcessModel.kt:37] */ data class CollectCoverageParams ( val clazz: ByteArray @@ -317,7 +330,7 @@ data class CollectCoverageParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:32] + * #### Generated from [InstrumentedProcessModel.kt:41] */ data class CollectCoverageResult ( val coverageInfo: ByteArray @@ -374,7 +387,7 @@ data class CollectCoverageResult ( /** - * #### Generated from [InstrumentedProcessModel.kt:36] + * #### Generated from [InstrumentedProcessModel.kt:45] */ data class ComputeStaticFieldParams ( val fieldId: ByteArray @@ -431,7 +444,7 @@ data class ComputeStaticFieldParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:40] + * #### Generated from [InstrumentedProcessModel.kt:49] */ data class ComputeStaticFieldResult ( val result: ByteArray @@ -488,7 +501,127 @@ data class ComputeStaticFieldResult ( /** - * #### Generated from [InstrumentedProcessModel.kt:44] + * #### Generated from [InstrumentedProcessModel.kt:17] + */ +data class GetResultOfInstrumentationParams ( + val className: String, + val methodName: String +) : IPrintable { + //companion + + companion object : IMarshaller { + override val _type: KClass = GetResultOfInstrumentationParams::class + + @Suppress("UNCHECKED_CAST") + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetResultOfInstrumentationParams { + val className = buffer.readString() + val methodName = buffer.readString() + return GetResultOfInstrumentationParams(className, methodName) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetResultOfInstrumentationParams) { + buffer.writeString(value.className) + buffer.writeString(value.methodName) + } + + + } + //fields + //methods + //initializer + //secondary constructor + //equals trait + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || other::class != this::class) return false + + other as GetResultOfInstrumentationParams + + if (className != other.className) return false + if (methodName != other.methodName) return false + + return true + } + //hash code trait + override fun hashCode(): Int { + var __r = 0 + __r = __r*31 + className.hashCode() + __r = __r*31 + methodName.hashCode() + return __r + } + //pretty print + override fun print(printer: PrettyPrinter) { + printer.println("GetResultOfInstrumentationParams (") + printer.indent { + print("className = "); className.print(printer); println() + print("methodName = "); methodName.print(printer); println() + } + printer.print(")") + } + //deepClone + //contexts +} + + +/** + * #### Generated from [InstrumentedProcessModel.kt:22] + */ +data class GetResultOfInstrumentationResult ( + val result: ByteArray +) : IPrintable { + //companion + + companion object : IMarshaller { + override val _type: KClass = GetResultOfInstrumentationResult::class + + @Suppress("UNCHECKED_CAST") + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetResultOfInstrumentationResult { + val result = buffer.readByteArray() + return GetResultOfInstrumentationResult(result) + } + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetResultOfInstrumentationResult) { + buffer.writeByteArray(value.result) + } + + + } + //fields + //methods + //initializer + //secondary constructor + //equals trait + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || other::class != this::class) return false + + other as GetResultOfInstrumentationResult + + if (!(result contentEquals other.result)) return false + + return true + } + //hash code trait + override fun hashCode(): Int { + var __r = 0 + __r = __r*31 + result.contentHashCode() + return __r + } + //pretty print + override fun print(printer: PrettyPrinter) { + printer.println("GetResultOfInstrumentationResult (") + printer.indent { + print("result = "); result.print(printer); println() + } + printer.print(")") + } + //deepClone + //contexts +} + + +/** + * #### Generated from [InstrumentedProcessModel.kt:53] */ data class GetSpringBeanParams ( val beanName: String @@ -545,7 +678,7 @@ data class GetSpringBeanParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:48] + * #### Generated from [InstrumentedProcessModel.kt:57] */ data class GetSpringBeanResult ( val beanModel: ByteArray @@ -602,7 +735,7 @@ data class GetSpringBeanResult ( /** - * #### Generated from [InstrumentedProcessModel.kt:52] + * #### Generated from [InstrumentedProcessModel.kt:61] */ data class GetSpringRepositoriesParams ( val classId: ByteArray @@ -659,7 +792,7 @@ data class GetSpringRepositoriesParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:56] + * #### Generated from [InstrumentedProcessModel.kt:65] */ data class GetSpringRepositoriesResult ( val springRepositoryIds: ByteArray @@ -716,7 +849,7 @@ data class GetSpringRepositoriesResult ( /** - * #### Generated from [InstrumentedProcessModel.kt:17] + * #### Generated from [InstrumentedProcessModel.kt:26] */ data class InvokeMethodCommandParams ( val classname: String, @@ -791,7 +924,7 @@ data class InvokeMethodCommandParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:24] + * #### Generated from [InstrumentedProcessModel.kt:33] */ data class InvokeMethodCommandResult ( val result: ByteArray @@ -905,7 +1038,7 @@ data class SetInstrumentationParams ( /** - * #### Generated from [InstrumentedProcessModel.kt:60] + * #### Generated from [InstrumentedProcessModel.kt:69] */ data class TryLoadingSpringContextResult ( val springContextLoadingResult: ByteArray diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt index cdefe5c103..5e2e4863ee 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt @@ -14,6 +14,15 @@ object InstrumentedProcessModel : Ext(InstrumentedProcessRoot) { field("instrumentation", array(PredefinedType.byte)) } + val GetResultOfInstrumentationParams = structdef { + field("className", PredefinedType.string) + field("methodName", PredefinedType.string) + } + + val GetResultOfInstrumentationResult = structdef { + field("result", array(PredefinedType.byte)) + } + val InvokeMethodCommandParams = structdef { field("classname", PredefinedType.string) field("signature", PredefinedType.string) @@ -77,6 +86,11 @@ object InstrumentedProcessModel : Ext(InstrumentedProcessRoot) { documentation = "The main process sends [instrumentation] to the instrumented process" } + call("GetResultOfInstrumentation", GetResultOfInstrumentationParams, GetResultOfInstrumentationResult).apply { + async + documentation = + "This command is sent to the instrumented process from the [ConcreteExecutor] to get instrumentation result" + } call("InvokeMethodCommand", InvokeMethodCommandParams, InvokeMethodCommandResult).apply { async documentation = From f288f182e9c320f4ddaa5365c74fff03b3a1bb12 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Fri, 28 Jul 2023 15:52:28 +0300 Subject: [PATCH 2/7] Move method getResultOfInstrumentation in SpringUtExecutionInstrumentation --- .../SpringUtExecutionInstrumentation.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt index f2ee82ffc4..ad5fee07c4 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt @@ -4,8 +4,12 @@ import com.jetbrains.rd.util.getLogger import com.jetbrains.rd.util.info import org.utbot.common.JarUtils import org.utbot.common.hasOnClasspath -import org.utbot.framework.plugin.api.* -import org.utbot.framework.plugin.api.SpringSettings.PresentSpringSettings +import org.utbot.framework.plugin.api.BeanDefinitionData +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.ConcreteContextLoadingResult +import org.utbot.framework.plugin.api.SpringRepositoryId +import org.utbot.framework.plugin.api.SpringSettings.* import org.utbot.framework.plugin.api.util.jClass import org.utbot.instrumentation.instrumentation.ArgumentList import org.utbot.instrumentation.instrumentation.execution.ResultOfInstrumentation @@ -79,6 +83,9 @@ class SpringUtExecutionInstrumentation( } } + override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = + delegateInstrumentation.getResultOfInstrumentation(className, methodName) + override fun getStaticField(fieldId: FieldId): Result<*> = delegateInstrumentation.getStaticField(fieldId) private fun getRelevantBeans(clazz: Class<*>): Set = relatedBeansCache.getOrPut(clazz) { @@ -113,10 +120,10 @@ class SpringUtExecutionInstrumentation( protectionDomain: ProtectionDomain, classfileBuffer: ByteArray ): ByteArray? = - // we do not transform Spring classes as it takes too much time + // we do not transform Spring classes as it takes too much time - // maybe we should still transform classes related to data validation - // (e.g. from packages "javax/persistence" and "jakarta/persistence"), + // maybe we should still transform classes related to data validation + // (e.g. from packages "javax/persistence" and "jakarta/persistence"), // since traces from such classes can be particularly useful for feedback to fuzzer if (userSourcesClassLoader.hasOnClasspath(className.replace("/", "."))) { delegateInstrumentation.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer) @@ -124,9 +131,6 @@ class SpringUtExecutionInstrumentation( null } - override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = - delegateInstrumentation.getResultOfInstrumentation(className, methodName) - class Factory( private val delegateInstrumentationFactory: UtExecutionInstrumentation.Factory<*>, private val springSettings: PresentSpringSettings, From 21865a5103ec82aef2b0265157be55b9025358b7 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Mon, 31 Jul 2023 17:13:53 +0300 Subject: [PATCH 3/7] Refactor imports --- .../utbot/instrumentation/ConcreteExecutor.kt | 21 ++++++++++++------- .../instrumentation/et/TraceHandler.kt | 13 ++++++------ .../execution/UtExecutionInstrumentation.kt | 2 +- .../process/InstrumentedProcessMain.kt | 11 ++++++++-- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt index 35e24e53d6..27017fd535 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt @@ -16,8 +16,13 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import mu.KotlinLogging +import org.utbot.framework.plugin.api.InstrumentedProcessDeathException import org.utbot.common.logException -import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.FieldId +import org.utbot.framework.plugin.api.ConcreteContextLoadingResult +import org.utbot.framework.plugin.api.SpringRepositoryId +import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.signature import org.utbot.instrumentation.instrumentation.Instrumentation @@ -30,7 +35,6 @@ import org.utbot.instrumentation.rd.InstrumentedProcess import org.utbot.instrumentation.util.InstrumentedProcessError import org.utbot.rd.generated.synchronizationModel import org.utbot.rd.loggers.overrideDefaultRdLoggerFactoryWithKLogger -import org.utbot.rd.startBlocking private val logger = KotlinLogging.logger {} @@ -313,10 +317,11 @@ fun ConcreteExecutor<*, *>.computeStaticField(fieldId: FieldId): Result = } } -fun ConcreteExecutor<*, *>.getInstrumentationResult(methodUnderTest: ExecutableId): ResultOfInstrumentation = runBlocking { - withProcess { - val params = GetResultOfInstrumentationParams(methodUnderTest.classId.name, methodUnderTest.name) - val result = instrumentedProcessModel.getResultOfInstrumentation.startBlocking(params) - kryoHelper.readObject(result.result) +fun ConcreteExecutor<*, *>.getInstrumentationResult(methodUnderTest: ExecutableId): ResultOfInstrumentation = + runBlocking { + withProcess { + val params = GetResultOfInstrumentationParams(methodUnderTest.classId.name, methodUnderTest.name) + val result = instrumentedProcessModel.getResultOfInstrumentation.startSuspending(lifetime, params) + kryoHelper.readObject(result.result) + } } -} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index 8fcb906c18..076ddb1d74 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -2,15 +2,15 @@ package org.utbot.instrumentation.instrumentation.et import com.jetbrains.rd.util.error import com.jetbrains.rd.util.getLogger -import org.objectweb.asm.MethodVisitor -import org.objectweb.asm.Opcodes -import org.objectweb.asm.Type -import org.objectweb.asm.commons.LocalVariablesSorter import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.FieldId import org.utbot.instrumentation.Settings import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.javaMethod +import org.objectweb.asm.MethodVisitor +import org.objectweb.asm.Opcodes +import org.objectweb.asm.Type +import org.objectweb.asm.commons.LocalVariablesSorter sealed class InstructionData { abstract val line: Int @@ -94,7 +94,6 @@ class ProcessingStorage { instructionsData.computeIfAbsent(id) { val (className, _) = computeClassNameAndLocalId(id) classToInstructionsCount.merge(className, 1, Long::plus) - // TODO refactor this if (methodId !in methodIdToInstructionsIds) { methodIdToInstructionsIds[methodId] = mutableListOf(id) } else { @@ -111,9 +110,9 @@ class ProcessingStorage { return instructionsData.getValue(id) } - fun getInstructionsIds(className: String, methodName: String): List { + fun getInstructionsIds(className: String, methodName: String): List? { val methodId = classMethodToId[ClassToMethod(className, methodName)] - return methodIdToInstructionsIds[methodId]!! + return methodIdToInstructionsIds[methodId] } companion object { diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt index da85e5a4fb..f0dbaa382c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt @@ -36,7 +36,7 @@ data class UtConcreteExecutionResult( } } -data class ResultOfInstrumentation(val instructionsIds: List) +data class ResultOfInstrumentation(val instructionsIds: List?) interface UtExecutionInstrumentation : Instrumentation { override fun invoke( diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt index 7c55e701af..045f689429 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt @@ -12,10 +12,17 @@ import org.utbot.framework.process.kryo.KryoHelper import org.utbot.instrumentation.agent.Agent import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.coverage.CoverageInstrumentation +import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor -import org.utbot.instrumentation.instrumentation.spring.SpringUtExecutionInstrumentation -import org.utbot.instrumentation.process.generated.* +import org.utbot.instrumentation.process.generated.CollectCoverageResult +import org.utbot.instrumentation.process.generated.GetSpringBeanResult +import org.utbot.instrumentation.process.generated.GetSpringRepositoriesResult +import org.utbot.instrumentation.process.generated.InstrumentedProcessModel +import org.utbot.instrumentation.process.generated.InvokeMethodCommandResult +import org.utbot.instrumentation.process.generated.TryLoadingSpringContextResult +import org.utbot.instrumentation.process.generated.instrumentedProcessModel +import org.utbot.instrumentation.process.generated.GetResultOfInstrumentationResult import org.utbot.rd.IdleWatchdog import org.utbot.rd.ClientProtocolBuilder import org.utbot.rd.RdSettingsContainerFactory From 2a4ea7b9852d48c68ce8a9c49b484e32bdc0da71 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Mon, 31 Jul 2023 17:32:01 +0300 Subject: [PATCH 4/7] Delete lines for debug --- .../src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 89de2c1f67..a70c402af8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -451,8 +451,6 @@ class UtBotSymbolicEngine( }.let(transform) val coverageToMinStateBeforeSize = mutableMapOf, Int>() - val instrumentationResult = concreteExecutor.getInstrumentationResult(methodUnderTest) - val needToCoverInstructionsIds = instrumentationResult.instructionsIds runJavaFuzzing( defaultIdGenerator, From 1dfb8e6d9b23f9952460ec00f9f2b4123a3a3433 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Thu, 3 Aug 2023 20:38:51 +0300 Subject: [PATCH 5/7] Refactor --- .../instrumentation/instrumentation/et/TraceHandler.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index 076ddb1d74..ce4693d81b 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -94,11 +94,7 @@ class ProcessingStorage { instructionsData.computeIfAbsent(id) { val (className, _) = computeClassNameAndLocalId(id) classToInstructionsCount.merge(className, 1, Long::plus) - if (methodId !in methodIdToInstructionsIds) { - methodIdToInstructionsIds[methodId] = mutableListOf(id) - } else { - methodIdToInstructionsIds[methodId]!!.add(id) - } + methodIdToInstructionsIds.getOrPut(methodId) { mutableListOf() }.add(id) instructionData } } From 9c61a346d15d8ea0bae109bd7dd6e1048f326f85 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Fri, 11 Aug 2023 10:41:18 +0300 Subject: [PATCH 6/7] Fix bug --- .../utbot/instrumentation/ConcreteExecutor.kt | 2 +- .../instrumentation/et/TraceHandler.kt | 10 +++++----- .../instrumentation/et/TraceListStrategy.kt | 2 +- .../SimpleUtExecutionInstrumentation.kt | 4 ++-- .../execution/UtExecutionInstrumentation.kt | 2 +- .../spring/SpringUtExecutionInstrumentation.kt | 4 ++-- .../process/InstrumentedProcessMain.kt | 5 +++-- .../InstrumentedProcessModel.Generated.kt | 16 ++++++++-------- .../utbot/rd/models/InstrumentedProcessModel.kt | 2 +- 9 files changed, 24 insertions(+), 23 deletions(-) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt index 27017fd535..3194e48560 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt @@ -320,7 +320,7 @@ fun ConcreteExecutor<*, *>.computeStaticField(fieldId: FieldId): Result = fun ConcreteExecutor<*, *>.getInstrumentationResult(methodUnderTest: ExecutableId): ResultOfInstrumentation = runBlocking { withProcess { - val params = GetResultOfInstrumentationParams(methodUnderTest.classId.name, methodUnderTest.name) + val params = GetResultOfInstrumentationParams(methodUnderTest.classId.name, methodUnderTest.signature) val result = instrumentedProcessModel.getResultOfInstrumentation.startSuspending(lifetime, params) kryoHelper.readObject(result.result) } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index ce4693d81b..c31e403519 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -52,7 +52,7 @@ data class PutStaticInstruction( private data class ClassToMethod( val className: String, - val methodName: String + val methodSignature: String ) class ProcessingStorage { @@ -77,8 +77,8 @@ class ProcessingStorage { return classToId[className]!!.toLong() * SHIFT + localId } - fun addClassMethod(className: String, methodName: String): Int { - val classToMethod = ClassToMethod(className, methodName) + fun addClassMethod(className: String, methodSignature: String): Int { + val classToMethod = ClassToMethod(className, methodSignature) val id = classMethodToId.getOrPut(classToMethod) { classMethodToId.size } idToClassMethod.putIfAbsent(id, classToMethod) return id @@ -106,8 +106,8 @@ class ProcessingStorage { return instructionsData.getValue(id) } - fun getInstructionsIds(className: String, methodName: String): List? { - val methodId = classMethodToId[ClassToMethod(className, methodName)] + fun getInstructionsIds(className: String, methodSignature: String): List? { + val methodId = classMethodToId[ClassToMethod(className, methodSignature)] return methodIdToInstructionsIds[methodId] } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt index 69364b43aa..d04f177219 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt @@ -27,7 +27,7 @@ class TraceListStrategy( methodVisitor: MethodVisitor ) { currentMethodSignature = name + descriptor - currentClassMethodId = storage.addClassMethod(className, name) + currentClassMethodId = storage.addClassMethod(className, currentMethodSignature) } override fun visitCode(mv: MethodVisitor, lvs: LocalVariablesSorter) { diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt index 83102d1bfe..c614ff2fa0 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt @@ -129,8 +129,8 @@ class SimpleUtExecutionInstrumentation( } } - override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = - ResultOfInstrumentation(traceHandler.processingStorage.getInstructionsIds(className, methodName)) + override fun getResultOfInstrumentation(className: String, methodSignature: String): ResultOfInstrumentation = + ResultOfInstrumentation(traceHandler.processingStorage.getInstructionsIds(className, methodSignature)) override fun getStaticField(fieldId: FieldId): Result = delegateInstrumentation.getStaticField(fieldId).map { value -> diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt index f0dbaa382c..b808ded23c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt @@ -56,7 +56,7 @@ interface UtExecutionInstrumentation : Instrumentation UtConcreteExecutionResult) -> UtConcreteExecutionResult ): UtConcreteExecutionResult - fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation + fun getResultOfInstrumentation(className: String, methodSignature: String): ResultOfInstrumentation interface Factory : Instrumentation.Factory { override fun create(): TInstrumentation = create(SimpleInstrumentationContext()) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt index 5ad3e978e6..3f4ca4d816 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/spring/SpringUtExecutionInstrumentation.kt @@ -85,8 +85,8 @@ class SpringUtExecutionInstrumentation( } } - override fun getResultOfInstrumentation(className: String, methodName: String): ResultOfInstrumentation = - delegateInstrumentation.getResultOfInstrumentation(className, methodName) + override fun getResultOfInstrumentation(className: String, methodSignature: String): ResultOfInstrumentation = + delegateInstrumentation.getResultOfInstrumentation(className, methodSignature) override fun getStaticField(fieldId: FieldId): Result<*> = delegateInstrumentation.getStaticField(fieldId) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt index 175107bc34..3d709d80d3 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/InstrumentedProcessMain.kt @@ -155,8 +155,9 @@ private fun InstrumentedProcessModel.setup(kryoHelper: KryoHelper, watchdog: Idl } watchdog.measureTimeForActiveCall(getResultOfInstrumentation, "Getting instrumentation result") { params -> HandlerClassesLoader.loadClass(params.className) - val result = (instrumentation as UtExecutionInstrumentation) - .getResultOfInstrumentation(params.className, params.methodName) + val result = (instrumentation as UtExecutionInstrumentation).getResultOfInstrumentation( + params.className, params.methodSignature + ) GetResultOfInstrumentationResult(kryoHelper.writeObject(result)) } watchdog.measureTimeForActiveCall(addPaths, "User and dependency classpath setup") { params -> diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt index 69a78f947a..9181bb145c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/rd/generated/InstrumentedProcessModel.Generated.kt @@ -70,7 +70,7 @@ class InstrumentedProcessModel private constructor( } - const val serializationHash = -7487216533584583779L + const val serializationHash = 5470408548487674098L } override val serializersOwner: ISerializersOwner get() = InstrumentedProcessModel @@ -505,7 +505,7 @@ data class ComputeStaticFieldResult ( */ data class GetResultOfInstrumentationParams ( val className: String, - val methodName: String + val methodSignature: String ) : IPrintable { //companion @@ -515,13 +515,13 @@ data class GetResultOfInstrumentationParams ( @Suppress("UNCHECKED_CAST") override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): GetResultOfInstrumentationParams { val className = buffer.readString() - val methodName = buffer.readString() - return GetResultOfInstrumentationParams(className, methodName) + val methodSignature = buffer.readString() + return GetResultOfInstrumentationParams(className, methodSignature) } override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GetResultOfInstrumentationParams) { buffer.writeString(value.className) - buffer.writeString(value.methodName) + buffer.writeString(value.methodSignature) } @@ -538,7 +538,7 @@ data class GetResultOfInstrumentationParams ( other as GetResultOfInstrumentationParams if (className != other.className) return false - if (methodName != other.methodName) return false + if (methodSignature != other.methodSignature) return false return true } @@ -546,7 +546,7 @@ data class GetResultOfInstrumentationParams ( override fun hashCode(): Int { var __r = 0 __r = __r*31 + className.hashCode() - __r = __r*31 + methodName.hashCode() + __r = __r*31 + methodSignature.hashCode() return __r } //pretty print @@ -554,7 +554,7 @@ data class GetResultOfInstrumentationParams ( printer.println("GetResultOfInstrumentationParams (") printer.indent { print("className = "); className.print(printer); println() - print("methodName = "); methodName.print(printer); println() + print("methodSignature = "); methodSignature.print(printer); println() } printer.print(")") } diff --git a/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt b/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt index 74c155367e..a906d21c28 100644 --- a/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt +++ b/utbot-rd/src/main/rdgen/org/utbot/rd/models/InstrumentedProcessModel.kt @@ -17,7 +17,7 @@ object InstrumentedProcessModel : Ext(InstrumentedProcessRoot) { val GetResultOfInstrumentationParams = structdef { field("className", PredefinedType.string) - field("methodName", PredefinedType.string) + field("methodSignature", PredefinedType.string) } val GetResultOfInstrumentationResult = structdef { From 9970171b3a2ad7f7d4ea5339de1e89be524829a0 Mon Sep 17 00:00:00 2001 From: Pavel Egipti Date: Wed, 30 Aug 2023 10:37:23 +0300 Subject: [PATCH 7/7] Implement getResultOfInstrumentation method in RemovingConstructFailsUtExecutionInstrumentation class --- .../RemovingConstructFailsUtExecutionInstrumentation.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/RemovingConstructFailsUtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/RemovingConstructFailsUtExecutionInstrumentation.kt index 803f0b6e8b..359d2dd2e9 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/RemovingConstructFailsUtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/RemovingConstructFailsUtExecutionInstrumentation.kt @@ -94,6 +94,9 @@ class RemovingConstructFailsUtExecutionInstrumentation( } } + override fun getResultOfInstrumentation(className: String, methodSignature: String): ResultOfInstrumentation = + delegateInstrumentation.getResultOfInstrumentation(className, methodSignature) + private fun shallowlyRemoveFailingCalls(model: UtModel): UtModel = when { model !is UtAssembleModel -> model model.instantiationCall.thrownConcreteException != null -> model.classId.defaultValueModel()