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
Next Next commit
merge
  • Loading branch information
DaniilStepanov committed Jan 24, 2023
commit 4da08785e48f0a5e3c2607f7fe37b37870d273e8
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader

private const val LONG_GENERATION_TIMEOUT = 1_200_000L

Expand Down Expand Up @@ -144,8 +145,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
protected fun getWorkingDirectory(classFqn: String): Path? {
val classRelativePath = classFqnToPath(classFqn) + ".class"
val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null
val classAbsolutePath = replaceSeparator(classAbsoluteURL.toPath().toString())
.removeSuffix(classRelativePath)
val classAbsolutePath =
if (classAbsoluteURL.toURI().scheme == "jar") {
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
.removeSuffix(classRelativePath)
.removeSuffix("/")
.removeSuffix("!")
} else {
replaceSeparator(classAbsoluteURL.toPath().toString())
.removeSuffix(classRelativePath)
}
return Paths.get(classAbsolutePath)
}

Expand All @@ -155,15 +164,17 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
sourceCodeFile: Path? = null,
searchDirectory: Path,
chosenClassesToMockAlways: Set<ClassId>
): List<UtMethodTestSet> =
testCaseGenerator.generate(
): List<UtMethodTestSet> {
CustomClassLoader.classLoader = classLoader
return testCaseGenerator.generate(
targetMethods,
mockStrategy,
chosenClassesToMockAlways,
generationTimeout
).map {
if (sourceCodeFile != null) it.summarize(searchDirectory, sourceCodeFile.toFile()) else it
}
}


