Skip to content

Commit a226ed1

Browse files
minor fixes
1 parent 73d485b commit a226ed1

File tree

23 files changed

+78
-114
lines changed

23 files changed

+78
-114
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) :
167167
sourceCodeFile: Path? = null,
168168
searchDirectory: Path,
169169
chosenClassesToMockAlways: Set<ClassId>
170-
): List<UtMethodTestSet> {
171-
return testCaseGenerator.generate(
170+
): List<UtMethodTestSet> =
171+
testCaseGenerator.generate(
172172
targetMethods,
173173
mockStrategy,
174174
chosenClassesToMockAlways,
175175
generationTimeout
176176
).map {
177177
if (sourceCodeFile != null) it.summarize(sourceCodeFile.toFile(), searchDirectory) else it
178178
}
179-
}
180179

181180

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

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

+1-4
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

+1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
239239
/**
240240
* Set to true to start fuzzing if symbolic execution haven't return anything
241241
*/
242-
var useFuzzing: Boolean by getBooleanProperty(false)
242+
var useFuzzing: Boolean by getBooleanProperty(true)
243243

244244
/**
245245
* Set to true to use grey-box fuzzing
@@ -254,7 +254,7 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
254254
/**
255255
* Set to true to use UtCompositeModels in grey-box fuzzing process
256256
*/
257-
var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(true)
257+
var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(false)
258258

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

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

-1
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/build.gradle

-4
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

+6-5
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.*
@@ -45,11 +48,10 @@ import org.utbot.fuzzing.utils.Trie
4548
import org.utbot.greyboxfuzzer.GreyBoxFuzzer
4649
import org.utbot.greyboxfuzzer.util.FuzzerUtModelConstructor
4750
import org.utbot.instrumentation.ConcreteExecutor
48-
import ru.vyarus.java.generics.resolver.context.GenericsInfoFactory
4951
import soot.jimple.Stmt
5052
import soot.tagkit.ParamNamesTag
5153
import java.lang.reflect.Method
52-
import java.util.*
54+
import java.util.IdentityHashMap
5355
import kotlin.system.measureTimeMillis
5456

5557
val logger = KotlinLogging.logger {}
@@ -336,7 +338,7 @@ class UtBotSymbolicEngine(
336338
fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow {
337339
val isFuzzable = methodUnderTest.parameters.all { classId ->
338340
classId != Method::class.java.id && // causes the instrumented process crash at invocation
339-
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)
340342
}
341343
val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty()
342344
if (!isFuzzable || !hasMethodUnderTestParametersToFuzz && methodUnderTest.isStatic) {
@@ -421,7 +423,6 @@ class UtBotSymbolicEngine(
421423
//Simple fuzzing
422424
fun greyBoxFuzzing(timeBudget: Long = Long.MAX_VALUE) =
423425
flow {
424-
GenericsInfoFactory.disableCache()
425426
val isFuzzable = methodUnderTest.parameters.all { classId ->
426427
classId != Method::class.java.id // causes the child process crash at invocation
427428
}

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

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import org.utbot.framework.plugin.api.UtValueExecutionState
4040
import org.utbot.framework.plugin.api.UtVoidModel
4141
import org.utbot.framework.plugin.api.isMockModel
4242
import org.utbot.framework.plugin.api.util.constructor
43-
import org.utbot.framework.plugin.api.util.id
4443
import org.utbot.framework.plugin.api.util.isStatic
4544
import org.utbot.framework.plugin.api.util.jField
4645
import org.utbot.framework.plugin.api.util.jClass

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/FuzzerConcreteExecutor.kt

-13
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-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt

-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import org.utbot.framework.concrete.phases.start
1313
import org.utbot.framework.plugin.api.Coverage
1414
import org.utbot.framework.plugin.api.EnvironmentModels
1515
import org.utbot.framework.plugin.api.FieldId
16-
import org.utbot.framework.plugin.api.Instruction
1716
import org.utbot.framework.plugin.api.UtAssembleModel
1817
import org.utbot.framework.plugin.api.UtExecutionResult
1918
import org.utbot.framework.plugin.api.UtExecutionSuccess
@@ -23,7 +22,6 @@ import org.utbot.framework.plugin.api.util.singleExecutableId
2322
import org.utbot.instrumentation.instrumentation.ArgumentList
2423
import org.utbot.instrumentation.instrumentation.Instrumentation
2524
import org.utbot.instrumentation.instrumentation.InvokeInstrumentation
26-
import org.utbot.instrumentation.instrumentation.et.EtInstruction
2725
import org.utbot.instrumentation.instrumentation.et.TraceHandler
2826
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
2927
import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor
@@ -235,12 +233,3 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
235233
return instrumenter.classByteCode
236234
}
237235
}
238-
239-
/**
240-
* Transforms a list of internal [EtInstruction]s to a list of api [Instruction]s.
241-
*/
242-
internal fun List<EtInstruction>.toApiCoverage(instructionsCount: Long? = null): Coverage =
243-
Coverage(
244-
map { Instruction(it.className, it.methodSignature, it.line, it.id) },
245-
instructionsCount
246-
)

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentationWithStatsCollection.kt

+4-4
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-framework/src/main/kotlin/org/utbot/framework/concrete/UtFuzzingExecutionInstrumentation.kt

+20
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-framework/src/main/kotlin/org/utbot/framework/concrete/constructors/MockValueConstructor.kt

+3-9
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-framework/src/main/kotlin/org/utbot/framework/concrete/phases/PhasesController.kt

-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.utbot.framework.concrete.mock.InstrumentationContext
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-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import org.utbot.instrumentation.ConcreteExecutor
4444
import org.utbot.instrumentation.warmup
4545
import org.utbot.instrumentation.warmup.Warmup
4646
import java.io.File
47-
import java.net.URLClassLoader
4847
import java.nio.file.Path
4948
import java.util.*
5049
import kotlin.coroutines.cancellation.CancellationException
@@ -86,6 +85,7 @@ open class TestCaseGenerator(
8685
if (disableCoroutinesDebug) {
8786
System.setProperty(kotlinx.coroutines.DEBUG_PROPERTY_NAME, kotlinx.coroutines.DEBUG_PROPERTY_VALUE_OFF)
8887
}
88+
8989
timeoutLogger.trace().bracket("Soot initialization") {
9090
SootUtils.runSoot(buildDirs, classpath, forceSootReload, jdkInfo)
9191
}
@@ -155,6 +155,7 @@ open class TestCaseGenerator(
155155
val method2controller = methods.associateWith { EngineController() }
156156
val method2executions = methods.associateWith { mutableListOf<UtExecution>() }
157157
val method2errors = methods.associateWith { mutableMapOf<String, Int>() }
158+
158159
runIgnoringCancellationException {
159160
runBlockingWithCancellationPredicate(isCanceled) {
160161
for ((method, controller) in method2controller) {

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

-2
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

+1-5
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

+29-2
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
}

0 commit comments

Comments
 (0)