Skip to content

Commit eb8ece9

Browse files
authored
Consider dynamically created mocks when pre minimizing fuzzer output and properly initialize @mock fields (#2569)
* Consider dynamically created mocks when pre minimizing fuzzer output * Clear already initialized field models after constructing class fields
1 parent b775394 commit eb8ece9

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class UtBotSymbolicEngine(
516516
trieNode = descr.tracer.add(coveredInstructions)
517517

518518
val earlierStateBeforeSize = coverageToMinStateBeforeSize[trieNode]
519-
val curStateBeforeSize = stateBefore.calculateSize()
519+
val curStateBeforeSize = concreteExecutionResult.stateBefore.calculateSize()
520520

521521
if (earlierStateBeforeSize == null || curStateBeforeSize < earlierStateBeforeSize)
522522
coverageToMinStateBeforeSize[trieNode] = curStateBeforeSize

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
3131
fields += constructClassFields(testClassModel)
3232
clearUnwantedVariableModels()
3333

34+
// constructClassFields may mark fields as initialized, while they are in
35+
// fact not initialized, so we clearAlreadyInitializedFieldModels()
36+
variableConstructor.clearAlreadyInitializedFieldModels()
37+
3438
constructAdditionalTestMethods()?.let { methodRegions += it }
3539

3640
for ((testSetIndex, testSet) in testClassModel.methodTestSets.withIndex()) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class CgSpringVariableConstructor(context: CgContext) : CgVariableConstructor(co
1414

1515
private val fieldManagerFacade = ClassFieldManagerFacade(context)
1616

17+
fun clearAlreadyInitializedFieldModels() {
18+
fieldManagerFacade.clearAlreadyInitializedModels()
19+
}
20+
1721
override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
1822
val variable = fieldManagerFacade.constructVariableForField(model)
1923

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class ClassFieldManagerFacade(context: CgContext) : CgContextOwner by context {
1111

1212
private val alreadyInitializedModels = mutableSetOf<UtModelWrapper>()
1313

14+
fun clearAlreadyInitializedModels() {
15+
alreadyInitializedModels.clear()
16+
}
17+
1418
fun constructVariableForField(model: UtModel): CgValue? {
1519
relevantFieldManagers.forEach { manager ->
1620
val alreadyCreatedVariable = manager.findCgValueByModel(model, manager.annotatedModels)

0 commit comments

Comments
 (0)