Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Split settings and move out
  • Loading branch information
amandelpie committed Nov 30, 2022
commit ec66af1a7ba32048fd0a695895eb46d7a3e4abbd
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ object UtSettings : AbstractSettings(
var testName by getBooleanProperty(true)
var testDisplayName by getBooleanProperty(true)

/**
* Generate summaries using plugin's custom JavaDoc tags.
*/
var useCustomJavaDocTags by getBooleanProperty(true)

/**
* Enable the Summarization module to generate summaries for methods under test.
* True by default.
Expand All @@ -145,6 +140,36 @@ object UtSettings : AbstractSettings(
*/
var enableSummariesGeneration by getBooleanProperty(true)

/**
* If True test comments will be generated.
*/
var enableJavaDocGeneration = true

/**
* If True cluster comments will be generated.
*/
var enableClusterCommentsGeneration = true

/**
* If True names for tests will be generated.
*/
var enableTestNamesGeneration = true

/**
* If True display names for tests will be generated.
*/
var enableDisplayNameGeneration = true

/**
* If True display name in from -> to style will be generated.
*/
var useDisplayNameArrowStyle = true

/**
* Generate summaries using plugin's custom JavaDoc tags.
*/
var useCustomJavaDocTags by getBooleanProperty(true)

/**
* Options below regulate which [NullPointerException] check should be performed.
*
Expand All @@ -169,7 +194,6 @@ object UtSettings : AbstractSettings(
*/
var substituteStaticsWithSymbolicVariable by getBooleanProperty(true)


/**
* Use concrete execution.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,25 @@
package org.utbot.summary

object UtSummarySettings {
/**
* If True test comments will be generated.
*/
var GENERATE_COMMENTS = true

/**
* If True cluster comments will be generated.
*/
var GENERATE_CLUSTER_COMMENTS = true

/**
* If True names for tests will be generated.
*/
var GENERATE_NAMES = true

/**
* If True display names for tests will be generated.
*/
var GENERATE_DISPLAY_NAMES = true

/**
* If True display name in from -> to style will be generated.
*/
var GENERATE_DISPLAYNAME_FROM_TO_STYLE = true

/**
* If True mutation descriptions for tests will be generated
* TODO: implement
*/
var GENERATE_MUTATION_DESCRIPTIONS = true

object DBSCANClusteringConstants {
/**
* Sets minimum number of successful execution
* for applying the clustering algorithm.
*/
const val MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING: Int = 4
internal const val MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING: Int = 4

/**
* DBSCAN hyperparameter.
*
* Sets minimum number of executions to form a cluster.
*/
var MIN_EXEC_DBSCAN: Int = 2
internal const val MIN_EXEC_DBSCAN: Int = 2

/**
* DBSCAN hyperparameter.
*
* Sets radius of search for algorithm.
*/
var RADIUS_DBSCAN: Float = 5.0f
internal const val RADIUS_DBSCAN: Float = 5.0f
}

object SummarySentenceConstants {
Expand Down
29 changes: 15 additions & 14 deletions utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import org.utbot.framework.plugin.api.UtExecutionCluster
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
import org.utbot.summary.UtSummarySettings.GENERATE_CLUSTER_COMMENTS
import org.utbot.summary.UtSummarySettings.GENERATE_COMMENTS
import org.utbot.summary.UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE
import org.utbot.summary.UtSummarySettings.GENERATE_DISPLAY_NAMES
import org.utbot.summary.UtSummarySettings.GENERATE_NAMES
import org.utbot.summary.analysis.ExecutionStructureAnalysis
import org.utbot.summary.ast.JimpleToASTMap
import org.utbot.summary.ast.SourceCodeParser
Expand All @@ -23,6 +18,12 @@ import java.io.File
import java.nio.file.Path
import java.nio.file.Paths
import mu.KotlinLogging
import org.utbot.framework.UtSettings.enableClusterCommentsGeneration
import org.utbot.framework.UtSettings.enableJavaDocGeneration
import org.utbot.framework.UtSettings.useDisplayNameArrowStyle
import org.utbot.framework.UtSettings.enableDisplayNameGeneration
import org.utbot.framework.UtSettings.enableTestNamesGeneration
import org.utbot.framework.UtSettings.useCustomJavaDocTags
import org.utbot.framework.plugin.api.util.jClass
import org.utbot.fuzzer.FuzzedMethodDescription
import org.utbot.fuzzer.FuzzedValue
Expand Down Expand Up @@ -86,7 +87,7 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
executionClusters += generateSummariesForTestsProducedByFuzzer(testSet)
executionClusters += generateSummariesForTestsWithEmptyPathsProducedBySymbolicExecutor(testSet)

return if (GENERATE_CLUSTER_COMMENTS && executionClusters.size > 0)
return if (enableClusterCommentsGeneration && executionClusters.size > 0)
executionClusters
else
listOf(UtExecutionCluster(UtClusterInfo(), testSet.executions))
Expand All @@ -110,9 +111,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
jimpleBodyAnalysis.traceStructuralAnalysis(jimpleBody, clusteredTags, methodUnderTest, invokeDescriptions)
val numberOfSuccessfulClusters = clusteredTags.filter { it.isSuccessful }.size
for (clusterTraceTags in clusteredTags) {
val clusterHeader = clusterTraceTags.clusterHeader.takeIf { GENERATE_CLUSTER_COMMENTS }
val clusterHeader = clusterTraceTags.clusterHeader.takeIf { enableClusterCommentsGeneration }
val clusterContent = if (
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful // add only for successful executions
enableClusterCommentsGeneration && 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
) {
Expand All @@ -130,8 +131,8 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
}

for (traceTags in clusterTraceTags.traceTags) {
if (GENERATE_COMMENTS) {
if (UtSettings.useCustomJavaDocTags) {
if (enableJavaDocGeneration) {
if (useCustomJavaDocTags) {
traceTags.execution.summary =
CustomJavaDocCommentBuilder(traceTags, sootToAST).buildDocStatements(methodUnderTest)
} else {
Expand All @@ -140,22 +141,22 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
}
}

if (GENERATE_DISPLAY_NAMES || GENERATE_NAMES) {
if (enableDisplayNameGeneration || enableTestNamesGeneration) {
val simpleNameBuilder = SimpleNameBuilder(traceTags, sootToAST, methodUnderTest)
val name = simpleNameBuilder.name
val displayName = simpleNameBuilder.displayName
val fromToName = simpleNameBuilder.fromToName
val nameIndex = namesCounter.getOrPut(name) { 0 }
namesCounter[name] = nameIndex + 1
updatedExecutions += traceTags.execution
if (GENERATE_DISPLAY_NAMES) {
if (!GENERATE_DISPLAYNAME_FROM_TO_STYLE) {
if (enableDisplayNameGeneration) {
if (!useDisplayNameArrowStyle) {
traceTags.execution.displayName = displayName
} else {
traceTags.execution.displayName = fromToName
}
}
if (GENERATE_NAMES) {
if (enableTestNamesGeneration) {
traceTags.execution.testMethodName = name
if (nameIndex != 0) traceTags.execution.testMethodName += "_$nameIndex"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.utbot.framework.plugin.api.UtTimeoutException
import org.utbot.framework.plugin.api.util.humanReadableName
import org.utbot.framework.plugin.api.util.isCheckedException
import org.utbot.fuzzer.UtFuzzedExecution
import org.utbot.summary.UtSummarySettings.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING
import org.utbot.summary.DBSCANClusteringConstants.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING
import org.utbot.summary.clustering.MatrixUniqueness
import org.utbot.summary.clustering.SplitSteps
import org.utbot.summary.tag.TraceTag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.utbot.summary.clustering

import org.utbot.framework.plugin.api.Step
import org.utbot.framework.plugin.api.UtSymbolicExecution
import org.utbot.summary.UtSummarySettings
import org.utbot.summary.DBSCANClusteringConstants
import org.utbot.summary.clustering.dbscan.DBSCANTrainer
import org.utbot.summary.clustering.dbscan.neighbor.LinearRangeQuery

Expand Down Expand Up @@ -81,8 +81,8 @@ class MatrixUniqueness(executions: List<UtSymbolicExecution>) {
/** Returns map: cluster identifier, List<executions>. */
fun dbscanClusterExecutions(
methodExecutions: List<UtSymbolicExecution>,
minPts: Int = UtSummarySettings.MIN_EXEC_DBSCAN,
radius: Float = UtSummarySettings.RADIUS_DBSCAN
minPts: Int = DBSCANClusteringConstants.MIN_EXEC_DBSCAN,
radius: Float = DBSCANClusteringConstants.RADIUS_DBSCAN
): Map<Int, List<UtSymbolicExecution>> {

val executionPaths = methodExecutions.map { it.path.asIterable() }.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.utbot.fuzzer.FuzzedMethodDescription
import org.utbot.fuzzer.FuzzedValue
import org.utbot.summary.SummarySentenceConstants.FROM_TO_NAMES_COLON
import org.utbot.summary.SummarySentenceConstants.FROM_TO_NAMES_TRANSITION
import org.utbot.summary.UtSummarySettings
import org.utbot.summary.comment.classic.fuzzer.SimpleCommentForTestProducedByFuzzerBuilder
import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzerBuilder
import java.util.*
Expand Down Expand Up @@ -35,9 +34,9 @@ class ModelBasedNameSuggester(

return sequenceOf(
TestSuggestedInfo(
testName = if (UtSummarySettings.GENERATE_NAMES) createTestName(description, values, result) else null,
displayName = if (UtSummarySettings.GENERATE_DISPLAY_NAMES) createDisplayName(description, values, result) else null,
javaDoc = if (UtSummarySettings.GENERATE_COMMENTS) createJavaDoc(description, values, result) else null
testName = if (UtSettings.enableTestNamesGeneration) createTestName(description, values, result) else null,
displayName = if (UtSettings.enableDisplayNameGeneration) createDisplayName(description, values, result) else null,
javaDoc = if (UtSettings.enableJavaDocGeneration) createJavaDoc(description, values, result) else null
)
)
}
Expand Down Expand Up @@ -108,14 +107,14 @@ class ModelBasedNameSuggester(
* 2. **Name without appropriate information**: `arg_0 = 0 and others -> return 0`
*
* NOTE: The ```:``` symbol is used as a separator instead
* of ```->``` if the [UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE] is false.
* of ```->``` if the [UtSettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE] is false.
*/
private fun createDisplayName(
description: FuzzedMethodDescription,
values: List<FuzzedValue>,
result: UtExecutionResult?
): String {
val displayNameSeparator = if (UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE) FROM_TO_NAMES_TRANSITION else FROM_TO_NAMES_COLON
val displayNameSeparator = if (UtSettings.useDisplayNameArrowStyle) FROM_TO_NAMES_TRANSITION else FROM_TO_NAMES_COLON

val summaries = values.asSequence()
.mapIndexed { index, value ->
Expand Down Expand Up @@ -183,5 +182,4 @@ class ModelBasedNameSuggester(
.filter { it.isUpperCase() }
.joinToString(separator = "")
}

}