Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniilStepanov committed Jan 24, 2023
1 parent 04fe674 commit 7392e6d
Show file tree
Hide file tree
Showing 32 changed files with 223 additions and 201 deletions.
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 @@ -245,17 +245,17 @@ 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)
* Set to true to use UtCompositeModels in grey-box fuzzing process
*/
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(true)
var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(false)

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

/**
* Set the total attempts to improve coverage by fuzzer.
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 Down Expand Up @@ -105,6 +106,11 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.utbot.common.currentThreadInfo
import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.ThreadContextElement
//import mu.KotlinLogging
import mu.KotlinLogging

val utContext: UtContext
get() = UtContext.currentContext()
Expand Down Expand Up @@ -75,7 +75,7 @@ inline fun <T> withUtContext(context: UtContext, block: () -> T): T = setUtConte
try {
return@use block.invoke()
} catch (e: Exception) {
//KotlinLogging.logger("withUtContext").error { e }
KotlinLogging.logger("withUtContext").error { e }
throw e
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ 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.UtFuzzingExecutionInstrumentation
import org.utbot.framework.concrete.FuzzerConcreteExecutor
import org.utbot.framework.concrete.constructors.UtModelConstructor
import org.utbot.framework.concrete.phases.ValueConstructionContext
import org.utbot.framework.concrete.UtFuzzingExecutionInstrumentation
import org.utbot.framework.util.convertToAssemble
import org.utbot.framework.plugin.api.*
import org.utbot.framework.plugin.api.Step
import org.utbot.framework.plugin.api.util.*
Expand All @@ -53,6 +49,8 @@ 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 org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor
import org.utbot.instrumentation.instrumentation.execution.phases.ValueConstructionContext
import soot.jimple.Stmt
import soot.tagkit.ParamNamesTag
import java.lang.reflect.Method
Expand Down Expand Up @@ -447,8 +445,7 @@ class UtBotSymbolicEngine(
collectConstantsForGreyBoxFuzzer(methodUnderTest.sootMethod, utModelConstructor),
fuzzerUtModelConstructor,
FuzzerConcreteExecutor(
concreteExecutor.pathsToUserClasses,
concreteExecutor.pathsToDependencyClasses
concreteExecutor.pathsToUserClasses
)::execute,
ValueConstructionContext(UtFuzzingExecutionInstrumentation.instrumentationContext, true)::constructParameters,
timeBudget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object UtBotJavaApi {

val concreteExecutor = ConcreteExecutor(
UtExecutionInstrumentation,
classpath,
classpath
)

testSets.addAll(generateUnitTests(concreteExecutor, methodsForGeneration, classUnderTest))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,8 @@ data class CgContext(
}
}

private var nestedClassIndex = 0
private fun createClassIdForNestedClass(testClassModel: TestClassModel): ClassId {
val simpleName = "${testClassModel.classUnderTest.simpleName}Test${nestedClassIndex++}"
val simpleName = "${testClassModel.classUnderTest.simpleName}Test"
return BuiltinClassId(
canonicalName = currentTestClass.canonicalName + "." + simpleName,
simpleName = simpleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class CgClass(
val body: CgClassBody,
val isStatic: Boolean,
val isNested: Boolean,
): CgStatement {
): CgElement {
val packageName
get() = id.packageName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,7 @@ abstract class CgAbstractRenderer(
is Boolean -> toStringConstant()
// String is "\"" + "str" + "\"", RawString is "str"
is String -> if (asRawString) "$this".escapeCharacters() else toStringConstant()
else -> {
val t = this@toStringConstant.type
val illegalType = t.toString().contains("$") || !t.isPublic
if (this == null && UtSettings.greyBoxFuzzingCompetitionMode && !illegalType) {
"(${this@toStringConstant.type}) null"
} else {
"$this"
}
}
else -> "$this"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ internal class CgJavaRenderer(context: CgRendererContext, printer: CgPrinter = C
renderExceptions(element)
}

private fun getTypeStringRepresentation(typeId: ClassId): String =
when {
typeId.isArray -> getTypeStringRepresentation(typeId.elementClassId!!) + "[]"
else -> typeId.toString()
}

override fun renderMethodSignature(element: CgMockMethod) {
val returnType = element.returnType.asString()
Expand Down
Loading

0 comments on commit 7392e6d

Please sign in to comment.