Skip to content

Commit bbb34cd

Browse files
minor fixes
1 parent 2bc68a0 commit bbb34cd

File tree

22 files changed

+75
-99
lines changed

22 files changed

+75
-99
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,15 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
168168
sourceCodeFile: Path? = null,
169169
searchDirectory: Path,
170170
chosenClassesToMockAlways: Set<ClassId>
171-
): List<UtMethodTestSet> {
172-
return testCaseGenerator.generate(
171+
): List<UtMethodTestSet> =
172+
testCaseGenerator.generate(
173173
targetMethods,
174174
mockStrategy,
175175
chosenClassesToMockAlways,
176176
generationTimeout
177177
).map {
178178
if (sourceCodeFile != null) it.summarize(searchDirectory, sourceCodeFile.toFile()) else it
179179
}
180-
}
181180

182181

183182
protected fun withLogger(targetClassFqn: String, block: Runnable) {

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ object FileUtil {
9090

9191
for (clazz in classes) {
9292
val path = clazz.toClassFilePath()
93-
val resource =
94-
clazz.classLoader.getResource(path)
95-
?: ClassLoader.getSystemClassLoader().getResource(path)
96-
?: error("No such file: $path")
93+
val resource = clazz.classLoader.getResource(path) ?: error("No such file: $path")
9794

9895
if (resource.toURI().scheme == "jar") {
9996
val jarLocation = resource.toURI().extractJarName()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.lang.reflect.Method
99
*/
1010
fun Method.invokeCatching(obj: Any?, args: List<Any?>) = try {
1111
val invocation = invoke(obj, *args.toTypedArray())
12+
1213
Result.success(invocation)
1314
} catch (e: InvocationTargetException) {
1415
Result.failure<Nothing>(e.targetException)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
240240
/**
241241
* Set to true to start fuzzing if symbolic execution haven't return anything
242242
*/
243-
var useFuzzing: Boolean by getBooleanProperty(false)
243+
var useFuzzing: Boolean by getBooleanProperty(true)
244244

245245
/**
246246
* Set to true to use grey-box fuzzing
@@ -255,7 +255,7 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
255255
/**
256256
* Set to true to use UtCompositeModels in grey-box fuzzing process
257257
*/
258-
var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(true)
258+
var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(false)
259259

260260
/**
261261
* Set the total attempts to improve coverage by fuzzer.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.utbot.framework.plugin.api
22

3-
import org.utbot.framework.plugin.api.util.objectClassId
43
import org.utbot.framework.plugin.api.visible.UtStreamConsumingException
54
import java.io.File
65
import java.util.LinkedList

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import org.utbot.framework.plugin.api.util.anyInstance
4242
import org.utbot.framework.plugin.api.util.constructLambda
4343
import org.utbot.framework.plugin.api.util.constructStaticLambda
4444
import org.utbot.framework.plugin.api.util.constructor
45-
import org.utbot.framework.plugin.api.util.id
4645
import org.utbot.framework.plugin.api.util.isStatic
4746
import org.utbot.framework.plugin.api.util.jClass
4847
import org.utbot.framework.plugin.api.util.jField

utbot-framework/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ dependencies {
3535
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion
3636
implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion
3737
implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion
38-
implementation "org.javaruntype:javaruntype:1.3"
39-
implementation "ru.vyarus:generics-resolver:3.0.3"
40-
implementation "ognl:ognl:3.3.2"
41-
4238
// we need this for construction mocks from composite models
4339
implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0'
4440

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import org.utbot.framework.UtSettings.pathSelectorStepsLimit
3232
import org.utbot.framework.UtSettings.pathSelectorType
3333
import org.utbot.framework.UtSettings.processUnknownStatesDuringConcreteExecution
3434
import org.utbot.framework.UtSettings.useDebugVisualization
35-
import org.utbot.framework.concrete.*
35+
import org.utbot.framework.concrete.UtConcreteExecutionData
36+
import org.utbot.framework.concrete.UtConcreteExecutionResult
37+
import org.utbot.framework.concrete.UtExecutionInstrumentation
3638
import org.utbot.framework.concrete.constructors.UtModelConstructor
39+
import org.utbot.framework.concrete.FuzzerConcreteExecutor
3740
import org.utbot.framework.plugin.api.*
3841
import org.utbot.framework.plugin.api.Step
3942
import org.utbot.framework.plugin.api.util.*
@@ -423,7 +426,6 @@ class UtBotSymbolicEngine(
423426
//Simple fuzzing
424427
fun greyBoxFuzzing(timeBudget: Long = Long.MAX_VALUE) =
425428
flow {
426-
GenericsInfoFactory.disableCache()
427429
val isFuzzable = methodUnderTest.parameters.all { classId ->
428430
classId != Method::class.java.id // causes the child process crash at invocation
429431
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ 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
119

1210
/**
1311
* Constructs [TestFlow] for customization and creates flow producer.

utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@ import soot.jimple.JimpleBody
1616
import soot.options.Options
1717
import soot.toolkits.graph.ExceptionalUnitGraph
1818
import java.io.File
19-
import java.net.URI
20-
import java.nio.file.FileSystems
21-
import java.nio.file.Files
2219
import java.nio.file.Path
23-
import kotlin.io.path.absolutePathString
24-
import kotlin.streams.toList
2520

2621
object SootUtils {
2722
/**
@@ -136,6 +131,7 @@ val ExecutableId.sootMethod: SootMethod
136131
fun jimpleBody(method: ExecutableId): JimpleBody =
137132
method.sootMethod.jimpleBody()
138133

134+
139135
private fun addBasicClasses(vararg classes: Class<*>) {
140136
classes.forEach {
141137
Scene.v().addBasicClass(it.name, SootClass.BODIES)

utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,36 @@ import org.utbot.framework.concrete.constructors.UtModelConstructor
55
import org.utbot.framework.plugin.api.ClassId
66
import org.utbot.framework.plugin.api.UtModel
77
import org.utbot.framework.plugin.api.classId
8-
import org.utbot.framework.plugin.api.util.*
8+
import org.utbot.framework.plugin.api.util.booleanClassId
9+
import org.utbot.framework.plugin.api.util.byteClassId
10+
import org.utbot.framework.plugin.api.util.charClassId
11+
import org.utbot.framework.plugin.api.util.doubleClassId
12+
import org.utbot.framework.plugin.api.util.floatClassId
13+
import org.utbot.framework.plugin.api.util.intClassId
14+
import org.utbot.framework.plugin.api.util.longClassId
15+
import org.utbot.framework.plugin.api.util.shortClassId
16+
import org.utbot.framework.plugin.api.util.stringClassId
17+
import org.utbot.framework.plugin.api.util.byteWrapperClassId
18+
import org.utbot.framework.plugin.api.util.charWrapperClassId
19+
import org.utbot.framework.plugin.api.util.doubleWrapperClassId
20+
import org.utbot.framework.plugin.api.util.floatWrapperClassId
21+
import org.utbot.framework.plugin.api.util.intWrapperClassId
22+
import org.utbot.framework.plugin.api.util.longWrapperClassId
23+
import org.utbot.framework.plugin.api.util.shortWrapperClassId
924
import org.utbot.framework.util.executableId
10-
import soot.*
25+
import soot.BooleanType
26+
import soot.ByteType
27+
import soot.CharType
28+
import soot.DoubleType
29+
import soot.FloatType
30+
import soot.IntType
31+
import soot.Local
32+
import soot.LongType
33+
import soot.ShortType
34+
import soot.SootMethod
1135
import soot.Unit
36+
import soot.Value
37+
import soot.ValueBox
1238
import soot.jimple.Constant
1339
import soot.jimple.IntConstant
1440
import soot.jimple.InvokeExpr
@@ -284,6 +310,7 @@ private object ConstantsAsIs: ConstantsFinder {
284310
override fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List<FuzzedConcreteValue> {
285311
if (value !is Constant || value is NullConstant) return emptyList()
286312
return listOf(FuzzedConcreteValue(value.type.classId, value.plainValue))
313+
287314
}
288315

289316
}

utbot-framework/src/main/resources/log4j2.xml

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

utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/GreyBoxFuzzer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import org.utbot.greyboxfuzzer.mutator.Seed
1919
import org.utbot.greyboxfuzzer.mutator.SeedCollector
2020
import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext
2121
import org.utbot.greyboxfuzzer.util.*
22+
import ru.vyarus.java.generics.resolver.context.GenericsInfoFactory
2223
import java.lang.reflect.Executable
2324
import java.lang.reflect.Field
2425
import kotlin.random.Random
25-
import kotlin.system.exitProcess
2626

2727
class GreyBoxFuzzer(
2828
private val methodUnderTest: ExecutableId,
@@ -40,6 +40,9 @@ class GreyBoxFuzzer(
4040
private val percentageOfTimeBudgetToChangeMode = 25
4141
private val logger = KotlinLogging.logger {}
4242

43+
init {
44+
GenericsInfoFactory.disableCache()
45+
}
4346

4447
suspend fun fuzz() = flow {
4548
logger.debug { "Started to fuzz ${methodUnderTest.name}" }

utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class UtFuzzingConcreteExecutionResult(
66
val stateAfter: EnvironmentModels?,
77
val result: UtExecutionResult,
88
val coverage: Coverage,
9-
val methodInstructions: List<Instruction>?
9+
val methodInstructions: List<Instruction>? = null
1010
)
1111

1212
//class UtFuzzExecutionResult() : UtConcreteExecutionResult

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.objectweb.asm.commons.LocalVariablesSorter
1010

1111
class TraceListStrategy(
1212
private val className: String,
13-
val storage: ProcessingStorage,
13+
private val storage: ProcessingStorage,
1414
private val inserter: TraceInstructionBytecodeInserter
1515
) : IInstructionVisitor {
1616
var currentLine: Int = 0

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/FuzzerConcreteExecutor.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@ class FuzzerConcreteExecutor(
1818
stateBefore: EnvironmentModels,
1919
instrumentation: List<UtInstrumentation>
2020
): UtFuzzingConcreteExecutionResult {
21-
// val fuzzingExecutor =
22-
// ConcreteExecutor(
23-
// UtFuzzingExecutionInstrumentation/*(UtSettings.greyBoxFuzzingCompetitionMode)*/,
24-
// pathsToUserClasses,
25-
// pathsToDependencyClasses
26-
// ).apply { this.classLoader = utContext.classLoader }
27-
// val executionResult = fuzzingExecutor.executeConcretelyFuzz(methodUnderTest, stateBefore, instrumentation)
28-
// return UtFuzzingConcreteExecutionResult(
29-
// null,
30-
// executionResult.result,
31-
// executionResult.coverage,
32-
// executionResult.methodInstructionsIds
33-
// )
3421
return if (UtSettings.greyBoxFuzzingCompetitionMode) {
3522
val fuzzingExecutor =
3623
ConcreteExecutor(

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.utbot.instrumentation.instrumentation.execution.phases.start
1212
import org.utbot.framework.plugin.api.Coverage
1313
import org.utbot.framework.plugin.api.EnvironmentModels
1414
import org.utbot.framework.plugin.api.FieldId
15+
import org.utbot.framework.plugin.api.UtAssembleModel
1516
import org.utbot.framework.plugin.api.UtExecutionResult
1617
import org.utbot.framework.plugin.api.UtInstrumentation
1718
import org.utbot.framework.plugin.api.UtModel

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationWithStatsCollection.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import kotlin.reflect.jvm.javaMethod
1919

2020
interface UtExecutionInstrumentationWithStatsCollection : Instrumentation<UtFuzzingConcreteExecutionResult> {
2121

22-
val delegateInstrumentation: InvokeInstrumentation// = InvokeInstrumentation()
22+
val delegateInstrumentation: InvokeInstrumentation
2323

24-
val instrumentationContext: InstrumentationContext// = InstrumentationContext()
24+
val instrumentationContext: InstrumentationContext
2525

26-
val traceHandler: TraceHandler //= TraceHandler()
27-
val pathsToUserClasses: MutableSet<String>// = mutableSetOf<String>()
26+
val traceHandler: TraceHandler
27+
val pathsToUserClasses: MutableSet<String>
2828
override fun init(pathsToUserClasses: Set<String>) {
2929
this.pathsToUserClasses.clear()
3030
this.pathsToUserClasses += pathsToUserClasses

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.framework.concrete
22

33
import org.utbot.framework.concrete.constructors.ConstructOnlyUserClassesOrCachedObjectsStrategy
44
import org.utbot.framework.concrete.mock.InstrumentationContext
5+
import org.utbot.framework.concrete.phases.PhaseError
56
import org.utbot.framework.concrete.phases.PhasesController
67
import org.utbot.framework.concrete.phases.start
78
import org.utbot.framework.plugin.api.*
@@ -10,6 +11,7 @@ import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult
1011
import org.utbot.instrumentation.instrumentation.ArgumentList
1112
import org.utbot.instrumentation.instrumentation.InvokeInstrumentation
1213
import org.utbot.instrumentation.instrumentation.et.TraceHandler
14+
import java.security.AccessControlException
1315

1416
object UtFuzzingExecutionInstrumentation : UtExecutionInstrumentationWithStatsCollection {
1517

@@ -186,3 +188,21 @@ private fun Coverage.toLocalCoverage(traceHandler: TraceHandler) =
186188
instructionsCount,
187189
missedInstructions.map { traceHandler.processingStorage.convertToLocalInstruction(it) }
188190
)
191+
192+
private inline fun PhasesController.computeFuzzingConcreteExecutionResult(block: PhasesController.() -> UtFuzzingConcreteExecutionResult): UtFuzzingConcreteExecutionResult {
193+
return use {
194+
try {
195+
block()
196+
} catch (e: PhaseError) {
197+
if (e.cause.cause is AccessControlException) {
198+
return@use UtFuzzingConcreteExecutionResult(
199+
MissingState,
200+
UtSandboxFailure(e.cause.cause!!),
201+
Coverage(),
202+
null
203+
)
204+
}
205+
throw e
206+
}
207+
}
208+
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,7 @@ class MockValueConstructor(
213213
check(Reflection.isModifiersAccessible())
214214

215215
val target = mockTarget(fieldModel) {
216-
FieldMockTarget(
217-
fieldModel.classId.name,
218-
model.classId.name,
219-
UtConcreteValue(classInstance),
220-
fieldId.name
221-
)
216+
FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), fieldId.name)
222217
}
223218
val value = construct(fieldModel, target).value
224219
val instance = if (Modifier.isStatic(declaredField.modifiers)) null else classInstance
@@ -367,10 +362,9 @@ class MockValueConstructor(
367362
val value = construct(elementModel, null).value
368363
try {
369364
java.lang.reflect.Array.set(instance, i, value)
370-
} catch (iae: IllegalArgumentException) {
365+
} catch (iae:IllegalArgumentException) {
371366
throw IllegalArgumentException(
372-
iae.message + " array: ${instance.javaClass.name}; value: ${value?.javaClass?.name}",
373-
iae
367+
iae.message + " array: ${instance.javaClass.name}; value: ${value?.javaClass?.name}" , iae
374368
)
375369
}
376370
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationC
77
import org.utbot.framework.plugin.api.Coverage
88
import org.utbot.framework.plugin.api.MissingState
99
import org.utbot.framework.plugin.api.UtSandboxFailure
10-
import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult
1110
import org.utbot.instrumentation.instrumentation.Instrumentation
1211
import org.utbot.instrumentation.instrumentation.et.TraceHandler
1312

@@ -48,25 +47,6 @@ class PhasesController(
4847
}
4948
}
5049

51-
inline fun computeFuzzingConcreteExecutionResult(block: PhasesController.() -> UtFuzzingConcreteExecutionResult): UtFuzzingConcreteExecutionResult {
52-
return use {
53-
try {
54-
block()
55-
} catch (e: PhaseError) {
56-
if (e.cause.cause is AccessControlException) {
57-
return@use UtFuzzingConcreteExecutionResult(
58-
MissingState,
59-
UtSandboxFailure(e.cause.cause!!),
60-
Coverage(),
61-
null
62-
)
63-
}
64-
// TODO: make failure results from different phase errors
65-
throw e
66-
}
67-
}
68-
}
69-
7050
override fun close() {
7151
valueConstructionContext.close()
7252
}

utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ fun runGeneration(
277277
val methodJob = currentCoroutineContext().job
278278

279279
logger.debug { " ... " }
280-
val statsForMethod = StatsForMethod("${method.classId.simpleName}#${method.name}#${method.signature}", Type.getInternalName(method.classId.jClass))
280+
val statsForMethod = StatsForMethod("${method.classId.simpleName}#${method.name}")
281281
statsForClass.statsForMethods.add(statsForMethod)
282282

283283

0 commit comments

Comments
 (0)