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
Global refactorings
  • Loading branch information
DaniilStepanov committed Jan 24, 2023
commit 3018dd75bbbafa6bc6370a9b0862261496d09562
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include("utbot-intellij")
include("utbot-sample")
include("utbot-fuzzers")
include("utbot-fuzzing")
include("utbot-greyboxfuzzer")
include("utbot-junit-contest")
include("utbot-analytics")
include("utbot-analytics-torch")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ 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 @@ -146,11 +145,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
val classRelativePath = classFqnToPath(classFqn) + ".class"
val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null
val classAbsolutePath =
if (classAbsoluteURL.toURI().scheme == "jar") {
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
.removeSuffix(classRelativePath)
.removeSuffix("/")
.removeSuffix("!")
if (UtSettings.useGreyBoxFuzzing) {
if (classAbsoluteURL.toURI().scheme == "jar") {
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
.removeSuffix(classRelativePath)
.removeSuffix("/")
.removeSuffix("!")
} else {
replaceSeparator(classAbsoluteURL.toPath().toString())
.removeSuffix(classRelativePath)
}
} else {
replaceSeparator(classAbsoluteURL.toPath().toString())
.removeSuffix(classRelativePath)
Expand All @@ -165,7 +169,6 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
searchDirectory: Path,
chosenClassesToMockAlways: Set<ClassId>
): List<UtMethodTestSet> {
CustomClassLoader.classLoader = classLoader
return testCaseGenerator.generate(
targetMethods,
mockStrategy,
Expand Down
7 changes: 1 addition & 6 deletions utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import java.lang.reflect.Method
* NOTE: vararg parameters must be passed as an array of the corresponding type.
*/
fun Method.invokeCatching(obj: Any?, args: List<Any?>) = try {
val invocation =
try {
invoke(obj, *args.toTypedArray())
} catch (e: Throwable) {
null
}
val invocation = invoke(obj, *args.toTypedArray())
Result.success(invocation)
} catch (e: InvocationTargetException) {
Result.failure<Nothing>(e.targetException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
/**
* Set to true to use grey-box fuzzing
*/
var useGreyBoxFuzzing: Boolean by getBooleanProperty(true)
var useGreyBoxFuzzing: Boolean by getBooleanProperty(false)

/**
* Set to true to use grey-box fuzzing in competition mode (without asserts generation)
*/
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(false)

/**
* Set to true to use UtCompositeModels in grey-box fuzzing process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ 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 constructor(
data class UtAssembleModel private constructor(
override val id: Int?,
override val classId: ClassId,
override val modelName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class ConcreteExecutionFailureException(cause: Throwable, errorFile: File, val p
appendLine("Cause:\n${cause.message}")
appendLine("Last 1000 lines of the error log ${errorFile.absolutePath}:")
appendLine("----------------------------------------")
if (!errorFile.exists()) {
errorFile.createNewFile()
}
errorFile.useLines { lines ->
val lastLines = LinkedList<String>()
for (line in lines) {
Expand Down Expand Up @@ -103,11 +106,6 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit):
return this
}

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

fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) {
is UtExecutionFailure -> rootCauseException
is UtExecutionSuccess -> null
Expand Down
1 change: 1 addition & 0 deletions utbot-framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
api project(':utbot-summary')
api project(':utbot-framework-api')
api project(':utbot-rd')
api project(':utbot-greyboxfuzzer')

implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: rdVersion
implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.utbot.api.exception.UtMockAssumptionViolatedException
import org.utbot.common.bracket
import org.utbot.common.debug
import org.utbot.engine.MockStrategy.NO_MOCKS
import org.utbot.engine.greyboxfuzzer.GreyBoxFuzzer
import org.utbot.engine.pc.*
import org.utbot.engine.selectors.*
import org.utbot.engine.selectors.nurs.NonUniformRandomSearch
Expand All @@ -33,9 +32,8 @@ import org.utbot.framework.UtSettings.pathSelectorStepsLimit
import org.utbot.framework.UtSettings.pathSelectorType
import org.utbot.framework.UtSettings.processUnknownStatesDuringConcreteExecution
import org.utbot.framework.UtSettings.useDebugVisualization
import org.utbot.framework.concrete.UtConcreteExecutionData
import org.utbot.framework.concrete.UtConcreteExecutionResult
import org.utbot.framework.concrete.UtExecutionInstrumentation
import org.utbot.framework.concrete.*
import org.utbot.framework.concrete.constructors.UtModelConstructor
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.Step
import org.utbot.framework.plugin.api.util.*
Expand All @@ -44,13 +42,16 @@ import org.utbot.framework.util.sootMethod
import org.utbot.fuzzer.*
import org.utbot.fuzzing.*
import org.utbot.fuzzing.utils.Trie
import org.utbot.greyboxfuzzer.GreyBoxFuzzer
import org.utbot.greyboxfuzzer.util.FuzzerUtModelConstructor
import org.utbot.instrumentation.ConcreteExecutor
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
import soot.jimple.Stmt
import soot.tagkit.ParamNamesTag
import java.lang.reflect.Method
import java.util.*
import kotlin.system.measureTimeMillis

val logger = KotlinLogging.logger {}
Expand Down Expand Up @@ -337,7 +338,7 @@ class UtBotSymbolicEngine(
fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow {
val isFuzzable = methodUnderTest.parameters.all { classId ->
classId != Method::class.java.id && // causes the instrumented process crash at invocation
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
}
val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty()
if (!isFuzzable || !hasMethodUnderTestParametersToFuzz && methodUnderTest.isStatic) {
Expand Down Expand Up @@ -429,13 +430,22 @@ class UtBotSymbolicEngine(
if (!isFuzzable) {
return@flow
}
val utModelConstructor = UtModelConstructor(IdentityHashMap())
val fuzzerUtModelConstructor = FuzzerUtModelConstructor(
utModelConstructor::construct,
utModelConstructor::computeUnusedIdAndUpdate
)

try {
emitAll(
GreyBoxFuzzer(
concreteExecutor.pathsToUserClasses,
concreteExecutor.pathsToDependencyClasses,
methodUnderTest,
collectConstantsForGreyBoxFuzzer(methodUnderTest.sootMethod, utModelConstructor),
fuzzerUtModelConstructor,
FuzzerConcreteExecutor(
concreteExecutor.pathsToUserClasses,
concreteExecutor.pathsToDependencyClasses
)::execute,
timeBudget
).fuzz()
)
Expand Down Expand Up @@ -587,7 +597,7 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId
return EnvironmentModels(thisInstanceBefore, paramsBefore, statics)
}

private suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
internal suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
methodUnderTest: ExecutableId,
stateBefore: EnvironmentModels,
instrumentation: List<UtInstrumentation>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
import org.utbot.framework.plugin.api.util.streamClassId
import org.utbot.framework.plugin.api.util.streamToArrayMethodId
import org.utbot.framework.plugin.api.util.isStatic
import org.utbot.greyboxfuzzer.util.UtGreyBoxFuzzedExecution

private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import org.utbot.framework.util.ConflictTriggers
import org.utbot.framework.util.SootUtils
import org.utbot.framework.util.jimpleBody
import org.utbot.framework.util.toModel
import org.utbot.greyboxfuzzer.util.CoverageCollector
import org.utbot.greyboxfuzzer.util.GreyBoxFuzzingStatisticPrinter
import org.utbot.instrumentation.ConcreteExecutor
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
import org.utbot.instrumentation.warmup
Expand Down Expand Up @@ -131,6 +133,7 @@ open class TestCaseGenerator(
generate: (engine: UtBotSymbolicEngine) -> Flow<UtResult> = defaultTestFlow(methodsGenerationTimeout)
): List<UtMethodTestSet> {
if (isCanceled()) return methods.map { UtMethodTestSet(it) }
if (UtSettings.useGreyBoxFuzzing) CoverageCollector.clear()

val executionStartInMillis = System.currentTimeMillis()
val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.flattenConcat
import kotlinx.coroutines.flow.flowOf
import org.utbot.engine.UtBotSymbolicEngine
import org.utbot.framework.UtSettings
import kotlin.io.path.Path
import kotlin.io.path.appendText

/**
* Constructs [TestFlow] for customization and creates flow producer.
Expand Down
Loading