@@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.catch
8
8
import kotlinx.coroutines.flow.emitAll
9
9
import kotlinx.coroutines.flow.flow
10
10
import kotlinx.coroutines.flow.flowOf
11
+ import kotlinx.coroutines.flow.map
11
12
import kotlinx.coroutines.isActive
12
13
import kotlinx.coroutines.launch
13
14
import kotlinx.coroutines.yield
@@ -16,6 +17,7 @@ import mu.KotlinLogging
16
17
import org.utbot.common.*
17
18
import org.utbot.engine.EngineController
18
19
import org.utbot.engine.Mocker
20
+ import org.utbot.engine.UsvmSymbolicEngine
19
21
import org.utbot.engine.UtBotSymbolicEngine
20
22
import org.utbot.engine.util.mockListeners.ForceMockListener
21
23
import org.utbot.engine.util.mockListeners.ForceStaticMockListener
@@ -173,9 +175,10 @@ open class TestCaseGenerator(
173
175
methods : List <ExecutableId >,
174
176
mockStrategy : MockStrategyApi ,
175
177
chosenClassesToMockAlways : Set <ClassId > = Mocker .javaDefaultClasses.mapTo(mutableSetOf()) { it.id },
176
- methodsGenerationTimeout : Long = utBotGenerationTimeoutInMillis,
178
+ utBotTimeout : Long = utBotGenerationTimeoutInMillis,
177
179
userTaintConfigurationProvider : TaintConfigurationProvider ? = null,
178
- generate : (engine: UtBotSymbolicEngine ) -> Flow <UtResult > = defaultTestFlow(methodsGenerationTimeout)
180
+ generate : (engine: UtBotSymbolicEngine ) -> Flow <UtResult > = defaultTestFlow(utBotTimeout),
181
+ usvmTimeoutMillis : Long = 0,
179
182
): List <UtMethodTestSet > = ConcreteExecutor .defaultPool.use { _ -> // TODO: think on appropriate way to close instrumented processes
180
183
if (isCanceled()) return @use methods.map { UtMethodTestSet (it) }
181
184
@@ -189,7 +192,7 @@ open class TestCaseGenerator(
189
192
return @use methods.map { method -> UtMethodTestSet (method, errors = method2errors.getValue(method)) }
190
193
191
194
val executionStartInMillis = System .currentTimeMillis()
192
- val executionTimeEstimator = ExecutionTimeEstimator (methodsGenerationTimeout , methods.size)
195
+ val executionTimeEstimator = ExecutionTimeEstimator (utBotTimeout , methods.size)
193
196
194
197
val currentUtContext = utContext
195
198
@@ -200,6 +203,29 @@ open class TestCaseGenerator(
200
203
val forceMockListener = ForceMockListener .create(this , conflictTriggers)
201
204
val forceStaticMockListener = ForceStaticMockListener .create(this , conflictTriggers)
202
205
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
+
203
229
runIgnoringCancellationException {
204
230
runBlockingWithCancellationPredicate(isCanceled) {
205
231
for ((method, controller) in method2controller) {
@@ -223,27 +249,7 @@ open class TestCaseGenerator(
223
249
engineActions.map { engine.apply (it) }
224
250
engineActions.clear()
225
251
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 })
247
253
} catch (e: Exception ) {
248
254
logger.error(e) {" Error in engine" }
249
255
throw e
@@ -284,6 +290,8 @@ open class TestCaseGenerator(
284
290
}
285
291
logger.debug(" test generator global scope lifecycle check ended" )
286
292
}
293
+
294
+ consumeUtResultFlow(UsvmSymbolicEngine .runUsvmGeneration(methods, classpathForEngine, usvmTimeoutMillis))
287
295
}
288
296
}
289
297
0 commit comments