Skip to content

Commit fbc0541

Browse files
Split processResult
1 parent a42d75c commit fbc0541

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ data class ExecutionState(
252252
)
253253
}
254254

255-
fun updateMemory(
255+
fun update(
256256
stateUpdate: SymbolicStateUpdate
257257
): ExecutionState {
258258
val last = executionStack.last()

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ class Traverser(
17971797
}
17981798

17991799
queuedSymbolicStateUpdates += arrayUpdateWithValue(arrayValue.addr, CharType.v().arrayType, newArray)
1800-
environment.state = environment.state.updateMemory(queuedSymbolicStateUpdates)
1800+
environment.state = environment.state.update(queuedSymbolicStateUpdates)
18011801
queuedSymbolicStateUpdates = queuedSymbolicStateUpdates.copy(memoryUpdates = MemoryUpdate())
18021802
}
18031803

@@ -3770,52 +3770,68 @@ class Traverser(
37703770
queuedSymbolicStateUpdates += mkNot(mkEq(symbolicResult.value.addr, nullObjectAddr)).asHardConstraint()
37713771
}
37723772

3773-
val newSolver = solver.add(
3774-
hard = queuedSymbolicStateUpdates.hardConstraints,
3775-
soft = queuedSymbolicStateUpdates.softConstraints
3776-
)
3777-
3778-
val updatedMemory = memory.update(queuedSymbolicStateUpdates.memoryUpdates)
3773+
val state = environment.state.update(queuedSymbolicStateUpdates)
3774+
val memory = state.memory
3775+
val solver = state.solver
37793776

37803777
//no need to respect soft constraints in NestedMethod
3781-
val holder = newSolver.check(respectSoft = !environment.state.isInNestedMethod())
3778+
val holder = solver.check(respectSoft = !state.isInNestedMethod())
37823779

37833780
if (holder !is UtSolverStatusSAT) {
37843781
logger.trace { "processResult<${environment.method.signature}> UNSAT" }
37853782
return
37863783
}
3784+
val methodResult = MethodResult(symbolicResult)
37873785

37883786
//execution frame from level 2 or above
3789-
if (environment.state.isInNestedMethod()) {
3787+
if (state.isInNestedMethod()) {
37903788
// static fields substitution
37913789
// TODO: JIRA:1610 -- better way of working with statics
37923790
val updates = if (environment.method.name == STATIC_INITIALIZER && substituteStaticsWithSymbolicVariable) {
37933791
substituteStaticFieldsWithSymbolicVariables(
37943792
environment.method.declaringClass,
3795-
updatedMemory.queuedStaticMemoryUpdates()
3793+
memory.queuedStaticMemoryUpdates()
37963794
)
37973795
} else {
37983796
MemoryUpdate() // all memory updates are already added in [environment.state]
37993797
}
3800-
val methodResult = MethodResult(
3801-
symbolicResult,
3802-
queuedSymbolicStateUpdates + updates
3803-
)
3804-
val stateToOffer = environment.state.pop(methodResult)
3798+
val stateToOffer = state.pop(methodResult.copy(symbolicStateUpdate = updates.asUpdate()))
38053799
pathSelector.offer(stateToOffer)
38063800

38073801
logger.trace { "processResult<${environment.method.signature}> return from nested method" }
38083802
return
38093803
}
38103804

38113805
//toplevel method
3806+
val terminalExecutionState =
3807+
state.copy(
3808+
methodResult = methodResult, // a way to put SymbolicResult into terminal state
3809+
label = StateLabel.TERMINAL
3810+
)
3811+
consumeTerminalState(terminalExecutionState)
3812+
}
3813+
3814+
private suspend fun FlowCollector<UtResult>.consumeTerminalState(
3815+
state: ExecutionState,
3816+
) {
3817+
// some checks to be sure the state is correct
3818+
require(state.label == StateLabel.TERMINAL) { "Can't process non-terminal state!" }
3819+
require(!state.isInNestedMethod()) { "The state has to correspond to the MUT"}
3820+
3821+
val memory = state.memory
3822+
val solver = state.solver
3823+
val parameters = state.parameters.map { it.value }
3824+
val symbolicResult = requireNotNull(state.methodResult?.symbolicResult) { "The state must have symbolicResult"}
3825+
// it's free to make a check, because in the result is SAT, it should be already cached
3826+
val holder = requireNotNull(solver.check(respectSoft = true) as? UtSolverStatusSAT) { "The state must be SAT!" }
3827+
38123828
val predictedTestName = Predictors.testName.predict(environment.state.path)
38133829
Predictors.testName.provide(environment.state.path, predictedTestName, "")
38143830

38153831
val resolver =
3816-
Resolver(hierarchy, updatedMemory, typeRegistry, typeResolver, holder, methodUnderTest, softMaxArraySize)
3832+
Resolver(hierarchy, memory, typeRegistry, typeResolver, holder, methodUnderTest, softMaxArraySize)
38173833

3818-
val (modelsBefore, modelsAfter, instrumentation) = resolver.resolveModels(resolvedParameters)
3834+
val (modelsBefore, modelsAfter, instrumentation) = resolver.resolveModels(parameters)
38193835

38203836
val symbolicExecutionResult = resolver.resolveResult(symbolicResult)
38213837

0 commit comments

Comments
 (0)