Skip to content

Make fuzzer explore single branch #2435

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 21, 2023
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
3 changes: 1 addition & 2 deletions utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,15 +422,14 @@ private fun <TYPE, RESULT, DESCRIPTION : Description<TYPE>, FEEDBACK : Feedback<
if (seeds.isEmpty()) {
throw NoSeedValueException(type)
}
val candidates = seeds.map {
return seeds.random(random).let {
when (it) {
is Seed.Simple<TYPE, RESULT> -> Result.Simple(it.value, it.mutation)
is Seed.Known<TYPE, RESULT, *> -> it.asResult()
is Seed.Recursive<TYPE, RESULT> -> reduce(it, fuzzing, description, random, configuration, state)
is Seed.Collection<TYPE, RESULT> -> reduce(it, fuzzing, description, random, configuration, state)
}
}
return candidates.random(random)
}

/**
Expand Down
26 changes: 26 additions & 0 deletions utbot-fuzzing/src/test/kotlin/org/utbot/fuzzing/FuzzerSmokeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import kotlinx.coroutines.flow.flow
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Timeout
import org.junit.jupiter.api.assertThrows
import org.utbot.fuzzing.seeds.BitVectorValue
import org.utbot.fuzzing.seeds.Signed
import java.util.concurrent.TimeUnit
import kotlin.reflect.KClass

class FuzzerSmokeTest {
Expand Down Expand Up @@ -282,4 +284,28 @@ class FuzzerSmokeTest {
Assertions.assertTrue(seenEmpty) { "Unmodified empty string wasn't generated" }
}
}

@Test
@Timeout(10, unit = TimeUnit.SECONDS) // withTimeout(1000) works inconsistently
fun `fuzzer works when there are many recursive seeds`() {
class Node(val parent: Node?)

runBlocking {
var seenAnything = false
withTimeout(1000) {
runFuzzing(
{ _, _ -> List(100) {Seed.Recursive<Unit, Node?>(
construct = Routine.Create(listOf(Unit)) { (parent) -> Node(parent) },
modify = emptySequence(),
empty = Routine.Empty { null }
)}.asSequence() },
Description(listOf(Unit))
) { _, _ ->
seenAnything = true
BaseFeedback(Unit, Control.STOP)
}
}
Assertions.assertTrue(seenAnything) { "Fuzzer hasn't generated any values" }
}
}
}