@@ -25,6 +25,7 @@ import org.utbot.framework.plugin.api.Coverage
25
25
import org.utbot.framework.plugin.api.EnvironmentModels
26
26
import org.utbot.framework.plugin.api.ExecutableId
27
27
import org.utbot.framework.plugin.api.Instruction
28
+ import org.utbot.framework.plugin.api.UtArrayModel
28
29
import org.utbot.framework.plugin.api.UtAssembleModel
29
30
import org.utbot.framework.plugin.api.UtExecutableCallModel
30
31
import org.utbot.framework.plugin.api.UtExecution
@@ -34,12 +35,14 @@ import org.utbot.framework.plugin.api.UtExplicitlyThrownException
34
35
import org.utbot.framework.plugin.api.UtImplicitlyThrownException
35
36
import org.utbot.framework.plugin.api.UtInstrumentation
36
37
import org.utbot.framework.plugin.api.UtPrimitiveModel
38
+ import org.utbot.framework.plugin.api.UtStatementCallModel
37
39
import org.utbot.framework.plugin.api.UtVoidModel
38
40
import org.utbot.framework.plugin.api.mapper.UtModelDeepMapper
39
41
import org.utbot.framework.plugin.api.util.executableId
40
42
import org.utbot.framework.plugin.api.util.jClass
41
43
import org.utbot.framework.plugin.api.util.utContext
42
44
import org.utbot.fuzzer.IdGenerator
45
+ import java.util.IdentityHashMap
43
46
44
47
private val logger = KotlinLogging .logger {}
45
48
@@ -68,17 +71,19 @@ class JcToUtExecutionConverter(
68
71
69
72
val utUsvmExecution: UtUsvmExecution = when (val executionResult = jcExecution.uTestExecutionResult) {
70
73
is UTestExecutionSuccessResult -> UtUsvmExecution (
71
- stateBefore = convertState(executionResult.initialState, jcExecution.method, jcToUtModelConverter ),
72
- stateAfter = convertState(executionResult.resultState, jcExecution.method, jcToUtModelConverter ),
74
+ stateBefore = convertState(executionResult.initialState, EnvironmentStateKind . INITIAL , jcExecution.method ),
75
+ stateAfter = convertState(executionResult.resultState, EnvironmentStateKind . FINAL , jcExecution.method ),
73
76
// TODO usvm-sbft: ask why `UTestExecutionSuccessResult.result` is nullable
74
- result = UtExecutionSuccess (executionResult.result?.let { jcToUtModelConverter.convert(it) } ? : UtVoidModel ),
77
+ result = UtExecutionSuccess (executionResult.result?.let {
78
+ jcToUtModelConverter.convert(it, EnvironmentStateKind .FINAL )
79
+ } ? : UtVoidModel ),
75
80
coverage = coverage,
76
81
instrumentation = instrumentation,
77
82
)
78
83
is UTestExecutionExceptionResult -> {
79
84
UtUsvmExecution (
80
- stateBefore = convertState(executionResult.initialState, jcExecution.method, jcToUtModelConverter ),
81
- stateAfter = convertState(executionResult.resultState, jcExecution.method, jcToUtModelConverter ),
85
+ stateBefore = convertState(executionResult.initialState, EnvironmentStateKind . INITIAL , jcExecution.method ),
86
+ stateAfter = convertState(executionResult.resultState, EnvironmentStateKind . FINAL , jcExecution.method ),
82
87
result = createExecutionFailureResult(
83
88
executionResult.cause,
84
89
jcExecution.method,
@@ -108,7 +113,10 @@ class JcToUtExecutionConverter(
108
113
}
109
114
} ? : return null
110
115
111
- return utUsvmExecution.mapModels(constructAssemblingMapper())
116
+ return utUsvmExecution
117
+ .mapModels(constructAssemblingMapper())
118
+ .mapModels(constructAssembleToCompositeModelMapper())
119
+ .mapModels(constructConstArrayModelMapper())
112
120
}
113
121
114
122
private fun constructAssemblingMapper (): UtModelDeepMapper = UtModelDeepMapper { model ->
@@ -145,6 +153,31 @@ class JcToUtExecutionConverter(
145
153
} ? : model
146
154
}
147
155
156
+ private fun constructConstArrayModelMapper (): UtModelDeepMapper = UtModelDeepMapper { model ->
157
+ if (model is UtArrayModel ) {
158
+ val storeGroups = model.stores.entries.groupByTo(IdentityHashMap ()) { it.value }
159
+ val mostCommonStore = storeGroups.maxBy { it.value.size }
160
+ if (mostCommonStore.value.size > 1 ) {
161
+ model.constModel = mostCommonStore.key
162
+ mostCommonStore.value.forEach { (index, _) -> model.stores.remove(index) }
163
+ }
164
+ }
165
+ model
166
+ }
167
+
168
+ private fun constructAssembleToCompositeModelMapper (): UtModelDeepMapper = UtModelDeepMapper { model ->
169
+ if (model is UtAssembleModel
170
+ && utilMethodProvider.createInstanceMethodId == model.instantiationCall.statement
171
+ && model.modificationsChain.all {
172
+ utilMethodProvider.setFieldMethodId == (it as ? UtStatementCallModel )?.statement
173
+ }
174
+ ) {
175
+ model.origin ? : model
176
+ } else {
177
+ model
178
+ }
179
+ }
180
+
148
181
private fun convertException (exceptionDescriptor : UTestExceptionDescriptor ): Throwable =
149
182
toValueConverter.buildObjectFromDescriptor(exceptionDescriptor.dropStaticFields(
150
183
cache = mutableMapOf ()
@@ -160,18 +193,20 @@ class JcToUtExecutionConverter(
160
193
161
194
private fun convertState (
162
195
state : UTestExecutionState ,
196
+ stateKind : EnvironmentStateKind ,
163
197
method : JcTypedMethod ,
164
- modelConverter : JcToUtModelConverter ,
165
- ): EnvironmentModels {
198
+ ): EnvironmentModels {
166
199
val thisInstance =
167
200
if (method.isStatic) null
168
201
else if (method.method.isConstructor) null
169
- else modelConverter.convert(state.instanceDescriptor ? : error(" Unexpected null instanceDescriptor" ))
170
- val parameters = state.argsDescriptors.map { modelConverter.convert(it ? : error(" Unexpected null argDescriptor" )) }
202
+ else jcToUtModelConverter.convert(state.instanceDescriptor ? : error(" Unexpected null instanceDescriptor" ), stateKind)
203
+ val parameters = state.argsDescriptors.map {
204
+ jcToUtModelConverter.convert(it ? : error(" Unexpected null argDescriptor" ), stateKind)
205
+ }
171
206
val statics = state.statics
172
207
.entries
173
208
.associate { (jcField, uTestDescr) ->
174
- jcField.fieldId to modelConverter .convert(uTestDescr)
209
+ jcField.fieldId to jcToUtModelConverter .convert(uTestDescr, stateKind )
175
210
}
176
211
val executableId: ExecutableId = method.method.toExecutableId(jcClasspath)
177
212
return EnvironmentModels (thisInstance, parameters, statics, executableId)
0 commit comments