-
Notifications
You must be signed in to change notification settings - Fork 45
Enhance fuzzing for arrays #738 #755
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0dd9ca9
Sketch for ArrayModelProvider
volivan239 1a730a9
Add RecursiveModelProvider abstraction
volivan239 570809e
Moved common logic from ArrayMP and ObjectMP to RecursiveMP
volivan239 36c749e
Minor changes & documentation added
volivan239 d6d09f2
Return behavior of defaultModelProviders and minor fixes:
volivan239 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Minor changes & documentation added
- Loading branch information
commit 36c749e02fed4007f8ad679c105a370489712971
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,37 @@ import org.utbot.fuzzer.defaultModelProviders | |
import org.utbot.fuzzer.exceptIsInstance | ||
import org.utbot.fuzzer.fuzz | ||
|
||
/** | ||
* Auxiliary data class that stores information describing how to construct model from parts (submodels) | ||
* | ||
* @param neededTypes list containing type ([ClassId]) of each submodel | ||
* @param createModel lambda that takes subModels (they should have types listed in [neededTypes]) and generates a model using them | ||
*/ | ||
data class ModelConstructor( | ||
val neededTypes: List<ClassId>, | ||
val createModel: (List<FuzzedValue>) -> FuzzedValue | ||
val createModel: (subModels: List<FuzzedValue>) -> FuzzedValue | ||
) | ||
|
||
/** | ||
* Abstraction for providers that may call other providers recursively inside them. [generate] will firstly get possible | ||
* model constructors (provided by [generateModelConstructors]) and then fuzz parameters for each of them using synthetic method | ||
* | ||
* @param recursionDepthLeft maximum recursion level, i.e. maximum number of nested calls produced by this provider | ||
* | ||
* @property modelProviderForRecursiveCalls providers that can be called by this provider. | ||
* Note that if [modelProviderForRecursiveCalls] has instances of [RecursiveModelProvider] then this provider will use | ||
* their copies created by [createNewInstance] rather than themselves (this is important because we have to change some | ||
* properties like [recursionDepthLeft], [totalLimit], etc.) | ||
* | ||
* @property fallbackProvider provider that will be used instead [modelProviderForRecursiveCalls] after reaching maximum recursion level | ||
* | ||
* @property totalLimit maximum number of parameters produced by this provider | ||
* | ||
* @property branchingLimit maximum number of [ModelConstructor]s used by [generate] (see [generateModelConstructors]) | ||
*/ | ||
abstract class RecursiveModelProvider( | ||
protected val idGenerator: IdentityPreservingIdGenerator<Int>, | ||
protected val recursionDepthLeft: Int | ||
val idGenerator: IdentityPreservingIdGenerator<Int>, | ||
val recursionDepthLeft: Int | ||
): ModelProvider { | ||
var modelProviderForRecursiveCalls: ModelProvider = defaultModelProviders(idGenerator, recursionDepthLeft - 1) | ||
|
||
|
@@ -33,12 +56,7 @@ abstract class RecursiveModelProvider( | |
if (recursionDepthLeft > 0) | ||
modelProviderForRecursiveCalls.map { | ||
if (it is RecursiveModelProvider) | ||
it.copy(idGenerator, recursionDepthLeft - 1).apply { | ||
modelProviderForRecursiveCalls = [email protected] | ||
fallbackProvider = [email protected] | ||
totalLimit = [email protected] / numOfBranches | ||
branchingLimit = [email protected] | ||
} | ||
it.createNewInstance(this, totalLimit / numOfBranches) | ||
else | ||
it | ||
} | ||
|
@@ -47,9 +65,24 @@ abstract class RecursiveModelProvider( | |
.exceptIsInstance<RecursiveModelProvider>() | ||
.withFallback(fallbackProvider) | ||
|
||
abstract fun copy(idGenerator: IdentityPreservingIdGenerator<Int>, recursionDepthLeft: Int): RecursiveModelProvider | ||
/** | ||
* Creates instance of the class on which it is called, assuming that it will be called recursively from [parentProvider] | ||
*/ | ||
protected abstract fun createNewInstance(parentProvider: RecursiveModelProvider, newTotalLimit: Int): RecursiveModelProvider | ||
|
||
abstract fun generateModelConstructors(description: FuzzedMethodDescription, clazz: ClassId): List<ModelConstructor> | ||
/** | ||
* Creates [ModelProvider]s that will be used to generate values recursively. The order of elements in returned list is important: | ||
* only first [branchingLimit] constructors will be used, so you should place most effective providers first | ||
*/ | ||
protected abstract fun generateModelConstructors(description: FuzzedMethodDescription, classId: ClassId): List<ModelConstructor> | ||
|
||
protected fun copySettingsFrom(otherProvider: RecursiveModelProvider): RecursiveModelProvider { | ||
modelProviderForRecursiveCalls = otherProvider.modelProviderForRecursiveCalls | ||
fallbackProvider = otherProvider.fallbackProvider | ||
totalLimit = otherProvider.totalLimit | ||
branchingLimit = otherProvider.branchingLimit | ||
return this | ||
} | ||
|
||
final override fun generate(description: FuzzedMethodDescription): Sequence<FuzzedParameter> = sequence { | ||
description.parametersMap.asSequence().forEach { (classId, indices) -> | ||
|
@@ -72,7 +105,7 @@ abstract class RecursiveModelProvider( | |
if (types.isEmpty()) | ||
return sequenceOf(listOf()) | ||
val syntheticMethodDescription = FuzzedMethodDescription( | ||
"<synthetic method for RecursiveModelProvider>", // TODO: maybe add something here | ||
"<synthetic method for RecursiveModelProvider>", //TODO: maybe add more info here | ||
voidClassId, | ||
types, | ||
baseMethodDescription.concreteValues | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add docs