Skip to content

Disabled clustering of tests generated by Fuzzer #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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