Skip to content

Commit

Permalink
Consider dynamically created mocks when pre minimizing fuzzer output …
Browse files Browse the repository at this point in the history
…and properly initialize @mock fields  (#2569)

* Consider dynamically created mocks when pre minimizing fuzzer output

* Clear already initialized field models after constructing class fields
  • Loading branch information
IlyaMuravjov authored Aug 31, 2023
1 parent b775394 commit eb8ece9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class UtBotSymbolicEngine(
trieNode = descr.tracer.add(coveredInstructions)

val earlierStateBeforeSize = coverageToMinStateBeforeSize[trieNode]
val curStateBeforeSize = stateBefore.calculateSize()
val curStateBeforeSize = concreteExecutionResult.stateBefore.calculateSize()

if (earlierStateBeforeSize == null || curStateBeforeSize < earlierStateBeforeSize)
coverageToMinStateBeforeSize[trieNode] = curStateBeforeSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
fields += constructClassFields(testClassModel)
clearUnwantedVariableModels()

// constructClassFields may mark fields as initialized, while they are in
// fact not initialized, so we clearAlreadyInitializedFieldModels()
variableConstructor.clearAlreadyInitializedFieldModels()

constructAdditionalTestMethods()?.let { methodRegions += it }

for ((testSetIndex, testSet) in testClassModel.methodTestSets.withIndex()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class CgSpringVariableConstructor(context: CgContext) : CgVariableConstructor(co

private val fieldManagerFacade = ClassFieldManagerFacade(context)

fun clearAlreadyInitializedFieldModels() {
fieldManagerFacade.clearAlreadyInitializedModels()
}

override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
val variable = fieldManagerFacade.constructVariableForField(model)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class ClassFieldManagerFacade(context: CgContext) : CgContextOwner by context {

private val alreadyInitializedModels = mutableSetOf<UtModelWrapper>()

fun clearAlreadyInitializedModels() {
alreadyInitializedModels.clear()
}

fun constructVariableForField(model: UtModel): CgValue? {
relevantFieldManagers.forEach { manager ->
val alreadyCreatedVariable = manager.findCgValueByModel(model, manager.annotatedModels)
Expand Down

0 comments on commit eb8ece9

Please sign in to comment.