Skip to content

Enable smart fuzzer for UTBot by default for a plugin #66 #385

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 1 commit into from
Jul 4, 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 @@ -246,12 +246,17 @@ object UtSettings {
/**
* Set to true to start fuzzing if symbolic execution haven't return anything
*/
var useFuzzing: Boolean by getBooleanProperty(false)
var useFuzzing: Boolean by getBooleanProperty(true)

/**
* Set the total attempts to improve coverage by fuzzer.
*/
var fuzzingMaxAttemps: Int by getIntProperty(Int.MAX_VALUE)
var fuzzingMaxAttempts: Int by getIntProperty(Int.MAX_VALUE)

/**
* Fuzzer tries to generate and run tests during this time.
*/
var fuzzingTimeoutInMillis: Int by getIntProperty(3_000)

/**
* Generate tests that treat possible overflows in arithmetic operations as errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,13 @@ class UtBotSymbolicEngine(
}


//Simple fuzzing
fun fuzzing(modelProvider: (ModelProvider) -> ModelProvider = { it }) = flow {
/**
* Run fuzzing flow.
*
* @param until is used by fuzzer to cancel all tasks if the current time is over this value
* @param modelProvider provides model values for a method
*/
fun fuzzing(until: Long = Long.MAX_VALUE, modelProvider: (ModelProvider) -> ModelProvider = { it }) = flow {
val executableId = if (methodUnderTest.isConstructor) {
methodUnderTest.javaConstructor!!.executableId
} else {
Expand Down Expand Up @@ -618,8 +623,13 @@ class UtBotSymbolicEngine(
}
val modelProviderWithFallback = modelProvider(defaultModelProviders { nextDefaultModelId++ }).withFallback(fallbackModelProvider::toModel)
val coveredInstructionTracker = mutableSetOf<Instruction>()
var attempts = UtSettings.fuzzingMaxAttemps
var attempts = UtSettings.fuzzingMaxAttempts
fuzz(methodUnderTestDescription, modelProviderWithFallback).forEach { values ->
if (System.currentTimeMillis() >= until) {
logger.info { "Fuzzing overtime: $methodUnderTest" }
return@flow
}

val initialEnvironmentModels = EnvironmentModels(thisInstance, values.map { it.model }, mapOf())

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ object UtBotTestCaseGenerator : TestCaseGenerator {
private fun createDefaultFlow(engine: UtBotSymbolicEngine): Flow<UtResult> {
var flow = engine.traverse()
if (UtSettings.useFuzzing) {
flow = flowOf(flow, engine.fuzzing()).flattenConcat()
flow = flowOf(
engine.fuzzing(System.currentTimeMillis() + UtSettings.fuzzingTimeoutInMillis),
flow,
).flattenConcat()
}
return flow
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ abstract class AbstractTestCaseGeneratorTest(
UtSettings.substituteStaticsWithSymbolicVariable = true
UtSettings.useAssembleModelGenerator = true
UtSettings.saveRemainingStatesForConcreteExecution = false
UtSettings.useFuzzing = false
}

// checks paramsBefore and result
Expand Down
7 changes: 6 additions & 1 deletion utbot-intellij/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<Logger name="org.utbot.intellij" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Root level="info"/>
<Logger name="org.utbot" level="error">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>