Skip to content

Commit 9fb393f

Browse files
amandelpiedenis-fokin
authored andcommitted
Summaries for tests generated by fuzzer are generated in the summary module #597 (#599)
* Just moved some classes and shifted the stage of name generation for fuzzing tests * Made some refactoring * Fixed a bug * Changed signatures * Fixed merge issues * Add some fixes * Add some fixes * Add some fixes * Fixed some places * Fixed some places * Fixed some places * Fixed wildcard imports
1 parent 1d1c348 commit 9fb393f

File tree

27 files changed

+354
-211
lines changed

27 files changed

+354
-211
lines changed

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

+52-18
Original file line numberDiff line numberDiff line change
@@ -135,31 +135,49 @@ data class Step(
135135
*/
136136
sealed class UtResult
137137

138+
138139
/**
139140
* Execution.
140141
*
141142
* Contains:
142143
* - execution parameters, including thisInstance;
143144
* - result;
144-
* - static fields changed during execution;
145-
* - required instrumentation details (such as randoms, time, static methods).
146145
* - coverage information (instructions) if this execution was obtained from the concrete execution.
147-
* - the engine type that created this execution.
148146
* - comments, method names and display names created by utbot-summary module.
149147
*/
150-
data class UtExecution(
148+
open class UtExecution(
151149
val stateBefore: EnvironmentModels,
152150
val stateAfter: EnvironmentModels,
153151
val result: UtExecutionResult,
154-
val instrumentation: List<UtInstrumentation>,
155-
val path: MutableList<Step>,
156-
val fullPath: List<Step>,
157152
val coverage: Coverage? = null,
158-
val createdBy: UtExecutionCreator? = null,
159153
var summary: List<DocStatement>? = null,
160154
var testMethodName: String? = null,
161-
var displayName: String? = null,
162-
) : UtResult() {
155+
var displayName: String? = null
156+
) : UtResult()
157+
158+
/**
159+
* Symbolic execution.
160+
*
161+
* Contains:
162+
* - execution parameters, including thisInstance;
163+
* - result;
164+
* - static fields changed during execution;
165+
* - required instrumentation details (such as randoms, time, static methods).
166+
* - coverage information (instructions) if this execution was obtained from the concrete execution.
167+
* - comments, method names and display names created by utbot-summary module.
168+
*/
169+
class UtSymbolicExecution(
170+
stateBefore: EnvironmentModels,
171+
stateAfter: EnvironmentModels,
172+
result: UtExecutionResult,
173+
val instrumentation: List<UtInstrumentation>,
174+
val path: MutableList<Step>,
175+
val fullPath: List<Step>,
176+
coverage: Coverage? = null,
177+
summary: List<DocStatement>? = null,
178+
testMethodName: String? = null,
179+
displayName: String? = null
180+
) : UtExecution(stateBefore, stateAfter, result, coverage, summary, testMethodName, displayName) {
163181
/**
164182
* By design the 'before' and 'after' states contain info about the same fields.
165183
* It means that it is not possible for a field to be present at 'before' and to be absent at 'after'.
@@ -169,7 +187,7 @@ data class UtExecution(
169187
get() = stateBefore.statics.keys
170188

171189
override fun toString(): String = buildString {
172-
append("UtExecution(")
190+
append("UtSymbolicExecution(")
173191
appendLine()
174192

175193
append("<State before>:")
@@ -190,6 +208,21 @@ data class UtExecution(
190208
appendOptional("instrumentation", instrumentation)
191209
append(")")
192210
}
211+
212+
fun copy(stateAfter: EnvironmentModels, result: UtExecutionResult, coverage: Coverage): UtResult {
213+
return UtSymbolicExecution(
214+
stateBefore,
215+
stateAfter,
216+
result,
217+
instrumentation,
218+
path,
219+
fullPath,
220+
coverage,
221+
summary,
222+
testMethodName,
223+
displayName
224+
)
225+
}
193226
}
194227

195228
open class EnvironmentModels(
@@ -209,7 +242,7 @@ open class EnvironmentModels(
209242
}
210243

211244
/**
212-
* Represents missing state. Useful for [UtConcreteExecutionFailure] because it does not have [UtExecution.stateAfter]
245+
* Represents missing state. Useful for [UtConcreteExecutionFailure] because it does not have [UtSymbolicExecution.stateAfter]
213246
*/
214247
object MissingState : EnvironmentModels(
215248
thisInstance = null,
@@ -553,12 +586,12 @@ data class UtDirectSetFieldModel(
553586
val fieldModel: UtModel,
554587
) : UtStatementModel(instance) {
555588
override fun toString(): String = withToStringThreadLocalReentrancyGuard {
556-
val modelRepresentation = when (fieldModel) {
557-
is UtAssembleModel -> fieldModel.modelName
558-
else -> fieldModel.toString()
559-
}
560-
"${instance.modelName}.${fieldId.name} = $modelRepresentation"
589+
val modelRepresentation = when (fieldModel) {
590+
is UtAssembleModel -> fieldModel.modelName
591+
else -> fieldModel.toString()
561592
}
593+
"${instance.modelName}.${fieldId.name} = $modelRepresentation"
594+
}
562595

563596
}
564597

@@ -1034,7 +1067,7 @@ class BuiltinMethodId(
10341067

10351068
open class TypeParameters(val parameters: List<ClassId> = emptyList())
10361069

1037-
class WildcardTypeParameter: TypeParameters(emptyList())
1070+
class WildcardTypeParameter : TypeParameters(emptyList())
10381071

10391072
interface CodeGenerationSettingItem {
10401073
val displayName: String
@@ -1164,6 +1197,7 @@ enum class CodegenLanguage(
11641197
"-cp", classPath,
11651198
"-XDignore.symbol.file" // to let javac use classes from rt.jar
11661199
).plus(sourcesFiles)
1200+
11671201
KOTLIN -> listOf("-d", buildDirectory, "-jvm-target", jvmTarget, "-cp", classPath).plus(sourcesFiles)
11681202
}
11691203
if (this == KOTLIN && System.getenv("KOTLIN_HOME") == null) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import soot.SootMethod
1818
import soot.jimple.Stmt
1919
import java.util.Objects
2020
import org.utbot.engine.symbolic.Assumption
21-
import org.utbot.framework.plugin.api.UtExecution
21+
import org.utbot.framework.plugin.api.UtSymbolicExecution
2222

2323
const val RETURN_DECISION_NUM = -1
2424
const val CALL_DECISION_NUM = -2

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

+12-36
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,30 @@ import org.utbot.framework.plugin.api.UtAssembleModel
6868
import org.utbot.framework.plugin.api.UtConcreteExecutionFailure
6969
import org.utbot.framework.plugin.api.UtError
7070
import org.utbot.framework.plugin.api.UtExecution
71-
import org.utbot.framework.plugin.api.UtExecutionCreator
7271
import org.utbot.framework.plugin.api.UtInstrumentation
7372
import org.utbot.framework.plugin.api.UtMethod
7473
import org.utbot.framework.plugin.api.UtNullModel
7574
import org.utbot.framework.plugin.api.UtOverflowFailure
7675
import org.utbot.framework.plugin.api.UtResult
77-
import org.utbot.framework.util.graph
76+
import org.utbot.framework.plugin.api.UtSymbolicExecution
7877
import org.utbot.framework.plugin.api.onSuccess
78+
import org.utbot.framework.util.graph
7979
import org.utbot.framework.plugin.api.util.executableId
8080
import org.utbot.framework.plugin.api.util.id
8181
import org.utbot.framework.plugin.api.util.utContext
8282
import org.utbot.framework.plugin.api.util.description
8383
import org.utbot.framework.util.jimpleBody
8484
import org.utbot.framework.plugin.api.util.voidClassId
85-
import org.utbot.fuzzer.ReferencePreservingIntIdGenerator
8685
import org.utbot.fuzzer.FallbackModelProvider
8786
import org.utbot.fuzzer.FuzzedMethodDescription
8887
import org.utbot.fuzzer.FuzzedValue
8988
import org.utbot.fuzzer.ModelProvider
89+
import org.utbot.fuzzer.ReferencePreservingIntIdGenerator
9090
import org.utbot.fuzzer.Trie
91+
import org.utbot.fuzzer.UtFuzzedExecution
9192
import org.utbot.fuzzer.collectConstantsForFuzzer
9293
import org.utbot.fuzzer.defaultModelProviders
9394
import org.utbot.fuzzer.fuzz
94-
import org.utbot.fuzzer.names.MethodBasedNameSuggester
95-
import org.utbot.fuzzer.names.ModelBasedNameSuggester
9695
import org.utbot.fuzzer.providers.ObjectModelProvider
9796
import org.utbot.instrumentation.ConcreteExecutor
9897
import soot.jimple.Stmt
@@ -298,15 +297,14 @@ class UtBotSymbolicEngine(
298297
val concreteExecutionResult =
299298
concreteExecutor.executeConcretely(methodUnderTest, stateBefore, instrumentation)
300299

301-
val concreteUtExecution = UtExecution(
300+
val concreteUtExecution = UtSymbolicExecution(
302301
stateBefore,
303302
concreteExecutionResult.stateAfter,
304303
concreteExecutionResult.result,
305304
instrumentation,
306305
mutableListOf(),
307306
listOf(),
308-
concreteExecutionResult.coverage,
309-
UtExecutionCreator.SYMBOLIC_ENGINE
307+
concreteExecutionResult.coverage
310308
)
311309
emit(concreteUtExecution)
312310

@@ -486,32 +484,15 @@ class UtBotSymbolicEngine(
486484
} else {
487485
logger.error { "Coverage is empty for $methodUnderTest with ${values.map { it.model }}" }
488486
}
489-
val nameSuggester = sequenceOf(ModelBasedNameSuggester(), MethodBasedNameSuggester())
490-
val testMethodName = try {
491-
nameSuggester.flatMap {
492-
it.suggest(
493-
methodUnderTestDescription,
494-
values,
495-
concreteExecutionResult.result
496-
)
497-
}.firstOrNull()
498-
} catch (t: Throwable) {
499-
logger.error(t) { "Cannot create suggested test name for ${methodUnderTest.displayName}" }
500-
null
501-
}
502487

503488
emit(
504-
UtExecution(
489+
UtFuzzedExecution(
505490
stateBefore = initialEnvironmentModels,
506491
stateAfter = concreteExecutionResult.stateAfter,
507492
result = concreteExecutionResult.result,
508-
instrumentation = emptyList(),
509-
path = mutableListOf(),
510-
fullPath = emptyList(),
511493
coverage = concreteExecutionResult.coverage,
512-
createdBy = UtExecutionCreator.FUZZER,
513-
testMethodName = testMethodName?.testName,
514-
displayName = testMethodName?.takeIf { hasMethodUnderTestParametersToFuzz }?.displayName
494+
fuzzingValues = values,
495+
fuzzedMethodDescription = methodUnderTestDescription
515496
)
516497
)
517498
}
@@ -524,11 +505,7 @@ class UtBotSymbolicEngine(
524505
val failedConcreteExecution = UtExecution(
525506
stateBefore = stateBefore,
526507
stateAfter = MissingState,
527-
result = UtConcreteExecutionFailure(e),
528-
instrumentation = emptyList(),
529-
path = mutableListOf(),
530-
fullPath = listOf(),
531-
createdBy = UtExecutionCreator.SYMBOLIC_ENGINE,
508+
result = UtConcreteExecutionFailure(e)
532509
)
533510

534511
emit(failedConcreteExecution)
@@ -562,14 +539,13 @@ class UtBotSymbolicEngine(
562539
val stateAfter = modelsAfter.constructStateForMethod(methodUnderTest)
563540
require(stateBefore.parameters.size == stateAfter.parameters.size)
564541

565-
val symbolicUtExecution = UtExecution(
542+
val symbolicUtExecution = UtSymbolicExecution(
566543
stateBefore = stateBefore,
567544
stateAfter = stateAfter,
568545
result = symbolicExecutionResult,
569546
instrumentation = instrumentation,
570547
path = entryMethodPath(state),
571-
fullPath = state.fullPath(),
572-
createdBy = UtExecutionCreator.SYMBOLIC_ENGINE,
548+
fullPath = state.fullPath()
573549
)
574550

575551
globalGraph.traversed(state)

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

+26-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.utbot.framework.plugin.api.UtModel
3030
import org.utbot.framework.plugin.api.UtNullModel
3131
import org.utbot.framework.plugin.api.UtPrimitiveModel
3232
import org.utbot.framework.plugin.api.UtReferenceModel
33+
import org.utbot.framework.plugin.api.UtSymbolicExecution
3334
import org.utbot.framework.plugin.api.UtValueExecution
3435
import org.utbot.framework.plugin.api.UtValueExecutionState
3536
import org.utbot.framework.plugin.api.UtVoidModel
@@ -123,17 +124,31 @@ class ValueConstructor {
123124
val (stateAfter, _) = constructState(execution.stateAfter)
124125
val returnValue = execution.result.map { construct(listOf(it)).single().value }
125126

126-
return UtValueExecution(
127-
stateBefore,
128-
stateAfter,
129-
returnValue,
130-
execution.path,
131-
mocks,
132-
execution.instrumentation,
133-
execution.summary,
134-
execution.testMethodName,
135-
execution.displayName
136-
)
127+
if (execution is UtSymbolicExecution) {
128+
return UtValueExecution(
129+
stateBefore,
130+
stateAfter,
131+
returnValue,
132+
execution.path,
133+
mocks,
134+
execution.instrumentation,
135+
execution.summary,
136+
execution.testMethodName,
137+
execution.displayName
138+
)
139+
} else {
140+
return UtValueExecution(
141+
stateBefore,
142+
stateAfter,
143+
returnValue,
144+
emptyList(),
145+
mocks,
146+
emptyList(),
147+
execution.summary,
148+
execution.testMethodName,
149+
execution.displayName
150+
)
151+
}
137152
}
138153

139154
private fun constructParamsAndMocks(

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ import org.utbot.framework.codegen.model.tree.CgThisInstance
3434
import org.utbot.framework.codegen.model.tree.CgValue
3535
import org.utbot.framework.codegen.model.tree.CgVariable
3636
import org.utbot.framework.codegen.model.util.createTestClassName
37-
import org.utbot.framework.plugin.api.BuiltinClassId
38-
import org.utbot.framework.plugin.api.ClassId
39-
import org.utbot.framework.plugin.api.CodegenLanguage
40-
import org.utbot.framework.plugin.api.ExecutableId
41-
import org.utbot.framework.plugin.api.FieldId
42-
import org.utbot.framework.plugin.api.MethodId
43-
import org.utbot.framework.plugin.api.MockFramework
44-
import org.utbot.framework.plugin.api.UtExecution
45-
import org.utbot.framework.plugin.api.UtModel
46-
import org.utbot.framework.plugin.api.UtReferenceModel
4737
import java.util.IdentityHashMap
4838
import kotlinx.collections.immutable.PersistentList
4939
import kotlinx.collections.immutable.PersistentMap
@@ -54,6 +44,16 @@ import kotlinx.collections.immutable.persistentSetOf
5444
import org.utbot.framework.codegen.model.constructor.CgMethodTestSet
5545
import org.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
5646
import org.utbot.framework.codegen.model.tree.CgParameterKind
47+
import org.utbot.framework.plugin.api.BuiltinClassId
48+
import org.utbot.framework.plugin.api.ClassId
49+
import org.utbot.framework.plugin.api.CodegenLanguage
50+
import org.utbot.framework.plugin.api.ExecutableId
51+
import org.utbot.framework.plugin.api.FieldId
52+
import org.utbot.framework.plugin.api.MethodId
53+
import org.utbot.framework.plugin.api.MockFramework
54+
import org.utbot.framework.plugin.api.UtExecution
55+
import org.utbot.framework.plugin.api.UtModel
56+
import org.utbot.framework.plugin.api.UtReferenceModel
5757
import org.utbot.framework.plugin.api.util.id
5858
import org.utbot.framework.plugin.api.util.isCheckedException
5959
import org.utbot.framework.plugin.api.util.isSubtypeOf

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgFieldStateManager.kt

+18-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import org.utbot.framework.fields.FieldPath
2626
import org.utbot.framework.fields.ModifiedFields
2727
import org.utbot.framework.fields.StateModificationInfo
2828
import org.utbot.framework.plugin.api.ClassId
29+
import org.utbot.framework.plugin.api.UtSymbolicExecution
2930
import org.utbot.framework.plugin.api.util.hasField
3031
import org.utbot.framework.plugin.api.util.id
3132
import org.utbot.framework.plugin.api.util.isArray
3233
import org.utbot.framework.plugin.api.util.isRefType
3334
import org.utbot.framework.plugin.api.util.objectClassId
3435
import org.utbot.framework.util.hasThisInstance
36+
import org.utbot.fuzzer.UtFuzzedExecution
3537
import java.lang.reflect.Array
3638

3739
internal interface CgFieldStateManager {
@@ -67,13 +69,23 @@ internal class CgFieldStateManagerImpl(val context: CgContext)
6769
}
6870

6971
private fun rememberThisInstanceState(info: StateModificationInfo, state: FieldState) {
70-
if (!currentExecution!!.hasThisInstance()) {
71-
return
72+
when (currentExecution) {
73+
is UtSymbolicExecution -> {
74+
if (!(currentExecution!! as UtSymbolicExecution).hasThisInstance()) {
75+
return
76+
}
77+
val thisInstance = context.thisInstance!!
78+
val modifiedFields = info.thisInstance
79+
// by now this instance variable must have already been created
80+
saveFieldsState(thisInstance, modifiedFields, statesCache.thisInstance, state)
81+
}
82+
is UtFuzzedExecution -> {
83+
return
84+
}
85+
else -> {
86+
return
87+
}
7288
}
73-
val thisInstance = context.thisInstance!!
74-
val modifiedFields = info.thisInstance
75-
// by now this instance variable must have already been created
76-
saveFieldsState(thisInstance, modifiedFields, statesCache.thisInstance, state)
7789
}
7890

7991
private fun rememberArgumentsState(info: StateModificationInfo, state: FieldState) {

0 commit comments

Comments
 (0)