Skip to content

Make fuzzer use generic field types #2431

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
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ internal fun findAccessibleModifiableFields(description: FuzzedDescription?, cla
FieldDescription(
name = field.name,
type = if (description != null) toFuzzerType(
field.type,
field.genericType,
description.typeCache
) else FuzzedType(field.type.id),
canBeSetDirectly = isAccessible(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.utbot.fuzzing.samples;

import java.util.List;

public class StringListHolder {
private List<String> strings;


public List<String> getStrings() {
return strings;
}


public void setStrings(List<String> strings) {
this.strings = strings;
}


public void methodUnderTest() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.utbot.framework.plugin.api.UtAssembleModel
import org.utbot.framework.plugin.api.UtNullModel
import org.utbot.framework.plugin.api.UtPrimitiveModel
import org.utbot.framework.plugin.api.util.*
import org.utbot.framework.plugin.api.util.constructor.ValueConstructor
import org.utbot.fuzzer.FuzzedConcreteValue
import org.utbot.fuzzing.samples.DeepNested
import org.utbot.fuzzer.FuzzedType
Expand All @@ -17,13 +18,15 @@ import org.utbot.fuzzer.IdentityPreservingIdGenerator
import org.utbot.fuzzing.providers.NullValueProvider
import org.utbot.fuzzing.samples.AccessibleObjects
import org.utbot.fuzzing.samples.FailToGenerateListGeneric
import org.utbot.fuzzing.samples.StringListHolder
import org.utbot.fuzzing.samples.Stubs
import org.utbot.fuzzing.utils.Trie
import java.lang.reflect.GenericArrayType
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.util.IdentityHashMap
import java.util.concurrent.atomic.AtomicInteger
import kotlin.reflect.jvm.javaMethod

internal object TestIdentityPreservingIdGenerator : IdentityPreservingIdGenerator<Int> {
private val cache = mutableMapOf<Any, Int>()
Expand Down Expand Up @@ -273,6 +276,31 @@ class JavaFuzzingTest {
}
}

@Test
fun `fuzzer correctly works with settable field that has a parameterized type`() {
val seenStringListHolders = mutableListOf<StringListHolder>()
var remainingRuns = 100
runBlockingWithContext {
runJavaFuzzing(
TestIdentityPreservingIdGenerator,
methodUnderTest = StringListHolder::methodUnderTest.javaMethod!!.executableId,
constants = emptyList(),
names = emptyList(),
) { thisInstance, _, _ ->
thisInstance?.let {
seenStringListHolders.add(
ValueConstructor().construct(listOf(it.model)).single().value as StringListHolder
)
}
remainingRuns--
BaseFeedback(Trie.emptyNode(), if (remainingRuns > 0) Control.CONTINUE else Control.STOP)
}
}
val seenStrings = seenStringListHolders.flatMap { it.strings.orEmpty().filterNotNull() }
assertNotEquals(emptyList<String>(), seenStrings)
seenStrings.forEach { assertInstanceOf(String::class.java, it) }
}

@Test
fun `value providers override every function of fuzzing in simple case`() {
val provided = MarkerValueProvider<FuzzedType, FuzzedValue, FuzzedDescription>("p")
Expand Down