Skip to content

Commit ae79145

Browse files
committed
Provide stateBefore for concrete execution result
1 parent 051b293 commit ae79145

File tree

10 files changed

+35
-20
lines changed

10 files changed

+35
-20
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ sealed class UtStatementCallModel(
735735
override val instance: UtReferenceModel?,
736736
open val statement: StatementId,
737737
open val params: List<UtModel>,
738+
var thrownConcreteException: ClassId? = null
738739
): UtStatementModel(instance) {
739740
override fun toString() = withToStringThreadLocalReentrancyGuard {
740741
buildString {

utbot-framework/src/main/kotlin/org/utbot/framework/util/UtConcreteExecutionResultUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private fun UtConcreteExecutionResult.updateWithAssembleModels(
2222
(result as? UtExecutionSuccess)?.model?.let { UtExecutionSuccess(toAssemble(it)) } ?: result
2323

2424
return UtConcreteExecutionResult(
25+
stateBefore,
2526
resolvedStateAfter,
2627
resolvedResult,
2728
coverage,

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/SimpleUtExecutionInstrumentation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class SimpleUtExecutionInstrumentation(
9999
}
100100

101101
UtConcreteExecutionResult(
102+
parameters.stateBefore,
102103
stateAfter,
103104
executionResult,
104105
coverage,

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ data class UtConcreteExecutionData(
2323
)
2424

2525
data class UtConcreteExecutionResult(
26+
val stateBefore: EnvironmentModels,
2627
val stateAfter: EnvironmentModels,
2728
val result: UtExecutionResult,
2829
val coverage: Coverage,

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/InstrumentationContextAwareValueConstructor.kt

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.utbot.instrumentation.instrumentation.execution.mock.MockController
4747
import org.utbot.instrumentation.process.runSandbox
4848
import java.lang.reflect.Modifier
4949
import java.util.*
50+
import org.utbot.framework.plugin.api.util.id
5051
import kotlin.reflect.KClass
5152

5253
/**
@@ -321,7 +322,7 @@ class InstrumentationContextAwareValueConstructor(
321322
constructedObjects[assembleModel]?.let { return it }
322323

323324
val instantiationExecutableCall = assembleModel.instantiationCall
324-
val result = updateWithStatementCallModel(instantiationExecutableCall)
325+
val result = updateWithStatementCallModel(instantiationExecutableCall).getOrThrow()
325326

326327
// Executions that get `null` in a complicated way (e.g. like this: `new Pair(null, null).getFirst()`)
327328
// are only produced by fuzzer and are considered undesirable because fuzzer can also produce simpler
@@ -381,26 +382,34 @@ class InstrumentationContextAwareValueConstructor(
381382
*
382383
* @return the result of [callModel] invocation
383384
*/
384-
private fun updateWithStatementCallModel(callModel: UtStatementCallModel): Any? {
385-
when (callModel) {
386-
is UtExecutableCallModel -> {
387-
val executable = callModel.executable
388-
val instanceValue = callModel.instance?.let { value(it) }
389-
val params = callModel.params.map { value(it) }
390-
391-
return when (executable) {
392-
is MethodId -> executable.call(params, instanceValue)
393-
is ConstructorId -> executable.call(params)
385+
private fun updateWithStatementCallModel(callModel: UtStatementCallModel): Result<*> =
386+
runCatching {
387+
when (callModel) {
388+
is UtExecutableCallModel -> {
389+
val executable = callModel.executable
390+
val instanceValue = callModel.instance?.let { value(it) }
391+
val params = callModel.params.map { value(it) }
392+
393+
when (executable) {
394+
is MethodId -> executable.call(params, instanceValue)
395+
is ConstructorId -> executable.call(params)
396+
}
394397
}
395-
}
396-
is UtDirectGetFieldModel -> {
397-
val fieldAccess = callModel.fieldAccess
398-
val instanceValue = value(callModel.instance)
399398

400-
return fieldAccess.get(instanceValue)
399+
is UtDirectGetFieldModel -> {
400+
val fieldAccess = callModel.fieldAccess
401+
val instanceValue = value(callModel.instance)
402+
403+
fieldAccess.get(instanceValue)
404+
}
401405
}
402406
}
403-
}
407+
.also { result ->
408+
result
409+
.exceptionOrNull()
410+
?.let { callModel.thrownConcreteException = it.javaClass.id }
411+
}
412+
404413

405414
/**
406415
* Updates instance with [UtDirectSetFieldModel] execution.

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/InvocationPhase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class InvocationPhase(
1818
override fun wrapError(e: Throwable): ExecutionPhaseException {
1919
val message = this.javaClass.simpleName
2020
return when(e) {
21-
is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage()))
21+
is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, MissingState, UtTimeoutException(e), Coverage()))
2222
else -> ExecutionPhaseError(message, e)
2323
}
2424
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ModelConstructionPhase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ModelConstructionPhase(
2525
return when (e) {
2626
is TimeoutException -> ExecutionPhaseStop(
2727
message,
28-
UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())
28+
UtConcreteExecutionResult(MissingState, MissingState, UtTimeoutException(e), Coverage())
2929
)
3030

3131
else -> ExecutionPhaseError(message, e)

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class PhasesController(
4343
} catch (e: ExecutionPhaseError) {
4444
if (e.cause.cause is AccessControlException) {
4545
return UtConcreteExecutionResult(
46+
MissingState,
4647
MissingState,
4748
UtSandboxFailure(e.cause.cause!!),
4849
Coverage()

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/StatisticsCollectionPhase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class StatisticsCollectionPhase(
2222
return when (e) {
2323
is TimeoutException -> ExecutionPhaseStop(
2424
message,
25-
UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())
25+
UtConcreteExecutionResult(MissingState, MissingState, UtTimeoutException(e), Coverage())
2626
)
2727

2828
else -> ExecutionPhaseError(message, e)

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionPhase.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ValueConstructionPhase(
2727
override fun wrapError(e: Throwable): ExecutionPhaseException = ExecutionPhaseStop(
2828
phase = this.javaClass.simpleName,
2929
result = UtConcreteExecutionResult(
30+
stateBefore = MissingState,
3031
stateAfter = MissingState,
3132
result = when(e) {
3233
is TimeoutException -> UtTimeoutException(e)

0 commit comments

Comments
 (0)