From 15025fabbcc34388248e3ab48ed9edc921487c8d Mon Sep 17 00:00:00 2001 From: Maksim Pelevin Date: Thu, 4 Aug 2022 12:07:44 +0300 Subject: [PATCH] Fuzzer fails with IllegalStateException #655 --- .../org/utbot/engine/UtBotSymbolicEngine.kt | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 54c553b3f1..c740114822 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -451,20 +451,31 @@ class UtBotSymbolicEngine( EnvironmentModels(values.first().model, emptyList(), mapOf()) } - try { - val concreteExecutionResult = - concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf()) + val concreteExecutionResult: UtConcreteExecutionResult? = try { + concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf()) + } catch (e: CancellationException) { + logger.debug { "Cancelled by timeout" }; null + } catch (e: ConcreteExecutionFailureException) { + emitFailedConcreteExecutionResult(initialEnvironmentModels, e); null + } catch (e: Throwable) { + emit(UtError("Default concrete execution failed", e)); null + } - workaround(REMOVE_ANONYMOUS_CLASSES) { - concreteExecutionResult.result.onSuccess { - if (it.classId.isAnonymous) { - logger.debug("Anonymous class found as a concrete result, symbolic one will be returned") - return@flow - } + // in case an exception occurred from the concrete execution + concreteExecutionResult ?: return@forEach + + workaround(REMOVE_ANONYMOUS_CLASSES) { + concreteExecutionResult.result.onSuccess { + if (it.classId.isAnonymous) { + logger.debug("Anonymous class found as a concrete result, symbolic one will be returned") + return@flow } } + } - val count = coveredInstructionTracker.add(concreteExecutionResult.coverage.coveredInstructions) + val coveredInstructions = concreteExecutionResult.coverage.coveredInstructions + if (coveredInstructions.isNotEmpty()) { + val count = coveredInstructionTracker.add(coveredInstructions) if (count.count > 1) { if (--attempts < 0) { return@flow @@ -472,35 +483,37 @@ class UtBotSymbolicEngine( return@forEach } coveredInstructionValues[count] = values - val nameSuggester = sequenceOf(ModelBasedNameSuggester(), MethodBasedNameSuggester()) - val testMethodName = try { - nameSuggester.flatMap { it.suggest(methodUnderTestDescription, values, concreteExecutionResult.result) }.firstOrNull() - } catch (t: Throwable) { - logger.error(t) { "Cannot create suggested test name for ${methodUnderTest.displayName}" } - null - } - - emit( - UtExecution( - stateBefore = initialEnvironmentModels, - stateAfter = concreteExecutionResult.stateAfter, - result = concreteExecutionResult.result, - instrumentation = emptyList(), - path = mutableListOf(), - fullPath = emptyList(), - coverage = concreteExecutionResult.coverage, - createdBy = UtExecutionCreator.FUZZER, - testMethodName = testMethodName?.testName, - displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName + } else { + logger.error { "Coverage is empty for $methodUnderTest with ${values.map { it.model }}" } + } + val nameSuggester = sequenceOf(ModelBasedNameSuggester(), MethodBasedNameSuggester()) + val testMethodName = try { + nameSuggester.flatMap { + it.suggest( + methodUnderTestDescription, + values, + concreteExecutionResult.result ) - ) - } catch (e: CancellationException) { - logger.debug { "Cancelled by timeout" } - } catch (e: ConcreteExecutionFailureException) { - emitFailedConcreteExecutionResult(initialEnvironmentModels, e) - } catch (e: Throwable) { - emit(UtError("Default concrete execution failed", e)) + }.firstOrNull() + } catch (t: Throwable) { + logger.error(t) { "Cannot create suggested test name for ${methodUnderTest.displayName}" } + null } + + emit( + UtExecution( + stateBefore = initialEnvironmentModels, + stateAfter = concreteExecutionResult.stateAfter, + result = concreteExecutionResult.result, + instrumentation = emptyList(), + path = mutableListOf(), + fullPath = emptyList(), + coverage = concreteExecutionResult.coverage, + createdBy = UtExecutionCreator.FUZZER, + testMethodName = testMethodName?.testName, + displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName + ) + ) } }