@@ -18,6 +18,7 @@ import org.utbot.framework.plugin.api.UtModel
18
18
import org.utbot.framework.plugin.api.UtNullModel
19
19
import org.utbot.framework.plugin.api.UtPrimitiveModel
20
20
import org.utbot.framework.plugin.api.UtStatementModel
21
+ import org.utbot.framework.plugin.api.UtSymbolicExecution
21
22
import org.utbot.framework.plugin.api.UtVoidModel
22
23
23
24
@@ -53,8 +54,11 @@ fun minimizeExecutions(executions: List<UtExecution>): List<UtExecution> {
53
54
executions.indices.filter { executions[it].coverage?.coveredInstructions?.isEmpty() ? : true }.toSet()
54
55
// ^^^ here we add executions with empty or null coverage, because it happens only if a concrete execution failed,
55
56
// 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()
58
62
59
63
val usedMinimizedExecutions = executions.filterIndexed { idx, _ -> idx in usedExecutionIndexes }
60
64
@@ -143,13 +147,14 @@ private fun <T : Any> groupExecutionsByTestSuite(
143
147
executions.groupBy { executionToTestSuite(it) }.values
144
148
145
149
/* *
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 .
147
151
*/
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>> {
149
153
// (inst1, instr2) -> edge id --- edge represents as a pair of instructions, which are connected by this edge
150
154
val allCoveredEdges = mutableMapOf<Pair <Long , Long >, Int > ()
151
155
val thrownExceptions = mutableMapOf<String , Long >()
152
156
val mapping = mutableMapOf<Int , List <Int >>()
157
+ val executionToPriorityMapping = mutableMapOf<Int , Int >()
153
158
154
159
155
160
executions.forEachIndexed { idx, execution ->
@@ -169,11 +174,12 @@ private fun buildMapping(executions: List<UtExecution>): Map<Int, List<Int>> {
169
174
edges + = allCoveredEdges[instructions[i] to instructions[i + 1 ]]!!
170
175
}
171
176
mapping[idx] = edges
177
+ executionToPriorityMapping[idx] = execution.getExecutionPriority()
172
178
}
173
179
}
174
180
}
175
181
176
- return mapping
182
+ return Pair ( mapping, executionToPriorityMapping)
177
183
}
178
184
179
185
/* *
@@ -264,4 +270,15 @@ private fun addExtraIfLastInstructionIsException(
264
270
* Takes an exception name, a class name, a method signature and a line number from exception.
265
271
*/
266
272
private 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