Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4da0878
merge
DaniilStepanov Nov 9, 2022
9fa553a
mocks generation
DaniilStepanov Nov 15, 2022
390d805
remove shrinker
Saloed Nov 10, 2022
d823f29
Rename .java to .kt
Saloed Nov 10, 2022
1343666
rewrite quickcheck on Kotlin
Saloed Nov 10, 2022
854c790
Rename .java to .kt
DaniilStepanov Nov 15, 2022
4d374c7
this instance rewriting
DaniilStepanov Nov 15, 2022
3157025
Added mutations
DaniilStepanov Nov 22, 2022
14604b4
minor
DaniilStepanov Nov 22, 2022
c5f5ae2
New seed selection strategy and time budget for generation
DaniilStepanov Nov 29, 2022
1dbcde7
refactoring and fixes
DaniilStepanov Dec 1, 2022
3452621
m
DaniilStepanov Dec 1, 2022
8240554
UnsafeBasedInstanceGenerator done
DaniilStepanov Dec 6, 2022
ad5af5d
Mutator refactorings
DaniilStepanov Dec 6, 2022
9e0ac70
minor
DaniilStepanov Dec 6, 2022
09343b0
Contest mode is done
DaniilStepanov Dec 19, 2022
3a86fd6
merge
DaniilStepanov Dec 19, 2022
1de5db5
constants collector
DaniilStepanov Dec 19, 2022
5fb1090
removed unnecessary files
DaniilStepanov Dec 19, 2022
1cc03c3
bug fixes
DaniilStepanov Dec 20, 2022
7eab043
removing fuzzer executor
DaniilStepanov Dec 20, 2022
3018dd7
Global refactorings
DaniilStepanov Dec 28, 2022
2bc68a0
minor
DaniilStepanov Dec 28, 2022
bbb34cd
minor fixes
DaniilStepanov Dec 28, 2022
4f77b79
minor
DaniilStepanov Dec 28, 2022
dd16ada
Fixed nested classes generation
DaniilStepanov Jan 13, 2023
ddaf943
fixes to contest
DaniilStepanov Jan 18, 2023
554a9c9
Mock renderer added
DaniilStepanov Jan 19, 2023
04fe674
fixes
DaniilStepanov Jan 24, 2023
7392e6d
rebase
DaniilStepanov Jan 24, 2023
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
Prev Previous commit
Next Next commit
rewrite quickcheck on Kotlin
  • Loading branch information
Saloed authored and DaniilStepanov committed Jan 24, 2023
commit 13436668de9d1ac03d9533a8c0006fbc23f6acc8

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object DataGenerator {
}

