Skip to content

Add Enabled Summaries Generation to the UI Settings #1162

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 6 commits into from
Oct 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ object UtSettings : AbstractSettings(
var useCustomJavaDocTags by getBooleanProperty(true)

/**
* Enable the machine learning module to generate summaries for methods under test.
* Enable the Summarization module to generate summaries for methods under test.
* True by default.
*
* Note: if it is false, all the execution for a particular method will be stored at the same nameless region.
*/
var enableMachineLearningModule by getBooleanProperty(true)
var enableSummariesGeneration by getBooleanProperty(true)

/**
* Options below regulate which [NullPointerException] check should be performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ abstract class UtValueTestCaseChecker(
UtSettings.saveRemainingStatesForConcreteExecution = false
UtSettings.useFuzzing = false
UtSettings.useCustomJavaDocTags = false
UtSettings.enableSummariesGeneration = true
}

// checks paramsBefore and result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import mu.KotlinLogging
import org.jetbrains.kotlin.idea.util.module
import org.utbot.framework.UtSettings
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.plugin.api.util.withStaticsSubstitutionRequired
import org.utbot.framework.plugin.services.JdkInfoService
Expand Down Expand Up @@ -192,6 +191,8 @@ object UtTestsDialogProcessor {
UtSettings.useCustomJavaDocTags =
model.commentStyle == JavaDocCommentStyle.CUSTOM_JAVADOC_TAGS

UtSettings.enableSummariesGeneration = model.enableSummariesGeneration

val searchDirectory = ReadAction
.nonBlocking<Path> {
project.basePath?.let { Paths.get(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data class GenerateTestsModel(
srcClasses.map { it.packageName }.distinct().size != 1
}
var runGeneratedTestsWithCoverage : Boolean = false
var enableSummariesGeneration : Boolean = true

val jdkVersion: JavaSdkVersion?
get() = try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
var classesToMockAlways: Array<String> = Mocker.defaultSuperClassesToMockAlwaysNames.toTypedArray(),
var fuzzingValue: Double = 0.05,
var runGeneratedTestsWithCoverage: Boolean = false,
var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem
var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem,
var enableSummariesGeneration: Boolean = true
) {
constructor(model: GenerateTestsModel) : this(
codegenLanguage = model.codegenLanguage,
Expand All @@ -70,7 +71,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(),
fuzzingValue = model.fuzzingValue,
runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage,
commentStyle = model.commentStyle
commentStyle = model.commentStyle,
enableSummariesGeneration = model.enableSummariesGeneration
)

override fun equals(other: Any?): Boolean {
Expand All @@ -92,6 +94,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
if (!classesToMockAlways.contentEquals(other.classesToMockAlways)) return false
if (fuzzingValue != other.fuzzingValue) return false
if (runGeneratedTestsWithCoverage != other.runGeneratedTestsWithCoverage) return false
if (commentStyle != other.commentStyle) return false
if (enableSummariesGeneration != other.enableSummariesGeneration) return false

return true
}
Expand All @@ -109,6 +113,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
result = 31 * result + classesToMockAlways.contentHashCode()
result = 31 * result + fuzzingValue.hashCode()
result = 31 * result + if (runGeneratedTestsWithCoverage) 1 else 0
result = 31 * result + if (enableSummariesGeneration) 1 else 0

return result
}
Expand Down Expand Up @@ -149,6 +154,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
}
var runGeneratedTestsWithCoverage = state.runGeneratedTestsWithCoverage

var enableSummariesGeneration = state.enableSummariesGeneration

fun setClassesToMockAlways(classesToMockAlways: List<String>) {
state.classesToMockAlways = classesToMockAlways.distinct().toTypedArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SettingsWindow(val project: Project) {
// TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement
private val excludeTable = MockAlwaysClassesTable(project)
private lateinit var forceMockCheckBox: JCheckBox
private lateinit var enableSummarizationGenerationCheckBox: JCheckBox

val panel: JPanel = panel {
val valuesComboBox: LayoutBuilder.(KClass<*>, Array<*>) -> Unit = { loader, values ->
Expand Down Expand Up @@ -98,6 +99,22 @@ class SettingsWindow(val project: Project) {
valuesComboBox(loader, values)
}

row {
cell {
enableSummarizationGenerationCheckBox = checkBox("Enable Summaries Generation")
.onApply {
settings.state.enableSummariesGeneration = enableSummarizationGenerationCheckBox.isSelected
}
.onReset {
enableSummarizationGenerationCheckBox.isSelected = settings.state.enableSummariesGeneration
}
.onIsModified {
enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration
}
.component
}
}

row {
cell {
forceMockCheckBox = checkBox("Force mocking static methods")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
model.chosenClassesToMockAlways = chosenClassesToMockAlways()
model.fuzzingValue = fuzzingValue
model.commentStyle = javaDocCommentStyle
model.enableSummariesGeneration = state.enableSummariesGeneration
UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fun setOptions() {
UtSettings.useFuzzing = true
UtSettings.classfilesCanChange = false
UtSettings.useAssembleModelGenerator = false
UtSettings.enableMachineLearningModule = false
UtSettings.enableSummariesGeneration = false
UtSettings.preferredCexOption = false
UtSettings.warmupConcreteExecution = true
UtSettings.testMinimizationStrategyType = TestSelectionStrategyType.COVERAGE_STRATEGY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import soot.SootMethod
private val logger = KotlinLogging.logger {}

fun UtMethodTestSet.summarize(sourceFile: File?, searchDirectory: Path = Paths.get("")): UtMethodTestSet {
if (!UtSettings.enableMachineLearningModule) return this
if (!UtSettings.enableSummariesGeneration) return this

return try {
makeDiverseExecutions(this)
Expand Down