Skip to content

Add mocking listener in plugin #1604

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 1 commit into from
Dec 30, 2022
Merged
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 @@ -18,6 +18,8 @@ import org.utbot.common.trace
import org.utbot.engine.EngineController
import org.utbot.engine.Mocker
import org.utbot.engine.UtBotSymbolicEngine
import org.utbot.engine.util.mockListeners.ForceMockListener
import org.utbot.engine.util.mockListeners.ForceStaticMockListener
import org.utbot.framework.TestSelectionStrategyType
import org.utbot.framework.UtSettings
import org.utbot.framework.UtSettings.checkSolverTimeoutMillis
Expand All @@ -35,6 +37,8 @@ import org.utbot.framework.plugin.api.util.intArrayClassId
import org.utbot.framework.plugin.api.util.utContext
import org.utbot.framework.plugin.api.util.withUtContext
import org.utbot.framework.plugin.services.JdkInfo
import org.utbot.framework.util.Conflict
import org.utbot.framework.util.ConflictTriggers
import org.utbot.framework.util.SootUtils
import org.utbot.framework.util.jimpleBody
import org.utbot.framework.util.toModel
Expand Down Expand Up @@ -153,6 +157,10 @@ open class TestCaseGenerator(
val method2executions = methods.associateWith { mutableListOf<UtExecution>() }
val method2errors = methods.associateWith { mutableMapOf<String, Int>() }

val conflictTriggers = ConflictTriggers()
val forceMockListener = ForceMockListener.create(this, conflictTriggers, cancelJob = false)
val forceStaticMockListener = ForceStaticMockListener.create(this, conflictTriggers, cancelJob = false)

runIgnoringCancellationException {
runBlockingWithCancellationPredicate(isCanceled) {
for ((method, controller) in method2controller) {
Expand All @@ -172,14 +180,23 @@ open class TestCaseGenerator(
)

engineActions.map { engine.apply(it) }
engineActions.clear()

generate(engine)
.catch {
logger.error(it) { "Error in flow" }
}
.collect {
when (it) {
is UtExecution -> method2executions.getValue(method) += it
is UtExecution -> {
if (it is UtSymbolicExecution &&
(conflictTriggers.triggered(Conflict.ForceMockHappened) ||
conflictTriggers.triggered(Conflict.ForceStaticMockHappened))
) {
it.containsMocking = true
}
method2executions.getValue(method) += it
}
is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus)
}
}
Expand All @@ -189,6 +206,7 @@ open class TestCaseGenerator(
}
}
controller.paused = true
conflictTriggers.reset(Conflict.ForceMockHappened, Conflict.ForceStaticMockHappened)
}

// All jobs are in the method2controller now (paused). execute them with timeout
Expand Down Expand Up @@ -226,6 +244,8 @@ open class TestCaseGenerator(
}
ConcreteExecutor.defaultPool.close() // TODO: think on appropriate way to close instrumented processes

forceMockListener.detach(this, forceMockListener)
forceStaticMockListener.detach(this, forceStaticMockListener)

return methods.map { method ->
UtMethodTestSet(
Expand Down