fun generate(
generator: Generator<*>?,
generator: Generator?,
parameter: Parameter,
random: SourceOfRandomness,
status: GenerationStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class FField(
val field: Field?,
val value: Any?,
val resolvedType: Type,
val generator: Generator<*>?,
val generator: Generator?,
val classId: ClassId,
val subFields: List<FField>,
var isBlocked: Boolean,
Expand All @@ -21,7 +21,7 @@ data class FField(
field: Field?,
value: Any?,
resolvedType: Type,
generator: Generator<*>?,
generator: Generator?,
subFields: List<FField>,
isBlocked: Boolean
) : this(
Expand All @@ -38,7 +38,7 @@ data class FField(
field: Field?,
value: Any?,
resolvedType: Type,
generator: Generator<*>?,
generator: Generator?,
subFields: List<FField>,
) : this(
field,
Expand All @@ -54,7 +54,7 @@ data class FField(
field: Field?,
value: Any?,
resolvedType: Type,
generator: Generator<*>?,
generator: Generator?,
) : this(
field,
value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class FParameter(
val parameter: Parameter,
val value: Any?,
var utModel: UtModel,
val generator: Generator<*>?,
val generator: Generator?,
val classId: ClassId,
val fields: List<FField>
) {
Expand All @@ -24,14 +24,14 @@ data class FParameter(
parameter: Parameter,
value: Any?,
utModel: UtModel,
generator: Generator<*>?
generator: Generator?
) : this(parameter, value, utModel, generator, classIdForType(parameter.type), emptyList())

constructor(
parameter: Parameter,
value: Any?,
utModel: UtModel,
generator: Generator<*>?,
generator: Generator?,
fields: List<FField>
) : this(parameter, value, utModel, generator, classIdForType(parameter.type), fields)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.utbot.quickcheck.generator.java.util.CollectionGenerator
import org.utbot.quickcheck.generator.java.util.MapGenerator
import org.utbot.quickcheck.internal.generator.ArrayGenerator
import org.utbot.engine.greyboxfuzzer.util.getTrue
import org.utbot.engine.greyboxfuzzer.util.setFieldValue
import org.utbot.quickcheck.generator.java.lang.*
import kotlin.random.Random

Expand Down Expand Up @@ -66,13 +65,13 @@ object GeneratorConfigurator {
inRangeAnnotationInstance = InRange::class.constructors.first().callBy(inRangeAnnotationParams)
}

fun configureGenerator(generator: Generator<*>, prob: Int) {
fun configureGenerator(generator: Generator, prob: Int) {
(listOf(generator) + generator.getAllComponents()).forEach {
if (Random.getTrue(prob)) handleGenerator(it)
}
}

private fun handleGenerator(generator: Generator<*>) =
private fun handleGenerator(generator: Generator) =
when (generator) {
is IntegerGenerator -> generator.configure(inRangeAnnotationInstance)
is ByteGenerator -> generator.configure(inRangeAnnotationInstance)
Expand All @@ -88,7 +87,7 @@ object GeneratorConfigurator {
is PrimitiveFloatGenerator -> generator.configure(inRangeAnnotationInstance)
is PrimitiveDoubleGenerator -> generator.configure(inRangeAnnotationInstance)
is PrimitiveLongGenerator -> generator.configure(inRangeAnnotationInstance)
is CollectionGenerator<*> -> generator.configure(sizeAnnotationInstance)
is CollectionGenerator -> generator.configure(sizeAnnotationInstance)
is ArrayGenerator -> generator.configure(sizeAnnotationInstance)
is MapGenerator -> generator.configure(sizeAnnotationInstance)
else -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import ru.vyarus.java.generics.resolver.context.MethodGenericsContext
import java.lang.reflect.*


fun Generator<*>.getAllComponents(): List<Generator<*>> {
val queue = ArrayDeque<Generator<*>>()
val res = mutableListOf<Generator<*>>()
fun Generator.getAllComponents(): List<Generator> {
val queue = ArrayDeque<Generator>()
val res = mutableListOf<Generator>()
this.getComponents().forEach { queue.add(it) }
while (queue.isNotEmpty()) {
val comp = queue.removeFirst()
Expand All @@ -37,9 +37,9 @@ fun Generator<*>.getAllComponents(): List<Generator<*>> {
return res
}

fun Generator<*>.getComponents(): List<Generator<*>> =
fun Generator.getComponents(): List<Generator> =
when (this) {
is ComponentizedGenerator<*> -> this.componentGenerators()
is ComponentizedGenerator -> this.componentGenerators()
is ArrayGenerator -> listOf(this.component)
else -> emptyList()
}
Expand All @@ -58,19 +58,19 @@ fun GeneratorRepository.produceUserClassGenerator(
return userClassGenerator
}

fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator<*>? =
fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator? =
getOrProduceGenerator(ParameterTypeContext.forField(field), depth)

fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator<*>? =
fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator? =
getOrProduceGenerator(param.createParameterTypeContext(parameterIndex), depth)

fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator<*>? =
fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator? =
getOrProduceGenerator(clazz.createParameterTypeContext(), depth)

fun GeneratorRepository.getOrProduceGenerator(
parameterTypeContext: ParameterTypeContext,
depth: Int
): Generator<*>? {
): Generator? {
val producedUserClassesGenerators = mutableListOf<UserClassGenerator>()
parameterTypeContext.getAllSubParameterTypeContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).reversed()
.forEach { typeContext ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import org.utbot.quickcheck.internal.generator.GeneratorRepository
import org.utbot.quickcheck.internal.generator.LambdaGenerator
import org.utbot.quickcheck.internal.generator.MarkerInterfaceGenerator
import org.utbot.quickcheck.random.SourceOfRandomness
import org.utbot.engine.greyboxfuzzer.util.toClass
import org.utbot.engine.logger
import org.utbot.quickcheck.internal.Zilch

class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) {

override fun generatorFor(parameter: ParameterTypeContext): Generator<*>? {
override fun generatorFor(parameter: ParameterTypeContext): Generator {
logger.debug { "TRYING TO GET GENERATOR FOR ${parameter.resolved}" }
if (parameter.resolved.name == "org.utbot.quickcheck.internal.Zilch") return null
if (parameter.resolved.name == Zilch::class.java.name) return TODO("null")
val generator = super.generatorFor(parameter)
if (generator is MarkerInterfaceGenerator<*>) {
if (generator is MarkerInterfaceGenerator) {
throw IllegalArgumentException(
"Cannot find generator for " + parameter.name()
+ " of type " + parameter.type().typeName
)
} else if (generator is LambdaGenerator<*, *>) {
return null
} else if (generator is LambdaGenerator<*>) {
return TODO("null")
}
return generator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package org.utbot.engine.greyboxfuzzer.generator.set

import org.utbot.quickcheck.generator.java.util.SetGenerator

class HashSetGenerator: SetGenerator<HashSet<*>>(HashSet::class.java)
class HashSetGenerator: SetGenerator(HashSet::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ import org.utbot.framework.plugin.api.UtNullModel
import org.utbot.framework.plugin.api.util.id
import java.lang.reflect.*

class UserClassGenerator : ComponentizedGenerator<Any>(Any::class.java) {
class UserClassGenerator : ComponentizedGenerator(Any::class.java) {

var clazz: Class<*>? = null
var parameterTypeContext: ParameterTypeContext? = null
var depth = 0
var generationMethod = GenerationMethod.ANY

override fun copy(): Generator<Any> {
override fun copy(): Generator {
return UserClassGenerator().also {
it.clazz = clazz
it.depth = depth
it.parameterTypeContext = parameterTypeContext
}
}

override fun canGenerateForParametersOfTypes(typeParameters: MutableList<TypeParameter<*>>?): Boolean {
override fun canGenerateForParametersOfTypes(typeParameters: List<TypeParameter<*>>): Boolean {
return true
}

Expand All @@ -45,15 +45,12 @@ class UserClassGenerator : ComponentizedGenerator<Any>(Any::class.java) {
return generate(random, status)
}

override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel? {
override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel {
logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" }
if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return UtNullModel(clazz!!.id)
if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return TODO("null")
val immutableClazz = clazz!!
when (immutableClazz) {
Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status).generate()
Class::class.java -> return ReflectionClassGenerator(parameterTypeContext!!).generate()
Type::class.java -> return ReflectionTypeGenerator(parameterTypeContext!!).generate()
}
if (immutableClazz == Any::class.java) return ObjectGenerator(random, status).generate()
if (immutableClazz == Class::class.java) return ReflectionClassGenerator(parameterTypeContext!!).generate()
//TODO! generate inner classes instances
if (immutableClazz.declaringClass != null && !immutableClazz.hasModifiers(Modifier.STATIC)) {
return UtNullModel(immutableClazz.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ClassesInstanceGenerator(
private val genStatus: GenerationStatus,
private val depth: Int
): InstanceGenerator {
override fun generate(): UtModel? {
override fun generate(): UtModel {
val typeOfGenerations = when (generationMethod) {
GenerationMethod.CONSTRUCTOR -> mutableListOf('c')
GenerationMethod.STATIC -> mutableListOf('s')
else -> mutableListOf('c', 'c', 's')
}
while (typeOfGenerations.isNotEmpty()) {
val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return null
val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return TODO("null")
logger.debug { "Type of generation: $randomTypeOfGeneration" }
val generatedInstance =
when (randomTypeOfGeneration) {
Expand All @@ -50,6 +50,6 @@ class ClassesInstanceGenerator(
return generatedInstance
}
}
return null
return TODO("null")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ConstructorBasedInstanceGenerator(
private val depth: Int
): InstanceGenerator {

override fun generate(): UtModel? {
val constructor = chooseRandomConstructor(clazz) ?: return null
override fun generate(): UtModel {
val constructor = chooseRandomConstructor(clazz) ?: return TODO("null")
val resolvedConstructor =
//In case if we can not resolve constructor
gctx.constructor(constructor).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator
import org.utbot.framework.plugin.api.UtModel

interface InstanceGenerator {
fun generate(): UtModel?
fun generate(): UtModel
}
Loading