Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
chosenClassesToMockAlways,
generationTimeout
).map {
if (sourceCodeFile != null) it.summarize(sourceCodeFile.toFile(), searchDirectory) else it
if (sourceCodeFile != null) it.summarize(searchDirectory, sourceCodeFile.toFile()) else it
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class GenerateTestsAndSarifReportFacade(
sarifProperties.classesToMockAlways,
sarifProperties.generationTimeout
).map {
it.summarize(targetClass.sourceCodeFile, workingDirectory)
it.summarize(workingDirectory, targetClass.sourceCodeFile)
}

private fun generateTestCode(targetClass: TargetClassWrapper, testSets: List<UtMethodTestSet>): String =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch
fuzzingValue = params.fuzzingValue
})
.apply { logger.info("generation ended, starting summarization, result size: ${this.size}") }
.map { it.summarize(Paths.get(params.searchDirectory)) }
.map { it.summarize(Paths.get(params.searchDirectory), sourceFile = null) }
.apply { logger.info("summarization ended") }
.filterNot { it.executions.isEmpty() && it.errors.isEmpty() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ fun runGeneration(

val testSets = testsByMethod.map { (method, executions) ->
UtMethodTestSet(method, minimizeExecutions(executions), jimpleBody(method))
.summarize(cut.classfileDir.toPath())
.summarize(cut.classfileDir.toPath(), sourceFile = null)
}

logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package examples
import org.junit.jupiter.api.*
import org.utbot.common.WorkaroundReason
import org.utbot.common.workaround
import org.utbot.framework.SummariesGenerationType
import org.utbot.framework.UtSettings.checkNpeInNestedMethods
import org.utbot.framework.UtSettings.checkNpeInNestedNotPrivateMethods
import org.utbot.framework.UtSettings.checkSolverTimeoutMillis
import org.utbot.framework.UtSettings.summaryGenerationType
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.util.UtContext
import org.utbot.framework.plugin.api.util.executableId
Expand Down Expand Up @@ -58,7 +60,7 @@ open class SummaryTestCaseGeneratorTest(
checkNpeInNestedNotPrivateMethods = true
}
val testSet = executionsModel(method.executableId, mockStrategy)
val testSetWithSummarization = testSet.summarize(searchDirectory)
val testSetWithSummarization = testSet.summarize(searchDirectory, sourceFile = null)

testSetWithSummarization.executions.checkMatchersWithTextSummary(summaryKeys)
testSetWithSummarization.executions.checkMatchersWithMethodNames(methodNames)
Expand Down
35 changes: 17 additions & 18 deletions utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder
import org.utbot.summary.name.SimpleNameBuilder
import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import mu.KotlinLogging
import org.utbot.framework.SummariesGenerationType
import org.utbot.framework.SummariesGenerationType.*
import org.utbot.framework.UtSettings.enableClusterCommentsGeneration
import org.utbot.framework.UtSettings.enableJavaDocGeneration
import org.utbot.framework.UtSettings.useDisplayNameArrowStyle
Expand All @@ -37,21 +36,28 @@ import soot.SootMethod

private val logger = KotlinLogging.logger {}

fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("")): UtMethodTestSet {
if (summaryGenerationType == SummariesGenerationType.NONE) return this
fun UtMethodTestSet.summarize(searchDirectory: Path, sourceFile: File?): UtMethodTestSet {
if (summaryGenerationType == NONE) return this

val sourceFileToAnalyze = sourceFile
?: when (summaryGenerationType) {
FULL -> Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory)
LIGHT,
NONE -> null
}

return try {
makeDiverseExecutions(this)

// HACK: we avoid calling [invokeDescriptions] method to save time, it is useless in Contest
val invokeDescriptions = when (summaryGenerationType) {
SummariesGenerationType.FULL -> invokeDescriptions(this, searchDirectory)
SummariesGenerationType.LIGHT,
SummariesGenerationType.NONE -> emptyList()
FULL -> invokeDescriptions(this, searchDirectory)
LIGHT,
NONE -> emptyList()
}

// every cluster has summary and list of executions
val executionClusters = Summarization(sourceFile, invokeDescriptions).fillSummaries(this)
val executionClusters = Summarization(sourceFileToAnalyze, invokeDescriptions).fillSummaries(this)
val updatedExecutions = executionClusters.flatMap { it.executions }
var pos = 0
val clustersInfo = executionClusters.map {
Expand All @@ -70,13 +76,6 @@ fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.g
}
}

fun UtMethodTestSet.summarize(searchDirectory: Path): UtMethodTestSet =
this.summarize(
Instrumenter.adapter.computeSourceFileByClass(this.method.classId.jClass, searchDirectory),
searchDirectory
)


class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDescription>) {
private val tagGenerator = TagGenerator()
private val jimpleBodyAnalysis = ExecutionStructureAnalysis()
Expand All @@ -93,16 +92,16 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
val executionClusters = mutableListOf<UtExecutionCluster>()

when (summaryGenerationType) {
SummariesGenerationType.FULL -> {
FULL -> {
executionClusters += generateSummariesForTestsWithNonEmptyPathsProducedBySymbolicExecutor(testSet)
executionClusters += generateFuzzerBasedSummariesForTests(testSet)
executionClusters += generateSummariesForTestsWithEmptyPathsProducedBySymbolicExecutor(testSet)
}
SummariesGenerationType.LIGHT -> {
LIGHT -> {
executionClusters += generateFuzzerBasedSummariesForTests(testSet, MethodDescriptionSource.SYMBOLIC)
executionClusters += generateFuzzerBasedSummariesForTests(testSet)
}
SummariesGenerationType.NONE -> error("We must not fill summaries if SummariesGenerationType is NONE")
NONE -> error("We must not fill summaries if SummariesGenerationType is NONE")
}

return if (enableClusterCommentsGeneration && executionClusters.size > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2452,7 +2452,7 @@ abstract class UtValueTestCaseChecker(
} else {
walk(executableId, mockStrategy, additionalDependenciesClassPath)
}
testSet.summarize(searchDirectory)
testSet.summarize(searchDirectory, sourceFile = null)
val valueTestCase = testSet.toValueTestCase()

assertTrue(testSet.errors.isEmpty()) {
Expand Down