Skip to content

Commit c89b3b2

Browse files
IlyaMuravjovEgorkaKulikov
authored andcommitted
Use same memoryScope to resolve uTest and symbolicResult.
1 parent c8fc4a5 commit c89b3b2

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

utbot-usvm/src/main/kotlin/org/utbot/usvm/jc/JcTestExecutor.kt

+15-22
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,8 @@ class JcTestExecutor(
6565
classConstants: Map<JcType, UConcreteHeapRef>,
6666
allowSymbolicResult: Boolean
6767
): JcExecution? {
68-
val model = state.models.first()
69-
val mocker = state.memory.mocker as JcMocker
70-
71-
val resolvedMethodMocks = mocker.symbols
72-
.entries
73-
.groupBy({ model.eval(it.key) }, { it.value })
74-
.mapValues { it.value.flatten() }
75-
76-
val uTest = createUTest(method, state, stringConstants, classConstants)
68+
val memoryScope = createMemoryScope(state, stringConstants, classConstants, method)
69+
val uTest = memoryScope.createUTest()
7770

7871
val concreteResult = runCatching {
7972
runBlocking {
@@ -90,17 +83,8 @@ class JcTestExecutor(
9083
when (val methodResult = state.methodResult) {
9184
is JcMethodResult.JcException -> UTestSymbolicExceptionResult(methodResult.type)
9285
is JcMethodResult.Success -> {
93-
val resultScope = MemoryScope(
94-
state.ctx,
95-
model,
96-
state.memory,
97-
stringConstants,
98-
classConstants,
99-
resolvedMethodMocks,
100-
method
101-
)
102-
val resultExpr = resultScope.resolveExpr(methodResult.value, method.returnType)
103-
val resultInitializer = resultScope.decoderApi.initializerInstructions()
86+
val resultExpr = memoryScope.resolveExpr(methodResult.value, method.returnType)
87+
val resultInitializer = memoryScope.decoderApi.initializerInstructions()
10488
UTestSymbolicSuccessResult(resultInitializer, resultExpr)
10589
}
10690

@@ -145,6 +129,16 @@ class JcTestExecutor(
145129
stringConstants: Map<String, UConcreteHeapRef>,
146130
classConstants: Map<JcType, UConcreteHeapRef>,
147131
): UTest {
132+
val memoryScope = createMemoryScope(state, stringConstants, classConstants, method)
133+
return memoryScope.createUTest()
134+
}
135+
136+
private fun createMemoryScope(
137+
state: JcState,
138+
stringConstants: Map<String, UConcreteHeapRef>,
139+
classConstants: Map<JcType, UConcreteHeapRef>,
140+
method: JcTypedMethod
141+
): MemoryScope {
148142
val model = state.models.first()
149143
val ctx = state.ctx
150144

@@ -158,8 +152,7 @@ class JcTestExecutor(
158152
.mapValues { it.value.flatten() }
159153

160154
val memoryScope = MemoryScope(ctx, model, model, stringConstants, classConstants, resolvedMethodMocks, method)
161-
162-
return memoryScope.createUTest()
155+
return memoryScope
163156
}
164157

165158
@Suppress("UNUSED_PARAMETER")

0 commit comments

Comments
 (0)