Skip to content

Commit 816e736

Browse files
committed
Added overridden classes in the visualization
1 parent 80ea481 commit 816e736

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/InterProceduralUnitGraph.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
4040

4141
val stmts: MutableSet<Stmt> = graph.stmts.toMutableSet()
4242
val registeredEdges: MutableSet<Edge> = graph.edges.toMutableSet()
43+
// this field is required for visualization
44+
val allEdges: MutableSet<Edge> = graph.edges.toMutableSet()
4345
/**
4446
* Used in [org.utbot.engine.selectors.nurs.InheritorsSelector] for a fast search of Virtual invoke successors.
4547
*/
@@ -54,6 +56,7 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
5456
private val edgeToGraph: MutableMap<Edge, ExceptionalUnitGraph> = graph.edges.associateWithTo(mutableMapOf()) { graph }
5557

5658
private val registeredEdgesCount: MutableMap<Stmt, Int> = graph.outgoingEdgesCount
59+
private val allEdgesCount: MutableMap<Stmt, Int> = graph.outgoingEdgesCount
5760
private val outgoingEdgesCount: MutableMap<Stmt, Int> = graph.outgoingEdgesCount
5861

5962
fun method(stmt: Stmt): SootMethod = stmtToGraph[stmt]?.body?.method ?: error("$stmt not in graph.")
@@ -125,6 +128,12 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
125128
outgoingEdgesCount += graph.outgoingEdgesCount
126129
stmts += joinedStmts
127130

131+
allEdges += graph.edges
132+
allEdgesCount += graph.outgoingEdgesCount
133+
allEdgesCount.computeIfPresent(stmt) { _, value ->
134+
value + 1
135+
}
136+
128137
if (registerEdges) {
129138
registeredMethods += method
130139
registeredEdgesCount += graph.outgoingEdgesCount
@@ -144,6 +153,7 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
144153
}
145154

146155
registeredEdges += invokeEdge
156+
allEdges += invokeEdge
147157

148158
outgoingEdgesCount.computeIfPresent(stmt) { _, value ->
149159
value + 1
@@ -168,11 +178,8 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
168178

169179
when (edge) {
170180
in implicitEdges -> coveredImplicitEdges += edge
171-
!in registeredEdges -> {
181+
!in registeredEdges, !in coveredEdges-> {
172182
coveredOutgoingEdges.putIfAbsent(edge.src, 0)
173-
coveredEdges += edge
174-
}
175-
!in coveredEdges -> {
176183
coveredOutgoingEdges.compute(edge.src) { _, value -> (value ?: 0) + 1 }
177184
coveredEdges += edge
178185
}
@@ -280,7 +287,10 @@ class InterProceduralUnitGraph(graph: ExceptionalUnitGraph) {
280287
* Statement is covered if all the outgoing edges are covered.
281288
*/
282289
fun isCovered(stmt: Stmt) =
283-
stmt !in registeredEdgesCount || stmt in coveredOutgoingEdges && coveredOutgoingEdges[stmt]!! >= registeredEdgesCount[stmt]!!
290+
stmt !in registeredEdgesCount || isCoveredIgnoringRegistration(stmt)
291+
292+
fun isCoveredIgnoringRegistration(stmt: Stmt) =
293+
stmt in coveredOutgoingEdges && coveredOutgoingEdges[stmt]!! >= allEdgesCount[stmt]!!
284294

285295
/**
286296
* Edge is covered if we visited it in successfully completed execution at least once

utbot-framework/src/main/kotlin/org/utbot/engine/selectors/strategies/GraphViz.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import java.nio.file.Files
1515
import java.nio.file.Paths
1616
import mu.KotlinLogging
1717
import org.apache.commons.io.FileUtils
18+
import org.utbot.engine.isOverridden
1819
import soot.jimple.Stmt
1920
import soot.toolkits.graph.ExceptionalUnitGraph
2021

@@ -81,8 +82,8 @@ class GraphViz(
8182
uncompletedStack.last().addDotEdge(it)
8283
fullStack.last().addDotEdge(it)
8384
}
84-
(graph.registeredEdges + graph.implicitEdges).forEach {
85-
if (!libraryGraphs.contains(stmtToSubgraph[it.src]) && !libraryGraphs.contains(stmtToSubgraph[it.src])) {
85+
(graph.allEdges + graph.implicitEdges).forEach {
86+
if (!libraryGraphs.contains(stmtToSubgraph[it.src]) && !libraryGraphs.contains(stmtToSubgraph[it.dst])) {
8687
dotGlobalGraph.addDotEdge(it)
8788
}
8889
}
@@ -152,7 +153,8 @@ class GraphViz(
152153
}
153154

154155
override fun onJoin(stmt: Stmt, graph: ExceptionalUnitGraph, shouldRegister: Boolean) {
155-
if (!shouldRegister) {
156+
val declaringClass = graph.body?.method?.declaringClass
157+
if (declaringClass?.isLibraryClass == true && !declaringClass.isOverridden) {
156158
libraryGraphs.add(graph.body?.method?.declaringClass?.shortName + "." + graph.body?.method?.name)
157159
}
158160
update()
@@ -175,7 +177,7 @@ class GraphViz(
175177
}
176178
}
177179

178-
for (edge in graph.registeredEdges + graph.implicitEdges) {
180+
for (edge in graph.allEdges + graph.implicitEdges) {
179181
subgraphEdges[stmtToSubgraph[edge.src]!!]!!.add(edge)
180182
}
181183
}
@@ -185,7 +187,7 @@ class GraphViz(
185187
graph.dotNode(executionState.stmt)?.isLast = true
186188

187189
// Node property: covered
188-
globalGraph.stmts.forEach { graph.dotNode(it)?.covered = globalGraph.isCovered(it) }
190+
globalGraph.stmts.forEach { graph.dotNode(it)?.covered = globalGraph.isCoveredIgnoringRegistration(it) }
189191

190192
// Node property: In queue
191193
pathSelector.queue().forEach { graph.dotNode(it.first.stmt)?.inQueue = true }
@@ -194,7 +196,7 @@ class GraphViz(
194196
if (!pathSelector.isEmpty()) graph.dotNode(pathSelector.peek()!!.stmt)?.headQueue = true
195197

196198
// Edge property: covered
197-
(globalGraph.registeredEdges + globalGraph.implicitEdges).forEach {
199+
(globalGraph.allEdges + globalGraph.implicitEdges).forEach {
198200
graph.dotEdge(it)?.isCovered = globalGraph.isCovered(it)
199201
}
200202

0 commit comments

Comments
 (0)