Skip to content

Commit e6accca

Browse files
Global refactorings
1 parent 1eba966 commit e6accca

File tree

198 files changed

+1629
-1932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+1629
-1932
lines changed

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include("utbot-intellij")
2323
include("utbot-sample")
2424
include("utbot-fuzzers")
2525
include("utbot-fuzzing")
26+
include("utbot-greyboxfuzzer")
2627
include("utbot-junit-contest")
2728
include("utbot-analytics")
2829
include("utbot-analytics-torch")

utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import java.nio.file.Path
3939
import java.nio.file.Paths
4040
import java.time.LocalDateTime
4141
import java.time.temporal.ChronoUnit
42-
import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader
4342

4443
private const val LONG_GENERATION_TIMEOUT = 1_200_000L
4544

@@ -145,11 +144,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
145144
val classRelativePath = classFqnToPath(classFqn) + ".class"
146145
val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null
147146
val classAbsolutePath =
148-
if (classAbsoluteURL.toURI().scheme == "jar") {
149-
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
150-
.removeSuffix(classRelativePath)
151-
.removeSuffix("/")
152-
.removeSuffix("!")
147+
if (UtSettings.useGreyBoxFuzzing) {
148+
if (classAbsoluteURL.toURI().scheme == "jar") {
149+
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
150+
.removeSuffix(classRelativePath)
151+
.removeSuffix("/")
152+
.removeSuffix("!")
153+
} else {
154+
replaceSeparator(classAbsoluteURL.toPath().toString())
155+
.removeSuffix(classRelativePath)
156+
}
153157
} else {
154158
replaceSeparator(classAbsoluteURL.toPath().toString())
155159
.removeSuffix(classRelativePath)
@@ -164,7 +168,6 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
164168
searchDirectory: Path,
165169
chosenClassesToMockAlways: Set<ClassId>
166170
): List<UtMethodTestSet> {
167-
CustomClassLoader.classLoader = classLoader
168171
return testCaseGenerator.generate(
169172
targetMethods,
170173
mockStrategy,

utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ import java.lang.reflect.Method
88
* NOTE: vararg parameters must be passed as an array of the corresponding type.
99
*/
1010
fun Method.invokeCatching(obj: Any?, args: List<Any?>) = try {
11-
val invocation =
12-
try {
13-
invoke(obj, *args.toTypedArray())
14-
} catch (e: Throwable) {
15-
null
16-
}
11+
val invocation = invoke(obj, *args.toTypedArray())
1712
Result.success(invocation)
1813
} catch (e: InvocationTargetException) {
1914
Result.failure<Nothing>(e.targetException)

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
244244
/**
245245
* Set to true to use grey-box fuzzing
246246
*/
247-
var useGreyBoxFuzzing: Boolean by getBooleanProperty(true)
247+
var useGreyBoxFuzzing: Boolean by getBooleanProperty(false)
248+
249+
/**
250+
* Set to true to use grey-box fuzzing in competition mode (without asserts generation)
251+
*/
252+
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(false)
248253

249254
/**
250255
* Set to true to use UtCompositeModels in grey-box fuzzing process

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ data class UtArrayModel(
480480
* @param instantiationCall is an [UtExecutableCallModel] to instantiate represented object. It **must** not return `null`.
481481
* @param modificationsChain is a chain of [UtStatementModel] to construct object state.
482482
*/
483-
data class UtAssembleModel constructor(
483+
data class UtAssembleModel private constructor(
484484
override val id: Int?,
485485
override val classId: ClassId,
486486
override val modelName: String,

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class ConcreteExecutionFailureException(cause: Throwable, errorFile: File, val p
7070
appendLine("Cause:\n${cause.message}")
7171
appendLine("Last 1000 lines of the error log ${errorFile.absolutePath}:")
7272
appendLine("----------------------------------------")
73+
if (!errorFile.exists()) {
74+
errorFile.createNewFile()
75+
}
7376
errorFile.useLines { lines ->
7477
val lastLines = LinkedList<String>()
7578
for (line in lines) {
@@ -103,11 +106,6 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit):
103106
return this
104107
}
105108

106-
fun UtExecutionResult.getOrThrow(): UtModel = when (this) {
107-
is UtExecutionSuccess -> model
108-
is UtExecutionFailure -> throw exception
109-
}
110-
111109
fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) {
112110
is UtExecutionFailure -> rootCauseException
113111
is UtExecutionSuccess -> null

utbot-framework/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ dependencies {
1515
api project(':utbot-summary')
1616
api project(':utbot-framework-api')
1717
api project(':utbot-rd')
18+
api project(':utbot-greyboxfuzzer')
1819

1920
implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: rdVersion
2021
implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import org.utbot.api.exception.UtMockAssumptionViolatedException
1111
import org.utbot.common.bracket
1212
import org.utbot.common.debug
1313
import org.utbot.engine.MockStrategy.NO_MOCKS
14-
import org.utbot.engine.greyboxfuzzer.GreyBoxFuzzer
1514
import org.utbot.engine.pc.*
1615
import org.utbot.engine.selectors.*
1716
import org.utbot.engine.selectors.nurs.NonUniformRandomSearch
@@ -33,9 +32,8 @@ import org.utbot.framework.UtSettings.pathSelectorStepsLimit
3332
import org.utbot.framework.UtSettings.pathSelectorType
3433
import org.utbot.framework.UtSettings.processUnknownStatesDuringConcreteExecution
3534
import org.utbot.framework.UtSettings.useDebugVisualization
36-
import org.utbot.framework.concrete.UtConcreteExecutionData
37-
import org.utbot.framework.concrete.UtConcreteExecutionResult
38-
import org.utbot.framework.concrete.UtExecutionInstrumentation
35+
import org.utbot.framework.concrete.*
36+
import org.utbot.framework.concrete.constructors.UtModelConstructor
3937
import org.utbot.framework.plugin.api.*
4038
import org.utbot.framework.plugin.api.Step
4139
import org.utbot.framework.plugin.api.util.*
@@ -44,11 +42,14 @@ import org.utbot.framework.util.sootMethod
4442
import org.utbot.fuzzer.*
4543
import org.utbot.fuzzing.*
4644
import org.utbot.fuzzing.utils.Trie
45+
import org.utbot.greyboxfuzzer.GreyBoxFuzzer
46+
import org.utbot.greyboxfuzzer.util.FuzzerUtModelConstructor
4747
import org.utbot.instrumentation.ConcreteExecutor
4848
import ru.vyarus.java.generics.resolver.context.GenericsInfoFactory
4949
import soot.jimple.Stmt
5050
import soot.tagkit.ParamNamesTag
5151
import java.lang.reflect.Method
52+
import java.util.*
5253
import kotlin.system.measureTimeMillis
5354

5455
val logger = KotlinLogging.logger {}
@@ -330,7 +331,7 @@ class UtBotSymbolicEngine(
330331
fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow {
331332
val isFuzzable = methodUnderTest.parameters.all { classId ->
332333
classId != Method::class.java.id && // causes the instrumented process crash at invocation
333-
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
334+
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
334335
}
335336
val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty()
336337
if (!isFuzzable || !hasMethodUnderTestParametersToFuzz && methodUnderTest.isStatic) {
@@ -422,13 +423,22 @@ class UtBotSymbolicEngine(
422423
if (!isFuzzable) {
423424
return@flow
424425
}
426+
val utModelConstructor = UtModelConstructor(IdentityHashMap())
427+
val fuzzerUtModelConstructor = FuzzerUtModelConstructor(
428+
utModelConstructor::construct,
429+
utModelConstructor::computeUnusedIdAndUpdate
430+
)
425431

426432
try {
427433
emitAll(
428434
GreyBoxFuzzer(
429-
concreteExecutor.pathsToUserClasses,
430-
concreteExecutor.pathsToDependencyClasses,
431435
methodUnderTest,
436+
collectConstantsForGreyBoxFuzzer(methodUnderTest.sootMethod, utModelConstructor),
437+
fuzzerUtModelConstructor,
438+
FuzzerConcreteExecutor(
439+
concreteExecutor.pathsToUserClasses,
440+
concreteExecutor.pathsToDependencyClasses
441+
)::execute,
432442
timeBudget
433443
).fuzz()
434444
)
@@ -567,7 +577,7 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId
567577
return EnvironmentModels(thisInstanceBefore, paramsBefore, statics)
568578
}
569579

570-
private suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
580+
internal suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
571581
methodUnderTest: ExecutableId,
572582
stateBefore: EnvironmentModels,
573583
instrumentation: List<UtInstrumentation>

utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)