Skip to content

Commit 9a3acb6

Browse files
authored
Disabled clustering of tests generated by Fuzzer (#431)
* Disabled clustering of tests generated by Fuzzer * Refactored the multiple calls
1 parent c09568f commit 9a3acb6

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt

+28-11
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,32 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
6868
}
6969
return listOf(UtExecutionCluster(UtClusterInfo(), testCase.executions))
7070
}
71+
7172
// init
7273
val sootToAST = sootToAST(testCase)
7374
val jimpleBody = testCase.jimpleBody
7475
val updatedExecutions = mutableListOf<UtExecution>()
7576
val clustersToReturn = mutableListOf<UtExecutionCluster>()
7677

78+
// TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428
79+
val executionsProducedByFuzzer = getExecutionsWithEmptyPath(testCase)
80+
81+
if (executionsProducedByFuzzer.isNotEmpty()) {
82+
executionsProducedByFuzzer.forEach {
83+
logger.info {
84+
"The path for test ${it.testMethodName} " +
85+
"for method ${testCase.method.clazz.qualifiedName} is empty and summaries could not be generated."
86+
}
87+
}
88+
89+
clustersToReturn.add(
90+
UtExecutionCluster(
91+
UtClusterInfo(),
92+
executionsProducedByFuzzer
93+
)
94+
)
95+
}
96+
7797
// analyze
7898
if (jimpleBody != null && sootToAST != null) {
7999
val methodUnderTest = jimpleBody.method
@@ -83,9 +103,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
83103
for (clusterTraceTags in clusteredTags) {
84104
val clusterHeader = clusterTraceTags.summary.takeIf { GENERATE_CLUSTER_COMMENTS }
85105
val clusterContent = if (
86-
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful //add only for successful executions
87-
&& numberOfSuccessfulClusters > 1 //there is more than one successful execution
88-
&& clusterTraceTags.traceTags.size > 1 //add if there is more than 1 execution
106+
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful // add only for successful executions
107+
&& numberOfSuccessfulClusters > 1 // there is more than one successful execution
108+
&& clusterTraceTags.traceTags.size > 1 // add if there is more than 1 execution
89109
) {
90110
SimpleClusterCommentBuilder(clusterTraceTags.commonStepsTraceTag, sootToAST)
91111
.buildString(methodUnderTest)
@@ -113,20 +133,14 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
113133
val nameIndex = namesCounter.getOrPut(name) { 0 }
114134
namesCounter[name] = nameIndex + 1
115135
updatedExecutions += traceTags.execution
116-
if (GENERATE_DISPLAY_NAMES
117-
// todo extract these options into more suitable place (https://github.com/UnitTestBot/UTBotJava/issues/359)
118-
// do not rewrite display name if already set
119-
&& traceTags.execution.displayName.isNullOrBlank()) {
136+
if (GENERATE_DISPLAY_NAMES) {
120137
if (!GENERATE_DISPLAYNAME_FROM_TO_STYLE) {
121138
traceTags.execution.displayName = displayName
122139
} else {
123140
traceTags.execution.displayName = fromToName
124141
}
125142
}
126-
if (GENERATE_NAMES
127-
// todo extract these options into more suitable place (https://github.com/UnitTestBot/UTBotJava/issues/359)
128-
// do not rewrite display name if already set
129-
&& traceTags.execution.testMethodName.isNullOrBlank()) {
143+
if (GENERATE_NAMES) {
130144
traceTags.execution.testMethodName = name
131145
if (nameIndex != 0) traceTags.execution.testMethodName += "_$nameIndex"
132146
}
@@ -150,6 +164,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
150164
return listOf(UtExecutionCluster(UtClusterInfo(), testCase.executions))
151165
}
152166

167+
private fun getExecutionsWithEmptyPath(testCase: UtTestCase) =
168+
testCase.executions.filter { it.path.isEmpty() }
169+
153170
/*
154171
* asts of invokes also included
155172
* */

utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class TagGenerator {
2929
mUniqueness.splitSteps()
3030
}
3131

32-
//intersections of steps ONLY in successful clusters
32+
// intersections of steps ONLY in successful clusters
3333
var stepsIntersections = listOf<Step>()
3434

35-
//we only want to find intersections if there is more than one successful execution
35+
// we only want to find intersections if there is more than one successful execution
3636
if (numberOfSuccessfulClusters > 1 && REMOVE_INTERSECTIONS) {
3737
val commonStepsInSuccessfulEx = listOfSplitSteps
3838
.filterIndexed { i, _ -> clusteredExecutions[i] is SuccessfulExecutionCluster } //search only in successful
@@ -46,7 +46,7 @@ class TagGenerator {
4646
}
4747
}
4848

49-
//for every cluster and step add TraceTagCluster
49+
// for every cluster and step add TraceTagCluster
5050
clusteredExecutions.zip(listOfSplitSteps) { cluster, splitSteps ->
5151
val commonStepsInCluster =
5252
if (stepsIntersections.isNotEmpty() && numberOfSuccessfulClusters > 1) {
@@ -70,11 +70,10 @@ class TagGenerator {
7070
)
7171
)
7272
}
73-
}//clusteredExecutions should not be empty!
73+
} // clusteredExecutions should not be empty!
7474

7575
return traceTagClusters
7676
}
77-
7877
}
7978

8079
/**
@@ -95,7 +94,7 @@ private fun generateExecutionTags(executions: List<UtExecution>, splitSteps: Spl
9594
* @return clustered executions
9695
*/
9796
private fun toClusterExecutions(testCase: UtTestCase): List<ExecutionCluster> {
98-
val methodExecutions = testCase.executions
97+
val methodExecutions = testCase.executions.filter { it.path.isNotEmpty() } // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428
9998
val clusters = mutableListOf<ExecutionCluster>()
10099
val commentPostfix = "for method ${testCase.method.displayName}"
101100

0 commit comments

Comments
 (0)