Skip to content

Commit ab0bdcb

Browse files
authored
Make fuzzer explore single branch #2434 (#2435)
1 parent 5b4d643 commit ab0bdcb

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

utbot-fuzzing/src/main/kotlin/org/utbot/fuzzing/Api.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,14 @@ private fun <TYPE, RESULT, DESCRIPTION : Description<TYPE>, FEEDBACK : Feedback<
422422
if (seeds.isEmpty()) {
423423
throw NoSeedValueException(type)
424424
}
425-
val candidates = seeds.map {
425+
return seeds.random(random).let {
426426
when (it) {
427427
is Seed.Simple<TYPE, RESULT> -> Result.Simple(it.value, it.mutation)
428428
is Seed.Known<TYPE, RESULT, *> -> it.asResult()
429429
is Seed.Recursive<TYPE, RESULT> -> reduce(it, fuzzing, description, random, configuration, state)
430430
is Seed.Collection<TYPE, RESULT> -> reduce(it, fuzzing, description, random, configuration, state)
431431
}
432432
}
433-
return candidates.random(random)
434433
}
435434

436435
/**

utbot-fuzzing/src/test/kotlin/org/utbot/fuzzing/FuzzerSmokeTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import kotlinx.coroutines.flow.flow
55
import org.junit.jupiter.api.Assertions
66
import org.junit.jupiter.api.Assertions.fail
77
import org.junit.jupiter.api.Test
8+
import org.junit.jupiter.api.Timeout
89
import org.junit.jupiter.api.assertThrows
910
import org.utbot.fuzzing.seeds.BitVectorValue
1011
import org.utbot.fuzzing.seeds.Signed
12+
import java.util.concurrent.TimeUnit
1113
import kotlin.reflect.KClass
1214

1315
class FuzzerSmokeTest {
@@ -282,4 +284,28 @@ class FuzzerSmokeTest {
282284
Assertions.assertTrue(seenEmpty) { "Unmodified empty string wasn't generated" }
283285
}
284286
}
287+
288+
@Test
289+
@Timeout(10, unit = TimeUnit.SECONDS) // withTimeout(1000) works inconsistently
290+
fun `fuzzer works when there are many recursive seeds`() {
291+
class Node(val parent: Node?)
292+
293+
runBlocking {
294+
var seenAnything = false
295+
withTimeout(1000) {
296+
runFuzzing(
297+
{ _, _ -> List(100) {Seed.Recursive<Unit, Node?>(
298+
construct = Routine.Create(listOf(Unit)) { (parent) -> Node(parent) },
299+
modify = emptySequence(),
300+
empty = Routine.Empty { null }
301+
)}.asSequence() },
302+
Description(listOf(Unit))
303+
) { _, _ ->
304+
seenAnything = true
305+
BaseFeedback(Unit, Control.STOP)
306+
}
307+
}
308+
Assertions.assertTrue(seenAnything) { "Fuzzer hasn't generated any values" }
309+
}
310+
}
285311
}

0 commit comments

Comments
 (0)