Skip to content

Commit

Permalink
Disabled clustering of tests generated by Fuzzer (#431)
Browse files Browse the repository at this point in the history
* Disabled clustering of tests generated by Fuzzer

* Refactored the multiple calls
  • Loading branch information
amandelpie authored Jul 6, 2022
1 parent c09568f commit 9a3acb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
39 changes: 28 additions & 11 deletions utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,32 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
}
return listOf(UtExecutionCluster(UtClusterInfo(), testCase.executions))
}

// init
val sootToAST = sootToAST(testCase)
val jimpleBody = testCase.jimpleBody
val updatedExecutions = mutableListOf<UtExecution>()
val clustersToReturn = mutableListOf<UtExecutionCluster>()

// TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428
val executionsProducedByFuzzer = getExecutionsWithEmptyPath(testCase)

if (executionsProducedByFuzzer.isNotEmpty()) {
executionsProducedByFuzzer.forEach {
logger.info {
"The path for test ${it.testMethodName} " +
"for method ${testCase.method.clazz.qualifiedName} is empty and summaries could not be generated."
}
}

clustersToReturn.add(
UtExecutionCluster(
UtClusterInfo(),
executionsProducedByFuzzer
)
)
}

// analyze
if (jimpleBody != null && sootToAST != null) {
val methodUnderTest = jimpleBody.method
Expand All @@ -83,9 +103,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
for (clusterTraceTags in clusteredTags) {
val clusterHeader = clusterTraceTags.summary.takeIf { GENERATE_CLUSTER_COMMENTS }
val clusterContent = if (
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful //add only for successful executions
&& numberOfSuccessfulClusters > 1 //there is more than one successful execution
&& clusterTraceTags.traceTags.size > 1 //add if there is more than 1 execution
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful // add only for successful executions
&& numberOfSuccessfulClusters > 1 // there is more than one successful execution
&& clusterTraceTags.traceTags.size > 1 // add if there is more than 1 execution
) {
SimpleClusterCommentBuilder(clusterTraceTags.commonStepsTraceTag, sootToAST)
.buildString(methodUnderTest)
Expand Down Expand Up @@ -113,20 +133,14 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
val nameIndex = namesCounter.getOrPut(name) { 0 }
namesCounter[name] = nameIndex + 1
updatedExecutions += traceTags.execution
if (GENERATE_DISPLAY_NAMES
// todo extract these options into more suitable place (https://github.com/UnitTestBot/UTBotJava/issues/359)
// do not rewrite display name if already set
&& traceTags.execution.displayName.isNullOrBlank()) {
if (GENERATE_DISPLAY_NAMES) {
if (!GENERATE_DISPLAYNAME_FROM_TO_STYLE) {
traceTags.execution.displayName = displayName
} else {
traceTags.execution.displayName = fromToName
}
}
if (GENERATE_NAMES
// todo extract these options into more suitable place (https://github.com/UnitTestBot/UTBotJava/issues/359)
// do not rewrite display name if already set
&& traceTags.execution.testMethodName.isNullOrBlank()) {
if (GENERATE_NAMES) {
traceTags.execution.testMethodName = name
if (nameIndex != 0) traceTags.execution.testMethodName += "_$nameIndex"
}
Expand All @@ -150,6 +164,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
return listOf(UtExecutionCluster(UtClusterInfo(), testCase.executions))
}

private fun getExecutionsWithEmptyPath(testCase: UtTestCase) =
testCase.executions.filter { it.path.isEmpty() }

/*
* asts of invokes also included
* */
Expand Down
11 changes: 5 additions & 6 deletions utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class TagGenerator {
mUniqueness.splitSteps()
}

//intersections of steps ONLY in successful clusters
// intersections of steps ONLY in successful clusters
var stepsIntersections = listOf<Step>()

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

//for every cluster and step add TraceTagCluster
// for every cluster and step add TraceTagCluster
clusteredExecutions.zip(listOfSplitSteps) { cluster, splitSteps ->
val commonStepsInCluster =
if (stepsIntersections.isNotEmpty() && numberOfSuccessfulClusters > 1) {
Expand All @@ -70,11 +70,10 @@ class TagGenerator {
)
)
}
}//clusteredExecutions should not be empty!
} // clusteredExecutions should not be empty!

return traceTagClusters
}

}

/**
Expand All @@ -95,7 +94,7 @@ private fun generateExecutionTags(executions: List<UtExecution>, splitSteps: Spl
* @return clustered executions
*/
private fun toClusterExecutions(testCase: UtTestCase): List<ExecutionCluster> {
val methodExecutions = testCase.executions
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
val clusters = mutableListOf<ExecutionCluster>()
val commentPostfix = "for method ${testCase.method.displayName}"

Expand Down

0 comments on commit 9a3acb6

Please sign in to comment.