Skip to content

Limit number of unknown coverage executions #2627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
*/
var minimizeCrashExecutions by getBooleanProperty(true)

/**
* Determines maximum number of executions with unknown coverage per method per result type,
* typically unknown coverage is caused either by JVM crash or method under test not being
* executed (e.g. because [ClassLoader] failed to load class containing it or some dynamic
* proxy intercepted invocation and never called the method under test).
*/
var maxUnknownCoverageExecutionsPerMethodPerResultType by getIntProperty(2, 1, Int.MAX_VALUE)

/**
* Enable it to calculate unsat cores for hard constraints as well.
* It may be usefull during debug.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.utbot.framework.minimization

import org.utbot.framework.UtSettings
import org.utbot.framework.plugin.api.UtConcreteExecutionFailure
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtExecutionFailure
import org.utbot.framework.plugin.api.UtExecutionResult
import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.framework.plugin.api.*
import org.utbot.framework.util.calculateSize
import org.utbot.fuzzer.UtFuzzedExecution
import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor
Expand Down Expand Up @@ -41,9 +37,22 @@ fun <T : Any> minimizeTestCase(

fun minimizeExecutions(executions: List<UtExecution>): List<UtExecution> {
val unknownCoverageExecutions =
executions.filter { it.coverage?.coveredInstructions.isNullOrEmpty() }.toSet()
// ^^^ here we add executions with empty or null coverage, because it happens only if a concrete execution failed,
// so we don't know the actual coverage for such executions
executions
.filter { it.coverage?.coveredInstructions.isNullOrEmpty() }
.groupBy {
it.result.javaClass to (
(it.result as? UtExecutionSuccess)?.model ?: (it.result as? UtExecutionFailure)?.exception
)?.javaClass
}
.values
.flatMap { executionsGroup ->
val executionToSize = executionsGroup.associateWith { it.stateBefore.calculateSize() }
executionsGroup
.sortedBy { executionToSize[it] }
.take(UtSettings.maxUnknownCoverageExecutionsPerMethodPerResultType)
}
.toSet()
// ^^^ here we add executions with empty or null coverage

val filteredExecutions = filterOutDuplicateCoverages(executions - unknownCoverageExecutions)
val (mapping, executionToPriorityMapping) = buildMapping(filteredExecutions)
Expand Down