Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add sarif results minimization (#490)
  • Loading branch information
mmvpm committed Jul 13, 2022
commit 8e396f0db3226f7dafe08352c2140dd43995935d
12 changes: 11 additions & 1 deletion utbot-framework/src/main/kotlin/org/utbot/sarif/DataClasses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ data class SarifResult(
val locations: List<SarifPhysicalLocationWrapper> = listOf(),
val relatedLocations: List<SarifRelatedPhysicalLocationWrapper> = listOf(),
val codeFlows: List<SarifCodeFlow> = listOf()
)
) {
/**
* Returns the total number of locations in all [codeFlows].
*/
fun totalCodeFlowLocations() =
codeFlows.sumBy { codeFlow ->
codeFlow.threadFlows.sumBy { threadFlow ->
threadFlow.locations.size
}
}
}

/**
* The severity of the result. "Error" for detected unchecked exceptions.
Expand Down
16 changes: 15 additions & 1 deletion utbot-framework/src/main/kotlin/org/utbot/sarif/SarifReport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,25 @@ class SarifReport(
return Sarif.fromRun(
SarifRun(
SarifTool.fromRules(sarifRules.toList()),
sarifResults
minimizeResults(sarifResults)
)
)
}

/**
* Minimizes detected errors and removes duplicates.
* Between two [SarifResult]s with the same `ruleId` and `locations`
* it chooses the one with the shorter length of the execution trace.
*/
private fun minimizeResults(sarifResults: List<SarifResult>): List<SarifResult> =
sarifResults.groupBy { sarifResult ->
Pair(sarifResult.ruleId, sarifResult.locations)
}.map { (_, sarifResultsGroup) ->
sarifResultsGroup.minByOrNull { sarifResult ->
sarifResult.totalCodeFlowLocations()
}!!
}

private fun processUncheckedException(
method: UtMethod<*>,
utExecution: UtExecution,
Expand Down