Skip to content

Commit 3018dd7

Browse files
Global refactorings
1 parent 7eab043 commit 3018dd7

File tree

198 files changed

+1629
-1926
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
-1926
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
@@ -40,7 +40,6 @@ import java.nio.file.Path
4040
import java.nio.file.Paths
4141
import java.time.LocalDateTime
4242
import java.time.temporal.ChronoUnit
43-
import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader
4443

4544
private const val LONG_GENERATION_TIMEOUT = 1_200_000L
4645

@@ -146,11 +145,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
146145
val classRelativePath = classFqnToPath(classFqn) + ".class"
147146
val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null
148147
val classAbsolutePath =
149-
if (classAbsoluteURL.toURI().scheme == "jar") {
150-
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
151-
.removeSuffix(classRelativePath)
152-
.removeSuffix("/")
153-
.removeSuffix("!")
148+
if (UtSettings.useGreyBoxFuzzing) {
149+
if (classAbsoluteURL.toURI().scheme == "jar") {
150+
replaceSeparator(classAbsoluteURL.file.removePrefix("file:"))
151+
.removeSuffix(classRelativePath)
152+
.removeSuffix("/")
153+
.removeSuffix("!")
154+
} else {
155+
replaceSeparator(classAbsoluteURL.toPath().toString())
156+
.removeSuffix(classRelativePath)
157+
}
154158
} else {
155159
replaceSeparator(classAbsoluteURL.toPath().toString())
156160
.removeSuffix(classRelativePath)
@@ -165,7 +169,6 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
165169
searchDirectory: Path,
166170
chosenClassesToMockAlways: Set<ClassId>
167171
): List<UtMethodTestSet> {
168-
CustomClassLoader.classLoader = classLoader
169172
return testCaseGenerator.generate(
170173
targetMethods,
171174
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
@@ -245,7 +245,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
245245
/**
246246
* Set to true to use grey-box fuzzing
247247
*/
248-
var useGreyBoxFuzzing: Boolean by getBooleanProperty(true)
248+
var useGreyBoxFuzzing: Boolean by getBooleanProperty(false)
249+
250+
/**
251+
* Set to true to use grey-box fuzzing in competition mode (without asserts generation)
252+
*/
253+
var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(false)
249254

250255
/**
251256
* 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,13 +42,16 @@ 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 org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData
4949
import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult
5050
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
5151
import soot.jimple.Stmt
5252
import soot.tagkit.ParamNamesTag
5353
import java.lang.reflect.Method
54+
import java.util.*
5455
import kotlin.system.measureTimeMillis
5556

5657
val logger = KotlinLogging.logger {}
@@ -337,7 +338,7 @@ class UtBotSymbolicEngine(
337338
fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow {
338339
val isFuzzable = methodUnderTest.parameters.all { classId ->
339340
classId != Method::class.java.id && // causes the instrumented process crash at invocation
340-
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
341+
classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method)
341342
}
342343
val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty()
343344
if (!isFuzzable || !hasMethodUnderTestParametersToFuzz && methodUnderTest.isStatic) {
@@ -429,13 +430,22 @@ class UtBotSymbolicEngine(
429430
if (!isFuzzable) {
430431
return@flow
431432
}
433+
val utModelConstructor = UtModelConstructor(IdentityHashMap())
434+
val fuzzerUtModelConstructor = FuzzerUtModelConstructor(
435+
utModelConstructor::construct,
436+
utModelConstructor::computeUnusedIdAndUpdate
437+
)
432438

433439
try {
434440
emitAll(
435441
GreyBoxFuzzer(
436-
concreteExecutor.pathsToUserClasses,
437-
concreteExecutor.pathsToDependencyClasses,
438442
methodUnderTest,
443+
collectConstantsForGreyBoxFuzzer(methodUnderTest.sootMethod, utModelConstructor),
444+
fuzzerUtModelConstructor,
445+
FuzzerConcreteExecutor(
446+
concreteExecutor.pathsToUserClasses,
447+
concreteExecutor.pathsToDependencyClasses
448+
)::execute,
439449
timeBudget
440450
).fuzz()
441451
)
@@ -587,7 +597,7 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId
587597
return EnvironmentModels(thisInstanceBefore, paramsBefore, statics)
588598
}
589599

590-
private suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
600+
internal suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstrumentation>.executeConcretely(
591601
methodUnderTest: ExecutableId,
592602
stateBefore: EnvironmentModels,
593603
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.

utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt

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

utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt

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

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId
159159
import org.utbot.framework.plugin.api.util.streamClassId
160160
import org.utbot.framework.plugin.api.util.streamToArrayMethodId
161161
import org.utbot.framework.plugin.api.util.isStatic
162+
import org.utbot.greyboxfuzzer.util.UtGreyBoxFuzzedExecution
162163

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import org.utbot.framework.util.ConflictTriggers
3636
import org.utbot.framework.util.SootUtils
3737
import org.utbot.framework.util.jimpleBody
3838
import org.utbot.framework.util.toModel
39+
import org.utbot.greyboxfuzzer.util.CoverageCollector
40+
import org.utbot.greyboxfuzzer.util.GreyBoxFuzzingStatisticPrinter
3941
import org.utbot.instrumentation.ConcreteExecutor
4042
import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation
4143
import org.utbot.instrumentation.warmup
@@ -131,6 +133,7 @@ open class TestCaseGenerator(
131133
generate: (engine: UtBotSymbolicEngine) -> Flow<UtResult> = defaultTestFlow(methodsGenerationTimeout)
132134
): List<UtMethodTestSet> {
133135
if (isCanceled()) return methods.map { UtMethodTestSet(it) }
136+
if (UtSettings.useGreyBoxFuzzing) CoverageCollector.clear()
134137

135138
val executionStartInMillis = System.currentTimeMillis()
136139
val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.flattenConcat
66
import kotlinx.coroutines.flow.flowOf
77
import org.utbot.engine.UtBotSymbolicEngine
88
import org.utbot.framework.UtSettings
9+
import kotlin.io.path.Path
10+
import kotlin.io.path.appendText
911

1012
/**
1113
* Constructs [TestFlow] for customization and creates flow producer.

0 commit comments

Comments
 (0)