Skip to content

Consider dynamically created mocks when pre minimizing fuzzer output and properly initialize @Mock fields #2569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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