protected fun withLogger(targetClassFqn: String, block: Runnable) {
Expand Down
5 changes: 4 additions & 1 deletion utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ object FileUtil {

for (clazz in classes) {
val path = clazz.toClassFilePath()
val resource = clazz.classLoader.getResource(path) ?: error("No such file: $path")
val resource =
clazz.classLoader.getResource(path)
?: ClassLoader.getSystemClassLoader().getResource(path)
?: error("No such file: $path")

if (resource.toURI().scheme == "jar") {
val jarLocation = resource.toURI().extractJarName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
/**
* Set to true to start fuzzing if symbolic execution haven't return anything
*/
var useFuzzing: Boolean by getBooleanProperty(true)
var useFuzzing: Boolean by getBooleanProperty(false)

/**
* Set to true to start grey-box fuzzing
*/
var useGreyBoxFuzzing: Boolean by getBooleanProperty(true)

/**
* Set the total attempts to improve coverage by fuzzer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,13 @@ data class UtArrayModel(
* @param instantiationCall is an [UtExecutableCallModel] to instantiate represented object. It **must** not return `null`.
* @param modificationsChain is a chain of [UtStatementModel] to construct object state.
*/
data class UtAssembleModel private constructor(
data class UtAssembleModel constructor(
override val id: Int?,
override val classId: ClassId,
override val modelName: String,
val instantiationCall: UtExecutableCallModel,
val modificationsChain: List<UtStatementModel>,
//TODO: get rid of var
var modificationsChain: List<UtStatementModel>,
val origin: UtCompositeModel?
) : UtReferenceModel(id, classId, modelName) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.utbot.framework.plugin.api

import org.utbot.framework.plugin.api.util.objectClassId
import org.utbot.framework.plugin.api.visible.UtStreamConsumingException
import java.io.File
import java.util.LinkedList
Expand All @@ -21,6 +22,10 @@ sealed class UtExecutionFailure : UtExecutionResult() {
get() = exception
}

data class UtExecutionSuccessConcrete(val result: Any?) : UtExecutionResult() {
override fun toString() = "$result"
}

data class UtOverflowFailure(
override val exception: Throwable,
) : UtExecutionFailure()
Expand Down Expand Up @@ -102,7 +107,14 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit):
return this
}

fun UtExecutionResult.getOrThrow(): UtModel = when (this) {
is UtExecutionSuccess -> model
is UtExecutionFailure -> throw exception
is UtExecutionSuccessConcrete -> UtNullModel(objectClassId)
}

fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) {
is UtExecutionFailure -> rootCauseException
is UtExecutionSuccess -> null
is UtExecutionSuccessConcrete -> null
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtExecutionFailure
import org.utbot.framework.plugin.api.UtExecutionResult
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.UtExecutionSuccessConcrete
import org.utbot.framework.plugin.api.UtLambdaModel
import org.utbot.framework.plugin.api.UtMockValue
import org.utbot.framework.plugin.api.UtModel
Expand All @@ -42,6 +43,7 @@ import org.utbot.framework.plugin.api.util.anyInstance
import org.utbot.framework.plugin.api.util.constructLambda
import org.utbot.framework.plugin.api.util.constructStaticLambda
import org.utbot.framework.plugin.api.util.constructor
import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.isStatic
import org.utbot.framework.plugin.api.util.jClass
import org.utbot.framework.plugin.api.util.jField
Expand Down Expand Up @@ -492,6 +494,7 @@ class ValueConstructor {
private fun <R> UtExecutionResult.map(transform: (model: UtModel) -> R): Result<R> = when (this) {
is UtExecutionSuccess -> Result.success(transform(model))
is UtExecutionFailure -> Result.failure(exception)
is UtExecutionSuccessConcrete -> Result.success(transform(UtNullModel(Any::class.java.id)))
}

/**
Expand Down
4 changes: 4 additions & 0 deletions utbot-framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ dependencies {
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion
implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion
implementation "org.javaruntype:javaruntype:1.3"
implementation "ru.vyarus:generics-resolver:3.0.3"
implementation "ognl:ognl:3.3.2"

// we need this for construction mocks from composite models
implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0'

Expand Down
65 changes: 65 additions & 0 deletions utbot-framework/src/main/java/org/utbot/quickcheck/From.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
The MIT License

Copyright (c) 2010-2021 Paul R. Holser, Jr.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.utbot.quickcheck;

import org.utbot.quickcheck.Produced;
import org.utbot.quickcheck.Property;
import org.utbot.quickcheck.generator.Generator;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* <p>Mark a parameter of a {@link Property} method with this annotation to
* have random values supplied to it via the specified
* {@link Generator}.</p>
*
* <p>You may specify as many of these annotations as as you wish on a given
* parameter. On a given generation, one of the specified generators will be
* chosen at random with probability in proportion to {@link #frequency()}.</p>
*
* <p>If any such generator produces values of a type incompatible with the
* type of the marked parameter, {@link IllegalArgumentException} is
* raised.</p>
*/
@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE })
@Retention(RUNTIME)
@Repeatable(Produced.class)
public @interface From {
/**
* @return the generator to be used for the annotated property parameter
*/
Class<? extends Generator> value();

/**
* @return a weight to influence how often the generator is chosen
*/
int frequency() default 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
The MIT License

Copyright (c) 2010-2021 Paul R. Holser, Jr.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.utbot.quickcheck;

import org.utbot.quickcheck.Property;

/**
* <p>Allows access to an actual failing example.</p>
*
* <p>This may be useful if any of the objects' {@link Object#toString()}
* representations is difficult to understand.</p>
*
* @see Property#onMinimalCounterexample()
*/
public interface MinimalCounterexampleHook {
/**
* @param counterexample the minimal counterexample (after shrinking)
* @param action work to perform with the minimal counterexample;
* for example, this could repeat the test using the same inputs.
* This action should be safely callable multiple times.
*/
void handle(Object[] counterexample, Runnable action);
}
63 changes: 63 additions & 0 deletions utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
The MIT License

Copyright (c) 2010-2021 Paul R. Holser, Jr.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.utbot.quickcheck;

import org.utbot.quickcheck.Property;
import org.utbot.quickcheck.internal.ParameterSampler;
import org.utbot.quickcheck.internal.sampling.ExhaustiveParameterSampler;
import org.utbot.quickcheck.internal.sampling.TupleParameterSampler;

/**
* Represents different modes of execution of property-based tests.
*
* @see org.utbot.quickcheck.generator.Only
* @see org.utbot.quickcheck.generator.Also
*/
public enum Mode {
/**
* Verify {@link org.utbot.quickcheck.Property#trials()} tuples of arguments for a property's
* parameters.
*/
SAMPLING {
@Override ParameterSampler sampler(int defaultSampleSize) {
return new TupleParameterSampler(defaultSampleSize);
}
},

/**
* Generate {@link Property#trials()} arguments for each parameter
* property, and verify the cross-products of those sets of arguments.
* This behavior mirrors that of the JUnit
* {@link org.junit.experimental.theories.Theories} runner.
*/
EXHAUSTIVE {
@Override ParameterSampler sampler(int defaultSampleSize) {
return new ExhaustiveParameterSampler(defaultSampleSize);
}
};

abstract ParameterSampler sampler(int defaultSampleSize);
}
Loading