@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.catch
88import kotlinx.coroutines.flow.emitAll
99import kotlinx.coroutines.flow.flow
1010import kotlinx.coroutines.flow.flowOf
11+ import kotlinx.coroutines.flow.map
1112import kotlinx.coroutines.isActive
1213import kotlinx.coroutines.launch
1314import kotlinx.coroutines.yield
@@ -16,6 +17,7 @@ import mu.KotlinLogging
1617import org.utbot.common.*
1718import org.utbot.engine.EngineController
1819import org.utbot.engine.Mocker
20+ import org.utbot.engine.UsvmSymbolicEngine
1921import org.utbot.engine.UtBotSymbolicEngine
2022import org.utbot.engine.util.mockListeners.ForceMockListener
2123import org.utbot.engine.util.mockListeners.ForceStaticMockListener
@@ -173,9 +175,10 @@ open class TestCaseGenerator(
173175 methods : List <ExecutableId >,
174176 mockStrategy : MockStrategyApi ,
175177 chosenClassesToMockAlways : Set <ClassId > = Mocker .javaDefaultClasses.mapTo(mutableSetOf()) { it.id },
176- methodsGenerationTimeout : Long = utBotGenerationTimeoutInMillis,
178+ utBotTimeout : Long = utBotGenerationTimeoutInMillis,
177179 userTaintConfigurationProvider : TaintConfigurationProvider ? = null,
178- generate : (engine: UtBotSymbolicEngine ) -> Flow <UtResult > = defaultTestFlow(methodsGenerationTimeout)
180+ generate : (engine: UtBotSymbolicEngine ) -> Flow <UtResult > = defaultTestFlow(utBotTimeout),
181+ usvmTimeoutMillis : Long = 0,
179182 ): List <UtMethodTestSet > = ConcreteExecutor .defaultPool.use { _ -> // TODO: think on appropriate way to close instrumented processes
180183 if (isCanceled()) return @use methods.map { UtMethodTestSet (it) }
181184
@@ -189,7 +192,7 @@ open class TestCaseGenerator(
189192 return @use methods.map { method -> UtMethodTestSet (method, errors = method2errors.getValue(method)) }
190193
191194 val executionStartInMillis = System .currentTimeMillis()
192- val executionTimeEstimator = ExecutionTimeEstimator (methodsGenerationTimeout , methods.size)
195+ val executionTimeEstimator = ExecutionTimeEstimator (utBotTimeout , methods.size)
193196
194197 val currentUtContext = utContext
195198
@@ -200,6 +203,29 @@ open class TestCaseGenerator(
200203 val forceMockListener = ForceMockListener .create(this , conflictTriggers)
201204 val forceStaticMockListener = ForceStaticMockListener .create(this , conflictTriggers)
202205
206+ suspend fun consumeUtResultFlow (utResultFlow : Flow <Pair <ExecutableId , UtResult >>) =
207+ utResultFlow.catch {
208+ logger.error(it) { " Error in flow" }
209+ }
210+ .collect { (executableId, utResult) ->
211+ when (utResult) {
212+ is UtExecution -> {
213+ if (utResult is UtSymbolicExecution &&
214+ (conflictTriggers.triggered(Conflict .ForceMockHappened ) ||
215+ conflictTriggers.triggered(Conflict .ForceStaticMockHappened ))
216+ ) {
217+ utResult.containsMocking = true
218+ }
219+ method2executions.getValue(executableId) + = utResult
220+ }
221+
222+ is UtError -> {
223+ method2errors.getValue(executableId).merge(utResult.description, 1 , Int ::plus)
224+ logger.error(utResult.error) { " UtError occurred" }
225+ }
226+ }
227+ }
228+
203229 runIgnoringCancellationException {
204230 runBlockingWithCancellationPredicate(isCanceled) {
205231 for ((method, controller) in method2controller) {
@@ -223,27 +249,7 @@ open class TestCaseGenerator(
223249 engineActions.map { engine.apply (it) }
224250 engineActions.clear()
225251
226- generate(engine)
227- .catch {
228- logger.error(it) { " Error in flow" }
229- }
230- .collect {
231- when (it) {
232- is UtExecution -> {
233- if (it is UtSymbolicExecution &&
234- (conflictTriggers.triggered(Conflict .ForceMockHappened ) ||
235- conflictTriggers.triggered(Conflict .ForceStaticMockHappened ))
236- ) {
237- it.containsMocking = true
238- }
239- method2executions.getValue(method) + = it
240- }
241- is UtError -> {
242- method2errors.getValue(method).merge(it.description, 1 , Int ::plus)
243- logger.error(it.error) { " UtError occurred" }
244- }
245- }
246- }
252+ consumeUtResultFlow(generate(engine).map { utResult -> method to utResult })
247253 } catch (e: Exception ) {
248254 logger.error(e) {" Error in engine" }
249255 throw e
@@ -284,6 +290,8 @@ open class TestCaseGenerator(
284290 }
285291 logger.debug(" test generator global scope lifecycle check ended" )
286292 }
293+
294+ consumeUtResultFlow(UsvmSymbolicEngine .runUsvmGeneration(methods, classpathForEngine, usvmTimeoutMillis))
287295 }
288296 }
289297
0 commit comments