@@ -18,6 +18,7 @@ import org.utbot.framework.plugin.api.UtModel
1818import org.utbot.framework.plugin.api.UtNullModel
1919import org.utbot.framework.plugin.api.UtPrimitiveModel
2020import org.utbot.framework.plugin.api.UtStatementModel
21+ import org.utbot.framework.plugin.api.UtSymbolicExecution
2122import org.utbot.framework.plugin.api.UtVoidModel
2223
2324
@@ -53,8 +54,11 @@ fun minimizeExecutions(executions: List<UtExecution>): List<UtExecution> {
5354 executions.indices.filter { executions[it].coverage?.coveredInstructions?.isEmpty() ? : true }.toSet()
5455 // ^^^ here we add executions with empty or null coverage, because it happens only if a concrete execution failed,
5556 // so we don't know the actual coverage for such executions
56- val mapping = buildMapping(executions.filterIndexed { idx, _ -> idx !in unknownCoverageExecutions })
57- val usedExecutionIndexes = (GreedyEssential .minimize(mapping) + unknownCoverageExecutions).toSet()
57+
58+ val filteredExecutions = executions.filterIndexed { idx, _ -> idx !in unknownCoverageExecutions }
59+ val (mapping, executionToPriorityMapping) = buildMapping(filteredExecutions)
60+
61+ val usedExecutionIndexes = (GreedyEssential .minimize(mapping, executionToPriorityMapping) + unknownCoverageExecutions).toSet()
5862
5963 val usedMinimizedExecutions = executions.filterIndexed { idx, _ -> idx in usedExecutionIndexes }
6064
@@ -143,13 +147,14 @@ private fun <T : Any> groupExecutionsByTestSuite(
143147 executions.groupBy { executionToTestSuite(it) }.values
144148
145149/* *
146- * Builds a mapping from execution id to edges id.
150+ * Builds a mapping from execution id to edges id and from execution id to its priority .
147151 */
148- private fun buildMapping (executions : List <UtExecution >): Map <Int , List <Int >> {
152+ private fun buildMapping (executions : List <UtExecution >): Pair < Map <Int , List <Int >>, Map<Int, Int>> {
149153 // (inst1, instr2) -> edge id --- edge represents as a pair of instructions, which are connected by this edge
150154 val allCoveredEdges = mutableMapOf<Pair <Long , Long >, Int > ()
151155 val thrownExceptions = mutableMapOf<String , Long >()
152156 val mapping = mutableMapOf<Int , List <Int >>()
157+ val executionToPriorityMapping = mutableMapOf<Int , Int >()
153158
154159
155160 executions.forEachIndexed { idx, execution ->
@@ -169,11 +174,12 @@ private fun buildMapping(executions: List<UtExecution>): Map<Int, List<Int>> {
169174 edges + = allCoveredEdges[instructions[i] to instructions[i + 1 ]]!!
170175 }
171176 mapping[idx] = edges
177+ executionToPriorityMapping[idx] = execution.getExecutionPriority()
172178 }
173179 }
174180 }
175181
176- return mapping
182+ return Pair ( mapping, executionToPriorityMapping)
177183}
178184
179185/* *
@@ -264,4 +270,15 @@ private fun addExtraIfLastInstructionIsException(
264270 * Takes an exception name, a class name, a method signature and a line number from exception.
265271 */
266272private fun Throwable.exceptionToInfo (): String =
267- this ::class .java.name + (this .stackTrace.firstOrNull()?.run { className + methodName + lineNumber } ? : " null" )
273+ this ::class .java.name + (this .stackTrace.firstOrNull()?.run { className + methodName + lineNumber } ? : " null" )
274+
275+ /* *
276+ * Returns an execution priority. [UtSymbolicExecution] has the highest priority
277+ * over other executions like [UtFuzzedExecution], [UtFailedExecution], etc.
278+ *
279+ * See [https://github.com/UnitTestBot/UTBotJava/issues/1504] for more details.
280+ */
281+ private fun UtExecution.getExecutionPriority (): Int = when (this ) {
282+ is UtSymbolicExecution -> 0
283+ else -> 1
284+ }
0 commit comments