Skip to content

Commit 94a2d03

Browse files
Replace SootMethod with ExecutableId if possible
1 parent b3c3714 commit 94a2d03

File tree

7 files changed

+35
-42
lines changed

7 files changed

+35
-42
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ class AssembleModelGeneratorTests {
14481448
expectedModelRepresentations: List<String?>,
14491449
assembleTestUtils: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
14501450
) {
1451-
val modelsMap = AssembleModelGenerator(assembleTestUtils.sootMethod).createAssembleModels(models) // TODO: rewrite usages
1451+
val modelsMap = AssembleModelGenerator(assembleTestUtils.classId.packageName).createAssembleModels(models) // TODO: rewrite usages
14521452
//we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order)
14531453
val assembleModels = modelsMap.values
14541454
.filterIsInstance<UtAssembleModel>()

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ import org.utbot.engine.pc.mkLong
2525
import org.utbot.engine.pc.mkShort
2626
import org.utbot.engine.pc.select
2727
import org.utbot.engine.pc.store
28-
import org.utbot.engine.util.statics.concrete.isEnumValuesFieldName
2928
import org.utbot.engine.symbolic.asHardConstraint
29+
import org.utbot.engine.util.statics.concrete.isEnumValuesFieldName
3030
import org.utbot.engine.z3.intValue
3131
import org.utbot.engine.z3.value
3232
import org.utbot.framework.assemble.AssembleModelGenerator
3333
import org.utbot.framework.plugin.api.ClassId
3434
import org.utbot.framework.plugin.api.ExecutableId
3535
import org.utbot.framework.plugin.api.FieldId
3636
import org.utbot.framework.plugin.api.MethodId
37+
import org.utbot.framework.plugin.api.SYMBOLIC_NULL_ADDR
3738
import org.utbot.framework.plugin.api.UtArrayModel
3839
import org.utbot.framework.plugin.api.UtAssembleModel
3940
import org.utbot.framework.plugin.api.UtClassRefModel
@@ -51,6 +52,7 @@ import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation
5152
import org.utbot.framework.plugin.api.UtNullModel
5253
import org.utbot.framework.plugin.api.UtOverflowFailure
5354
import org.utbot.framework.plugin.api.UtPrimitiveModel
55+
import org.utbot.framework.plugin.api.UtSandboxFailure
5456
import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation
5557
import org.utbot.framework.plugin.api.UtVoidModel
5658
import org.utbot.framework.plugin.api.classId
@@ -62,16 +64,6 @@ import org.utbot.framework.plugin.api.util.jClass
6264
import org.utbot.framework.plugin.api.util.primitiveByWrapper
6365
import org.utbot.framework.plugin.api.util.utContext
6466
import org.utbot.framework.util.nextModelName
65-
import java.awt.color.ICC_ProfileRGB
66-
import java.io.PrintStream
67-
import java.security.AccessControlContext
68-
import java.util.concurrent.atomic.AtomicInteger
69-
import kotlin.math.max
70-
import kotlin.math.min
71-
import kotlinx.collections.immutable.persistentListOf
72-
import kotlinx.collections.immutable.persistentSetOf
73-
import org.utbot.framework.plugin.api.SYMBOLIC_NULL_ADDR
74-
import org.utbot.framework.plugin.api.UtSandboxFailure
7567
import soot.ArrayType
7668
import soot.BooleanType
7769
import soot.ByteType
@@ -86,10 +78,17 @@ import soot.Scene
8678
import soot.ShortType
8779
import soot.SootClass
8880
import soot.SootField
89-
import soot.SootMethod
9081
import soot.Type
9182
import soot.VoidType
83+
import java.awt.color.ICC_ProfileRGB
84+
import java.io.PrintStream
85+
import java.security.AccessControlContext
9286
import java.security.AccessControlException
87+
import java.util.concurrent.atomic.AtomicInteger
88+
import kotlin.math.max
89+
import kotlin.math.min
90+
import kotlinx.collections.immutable.persistentListOf
91+
import kotlinx.collections.immutable.persistentSetOf
9392

9493
// hack
9594
const val MAX_LIST_SIZE = 10
@@ -118,7 +117,7 @@ class Resolver(
118117
val typeRegistry: TypeRegistry,
119118
private val typeResolver: TypeResolver,
120119
val holder: UtSolverStatusSAT,
121-
methodUnderTest: SootMethod,
120+
methodUnderTest: ExecutableId,
122121
private val softMaxArraySize: Int
123122
) {
124123

@@ -133,7 +132,7 @@ class Resolver(
133132
private val instrumentation = mutableListOf<UtInstrumentation>()
134133
private val requiredInstanceFields = mutableMapOf<Address, Set<FieldId>>()
135134

136-
private val assembleModelGenerator = AssembleModelGenerator(methodUnderTest)
135+
private val assembleModelGenerator = AssembleModelGenerator(methodUnderTest.classId.packageName)
137136

138137
/**
139138
* Contains FieldId of the static field which is construction at the moment and null of there is no such field.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ import org.utbot.framework.UtSettings.maximizeCoverageUsingReflection
8787
import org.utbot.framework.UtSettings.preferredCexOption
8888
import org.utbot.framework.UtSettings.substituteStaticsWithSymbolicVariable
8989
import org.utbot.framework.plugin.api.ClassId
90+
import org.utbot.framework.plugin.api.ExecutableId
9091
import org.utbot.framework.plugin.api.FieldId
9192
import org.utbot.framework.plugin.api.MethodId
9293
import org.utbot.framework.plugin.api.classId
@@ -95,6 +96,7 @@ import org.utbot.framework.plugin.api.util.executable
9596
import org.utbot.framework.plugin.api.util.jField
9697
import org.utbot.framework.plugin.api.util.jClass
9798
import org.utbot.framework.plugin.api.util.id
99+
import org.utbot.framework.plugin.api.util.isConstructor
98100
import org.utbot.framework.plugin.api.util.utContext
99101
import org.utbot.framework.util.executableId
100102
import org.utbot.framework.util.graph
@@ -197,7 +199,7 @@ import java.util.concurrent.atomic.AtomicInteger
197199
private val CAUGHT_EXCEPTION = LocalVariable("@caughtexception")
198200

199201
class Traverser(
200-
private val methodUnderTest: SootMethod,
202+
private val methodUnderTest: ExecutableId,
201203
internal val typeRegistry: TypeRegistry,
202204
internal val hierarchy: Hierarchy,
203205
// TODO HACK violation of encapsulation
@@ -954,7 +956,7 @@ class Traverser(
954956
* Stores information about the generic types used in the parameters of the method under test.
955957
*/
956958
private fun updateGenericTypeInfo(identityRef: IdentityRef, value: ReferenceValue) {
957-
val callable = methodUnderTest.executableId.executable
959+
val callable = methodUnderTest.executable
958960
val type = if (identityRef is ThisRef) {
959961
// TODO: for ThisRef both methods don't return parameterized type
960962
if (methodUnderTest.isConstructor) {

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ import org.utbot.framework.plugin.api.UtNullModel
6060
import org.utbot.framework.plugin.api.UtOverflowFailure
6161
import org.utbot.framework.plugin.api.UtResult
6262
import org.utbot.framework.plugin.api.UtSymbolicExecution
63-
import org.utbot.framework.plugin.api.id
6463
import org.utbot.framework.plugin.api.onSuccess
6564
import org.utbot.framework.plugin.api.util.description
6665
import org.utbot.framework.plugin.api.util.id
66+
import org.utbot.framework.plugin.api.util.isConstructor
6767
import org.utbot.framework.plugin.api.util.isEnum
6868
import org.utbot.framework.plugin.api.util.utContext
6969
import org.utbot.framework.plugin.api.util.voidClassId
@@ -85,7 +85,6 @@ import org.utbot.fuzzer.fuzz
8585
import org.utbot.fuzzer.providers.ObjectModelProvider
8686
import org.utbot.fuzzer.withMutations
8787
import org.utbot.instrumentation.ConcreteExecutor
88-
import soot.SootMethod
8988
import soot.jimple.Stmt
9089
import soot.tagkit.ParamNamesTag
9190
import java.lang.reflect.Method
@@ -154,16 +153,14 @@ private fun pathSelector(graph: InterProceduralUnitGraph, typeRegistry: TypeRegi
154153

155154
class UtBotSymbolicEngine(
156155
private val controller: EngineController,
157-
private val executableId: ExecutableId,
156+
private val methodUnderTest: ExecutableId,
158157
classpath: String,
159158
dependencyPaths: String,
160159
mockStrategy: MockStrategy = NO_MOCKS,
161160
chosenClassesToMockAlways: Set<ClassId>,
162161
private val solverTimeoutInMillis: Int = checkSolverTimeoutMillis
163162
) : UtContextInitializer() {
164-
private val methodUnderTest = executableId.sootMethod
165-
166-
private val graph = methodUnderTest.jimpleBody().apply {
163+
private val graph = methodUnderTest.sootMethod.jimpleBody().apply {
167164
logger.trace { "JIMPLE for $methodUnderTest:\n$this" }
168165
}.graph()
169166

@@ -177,7 +174,7 @@ class UtBotSymbolicEngine(
177174
// TODO HACK violation of encapsulation
178175
internal val typeResolver: TypeResolver = TypeResolver(typeRegistry, hierarchy)
179176

180-
private val classUnderTest: ClassId = methodUnderTest.declaringClass.id
177+
private val classUnderTest: ClassId = methodUnderTest.classId
181178

182179
private val mocker: Mocker = Mocker(
183180
mockStrategy,
@@ -384,7 +381,7 @@ class UtBotSymbolicEngine(
384381
* @param modelProvider provides model values for a method
385382
*/
386383
fun fuzzing(until: Long = Long.MAX_VALUE, modelProvider: (ModelProvider) -> ModelProvider = { it }) = flow {
387-
val isFuzzable = executableId.parameters.all { classId ->
384+
val isFuzzable = methodUnderTest.parameters.all { classId ->
388385
classId != Method::class.java.id && // causes the child process crash at invocation
389386
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
390387
}
@@ -417,8 +414,8 @@ class UtBotSymbolicEngine(
417414
}
418415
}
419416

420-
val methodUnderTestDescription = FuzzedMethodDescription(executableId, collectConstantsForFuzzer(graph)).apply {
421-
compilableName = if (!methodUnderTest.isConstructor) executableId.name else null
417+
val methodUnderTestDescription = FuzzedMethodDescription(methodUnderTest, collectConstantsForFuzzer(graph)).apply {
418+
compilableName = if (!methodUnderTest.isConstructor) methodUnderTest.name else null
422419
className = classUnderTest.simpleName
423420
packageName = classUnderTest.packageName
424421
val names = graph.body.method.tags.filterIsInstance<ParamNamesTag>().firstOrNull()?.names
@@ -428,7 +425,7 @@ class UtBotSymbolicEngine(
428425
val coveredInstructionValues = linkedMapOf<Trie.Node<Instruction>, List<FuzzedValue>>()
429426
var attempts = 0
430427
val attemptsLimit = UtSettings.fuzzingMaxAttempts
431-
val hasMethodUnderTestParametersToFuzz = executableId.parameters.isNotEmpty()
428+
val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty()
432429
val fuzzedValues = if (hasMethodUnderTestParametersToFuzz) {
433430
fuzz(methodUnderTestDescription, modelProvider(defaultModelProviders(defaultIdGenerator)))
434431
} else {
@@ -627,7 +624,7 @@ class UtBotSymbolicEngine(
627624
}
628625
}
629626

630-
private fun ResolvedModels.constructStateForMethod(methodUnderTest: SootMethod): EnvironmentModels {
627+
private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId): EnvironmentModels {
631628
val (thisInstanceBefore, paramsBefore) = when {
632629
methodUnderTest.isStatic -> null to parameters
633630
methodUnderTest.isConstructor -> null to parameters.drop(1)
@@ -637,15 +634,15 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: SootMethod):
637634
}
638635

639636
private suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
640-
methodUnderTest: SootMethod,
637+
methodUnderTest: ExecutableId,
641638
stateBefore: EnvironmentModels,
642639
instrumentation: List<UtInstrumentation>
643640
): UtConcreteExecutionResult = executeAsync(
644-
methodUnderTest.declaringClass.name,
645-
methodUnderTest.pureJavaSignature,
641+
methodUnderTest.classId.name,
642+
methodUnderTest.signature,
646643
arrayOf(),
647644
parameters = UtConcreteExecutionData(stateBefore, instrumentation)
648-
).convertToAssemble(methodUnderTest)
645+
).convertToAssemble(methodUnderTest.classId.packageName)
649646

650647
/**
651648
* Before pushing our states for concrete execution, we have to be sure that every state is consistent.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import org.utbot.framework.plugin.api.UtArrayModel
88
import org.utbot.framework.plugin.api.UtClassRefModel
99
import org.utbot.framework.plugin.api.UtCompositeModel
1010
import org.utbot.framework.plugin.api.UtModel
11-
import org.utbot.framework.plugin.api.util.executableId
1211
import org.utbot.framework.plugin.api.util.id
13-
import org.utbot.framework.util.sootMethod
1412
import java.lang.reflect.Field
1513
import java.lang.reflect.Method
1614
import java.util.IdentityHashMap
@@ -50,7 +48,7 @@ class UtModelFactory(
5048
classUnderTest: Class<*>,
5149
models: List<UtModel>
5250
): IdentityHashMap<UtModel, UtModel> =
53-
AssembleModelGenerator(methodUnderTest.executableId.sootMethod)
51+
AssembleModelGenerator(classUnderTest.packageName)
5452
.createAssembleModels(models)
5553

5654
@JvmOverloads

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import org.utbot.framework.plugin.api.util.defaultValueModel
3838
import org.utbot.framework.plugin.api.util.executableId
3939
import org.utbot.framework.plugin.api.util.jClass
4040
import org.utbot.framework.util.nextModelName
41-
import soot.SootMethod
4241
import java.lang.reflect.Constructor
4342
import java.util.IdentityHashMap
4443

@@ -50,8 +49,7 @@ import java.util.IdentityHashMap
5049
*
5150
* Note: Caches class related information, can be reused if classes don't change.
5251
*/
53-
class AssembleModelGenerator(private val methodUnderTest: SootMethod) {
54-
private val methodPackageName = methodUnderTest.declaringClass.packageName
52+
class AssembleModelGenerator(private val methodPackageName: String) {
5553

5654
//Instantiated models are stored to avoid cyclic references during reference graph analysis
5755
private val instantiatedModels: IdentityHashMap<UtModel, UtReferenceModel> =

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import org.utbot.instrumentation.instrumentation.et.ExplicitThrowInstruction
4040
import org.utbot.instrumentation.instrumentation.et.TraceHandler
4141
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
4242
import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor
43-
import soot.SootMethod
4443
import java.security.AccessControlException
4544
import java.security.ProtectionDomain
4645
import java.util.IdentityHashMap
@@ -99,11 +98,11 @@ class UtConcreteExecutionResult(
9998
* @return [UtConcreteExecutionResult] with converted models.
10099
*/
101100
fun convertToAssemble(
102-
methodUnderTest: SootMethod
101+
packageName: String
103102
): UtConcreteExecutionResult {
104103
val allModels = collectAllModels()
105104

106-
val modelsToAssembleModels = AssembleModelGenerator(methodUnderTest).createAssembleModels(allModels)
105+
val modelsToAssembleModels = AssembleModelGenerator(packageName).createAssembleModels(allModels)
107106
return updateWithAssembleModels(modelsToAssembleModels)
108107
}
109108
}

0 commit comments

Comments
 (0)