@@ -36,6 +36,7 @@ import org.utbot.framework.plugin.api.util.utContext
36
36
import org.utbot.framework.plugin.api.util.withUtContext
37
37
import org.utbot.framework.plugin.services.JdkInfo
38
38
import org.utbot.framework.synthesis.Synthesizer
39
+ import org.utbot.framework.synthesis.SynthesizerController
39
40
import org.utbot.framework.synthesis.postcondition.constructors.EmptyPostCondition
40
41
import org.utbot.framework.synthesis.postcondition.constructors.PostConditionConstructor
41
42
import org.utbot.framework.util.SootUtils
@@ -52,6 +53,7 @@ import java.util.*
52
53
import kotlin.coroutines.cancellation.CancellationException
53
54
import kotlin.math.min
54
55
import kotlin.reflect.KCallable
56
+ import kotlin.system.measureTimeMillis
55
57
56
58
/* *
57
59
* Generates test cases: one by one or a whole set for the method under test.
@@ -74,6 +76,7 @@ open class TestCaseGenerator(
74
76
) {
75
77
private val logger: KLogger = KotlinLogging .logger {}
76
78
private val timeoutLogger: KLogger = KotlinLogging .logger(logger.name + " .timeout" )
79
+ protected var synthesizerController = SynthesizerController (UtSettings .synthesisTimeoutInMillis)
77
80
78
81
private val classpathForEngine: String
79
82
get() = buildDir.toString() + (classpath?.let { File .pathSeparator + it } ? : " " )
@@ -387,20 +390,26 @@ open class TestCaseGenerator(
387
390
388
391
protected fun List<UtExecution>.toAssemble (method : ExecutableId ): List <UtExecution > =
389
392
map { execution ->
390
- val symbolicExecution = (execution as ? UtSymbolicExecution )
391
- ? : return @map execution
392
-
393
- val newBeforeState = mapEnvironmentModels(method, symbolicExecution, symbolicExecution.stateBefore) {
394
- it.modelsBefore
395
- } ? : return @map execution
396
- val newAfterState = getConcreteAfterState(method, newBeforeState) ? : return @map execution
397
-
398
- symbolicExecution.copy(
399
- newBeforeState,
400
- newAfterState,
401
- symbolicExecution.result,
402
- symbolicExecution.coverage
403
- )
393
+ var result = execution
394
+ synthesizerController.spentTime + = measureTimeMillis {
395
+ if (! synthesizerController.hasTimeLimit()) return @measureTimeMillis
396
+
397
+ val symbolicExecution = (execution as ? UtSymbolicExecution )
398
+ ? : return @measureTimeMillis
399
+
400
+ val newBeforeState = mapEnvironmentModels(method, symbolicExecution, symbolicExecution.stateBefore) {
401
+ it.modelsBefore
402
+ } ? : return @measureTimeMillis
403
+ val newAfterState = getConcreteAfterState(method, newBeforeState) ? : return @measureTimeMillis
404
+
405
+ result = symbolicExecution.copy(
406
+ newBeforeState,
407
+ newAfterState,
408
+ symbolicExecution.result,
409
+ symbolicExecution.coverage
410
+ )
411
+ }
412
+ result
404
413
}
405
414
406
415
private fun mapEnvironmentModels (
@@ -411,7 +420,7 @@ open class TestCaseGenerator(
411
420
): EnvironmentModels ? {
412
421
val constrainedExecution = symbolicExecution.constrainedExecution ? : return null
413
422
val aa = Synthesizer (this @TestCaseGenerator, method, selector(constrainedExecution))
414
- val synthesizedModels = aa.synthesize()
423
+ val synthesizedModels = aa.synthesize(synthesizerController.localTimeLimit )
415
424
416
425
val (synthesizedThis, synthesizedParameters) = models.thisInstance?.let {
417
426
synthesizedModels.first() to synthesizedModels.drop(1 )
0 commit comments