Skip to content

Commit fc99784

Browse files
authored
Enable smart fuzzer for UTBot by default for a plugin #385
1 parent 2a2173a commit fc99784

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,17 @@ object UtSettings {
246246
/**
247247
* Set to true to start fuzzing if symbolic execution haven't return anything
248248
*/
249-
var useFuzzing: Boolean by getBooleanProperty(false)
249+
var useFuzzing: Boolean by getBooleanProperty(true)
250250

251251
/**
252252
* Set the total attempts to improve coverage by fuzzer.
253253
*/
254-
var fuzzingMaxAttemps: Int by getIntProperty(Int.MAX_VALUE)
254+
var fuzzingMaxAttempts: Int by getIntProperty(Int.MAX_VALUE)
255+
256+
/**
257+
* Fuzzer tries to generate and run tests during this time.
258+
*/
259+
var fuzzingTimeoutInMillis: Int by getIntProperty(3_000)
255260

256261
/**
257262
* Generate tests that treat possible overflows in arithmetic operations as errors

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,13 @@ class UtBotSymbolicEngine(
574574
}
575575

576576

577-
//Simple fuzzing
578-
fun fuzzing(modelProvider: (ModelProvider) -> ModelProvider = { it }) = flow {
577+
/**
578+
* Run fuzzing flow.
579+
*
580+
* @param until is used by fuzzer to cancel all tasks if the current time is over this value
581+
* @param modelProvider provides model values for a method
582+
*/
583+
fun fuzzing(until: Long = Long.MAX_VALUE, modelProvider: (ModelProvider) -> ModelProvider = { it }) = flow {
579584
val executableId = if (methodUnderTest.isConstructor) {
580585
methodUnderTest.javaConstructor!!.executableId
581586
} else {
@@ -618,8 +623,13 @@ class UtBotSymbolicEngine(
618623
}
619624
val modelProviderWithFallback = modelProvider(defaultModelProviders { nextDefaultModelId++ }).withFallback(fallbackModelProvider::toModel)
620625
val coveredInstructionTracker = mutableSetOf<Instruction>()
621-
var attempts = UtSettings.fuzzingMaxAttemps
626+
var attempts = UtSettings.fuzzingMaxAttempts
622627
fuzz(methodUnderTestDescription, modelProviderWithFallback).forEach { values ->
628+
if (System.currentTimeMillis() >= until) {
629+
logger.info { "Fuzzing overtime: $methodUnderTest" }
630+
return@flow
631+
}
632+
623633
val initialEnvironmentModels = EnvironmentModels(thisInstance, values.map { it.model }, mapOf())
624634

625635
try {

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ object UtBotTestCaseGenerator : TestCaseGenerator {
219219
private fun createDefaultFlow(engine: UtBotSymbolicEngine): Flow<UtResult> {
220220
var flow = engine.traverse()
221221
if (UtSettings.useFuzzing) {
222-
flow = flowOf(flow, engine.fuzzing()).flattenConcat()
222+
flow = flowOf(
223+
engine.fuzzing(System.currentTimeMillis() + UtSettings.fuzzingTimeoutInMillis),
224+
flow,
225+
).flattenConcat()
223226
}
224227
return flow
225228
}

utbot-framework/src/test/kotlin/org/utbot/examples/AbstractTestCaseGeneratorTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ abstract class AbstractTestCaseGeneratorTest(
9191
UtSettings.substituteStaticsWithSymbolicVariable = true
9292
UtSettings.useAssembleModelGenerator = true
9393
UtSettings.saveRemainingStatesForConcreteExecution = false
94+
UtSettings.useFuzzing = false
9495
}
9596

9697
// checks paramsBefore and result

utbot-intellij/src/main/resources/log4j2.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<Logger name="org.utbot.intellij" level="info">
1010
<AppenderRef ref="Console"/>
1111
</Logger>
12-
<Root level="info"/>
12+
<Logger name="org.utbot" level="error">
13+
<AppenderRef ref="Console"/>
14+
</Logger>
15+
<Root level="error">
16+
<AppenderRef ref="Console"/>
17+
</Root>
1318
</Loggers>
1419
</Configuration>

0 commit comments

Comments
 (0)