From 3a48e4843cf67b6abf5be3affad5101bcd6e03a3 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Wed, 6 Jul 2022 11:57:38 +0300 Subject: [PATCH 1/2] Disabled clustering of tests generated by Fuzzer --- .../kotlin/org/utbot/summary/Summarization.kt | 36 +++++++++++++------ .../kotlin/org/utbot/summary/TagGenerator.kt | 11 +++--- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index dfc0547821..47138fd0ff 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -68,12 +68,32 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List() val clustersToReturn = mutableListOf() + // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428 + if (testCase.executions.any { it.path.isEmpty() }) { + testCase.executions.filter { it.path.isEmpty() }.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(), + testCase.executions.filter { it.path.isEmpty() } + ) + ) + } + // analyze if (jimpleBody != null && sootToAST != null) { val methodUnderTest = jimpleBody.method @@ -83,9 +103,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List 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) @@ -113,20 +133,14 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List() - //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 @@ -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) { @@ -70,11 +70,10 @@ class TagGenerator { ) ) } - }//clusteredExecutions should not be empty! + } // clusteredExecutions should not be empty! return traceTagClusters } - } /** @@ -95,7 +94,7 @@ private fun generateExecutionTags(executions: List, splitSteps: Spl * @return clustered executions */ private fun toClusterExecutions(testCase: UtTestCase): List { - 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() val commentPostfix = "for method ${testCase.method.displayName}" From bce94d99a3662802be1baacbc2225ac665eaabf3 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Wed, 6 Jul 2022 12:42:37 +0300 Subject: [PATCH 2/2] Refactored the multiple calls --- .../main/kotlin/org/utbot/summary/Summarization.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt index 47138fd0ff..fb473101e5 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt @@ -69,8 +69,6 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List() // TODO: Now it excludes tests generated by Fuzzer, handle it properly, related to the https://github.com/UnitTestBot/UTBotJava/issues/428 - if (testCase.executions.any { it.path.isEmpty() }) { - testCase.executions.filter { it.path.isEmpty() }.forEach { + 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." @@ -89,7 +89,7 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List