Skip to content

Commit

Permalink
fixes after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Moiseenko <[email protected]>
  • Loading branch information
eupp committed May 30, 2024
1 parent e4a35d6 commit 2a7dd77
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
19 changes: 12 additions & 7 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/LinChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,18 @@ class LinChecker(private val testClass: Class<*>, options: Options<*, *>?) {
verifier = createVerifier()
scenario.validate()
reporter.logIteration(i + 1, scenariosSize, scenario)
var failure = scenario.run(i, this, verifier)
var failure = scenario.run(this, verifier)
if (failure == null)
return@forEachIndexed
if (minimizeFailedScenario && !isCustomScenario) {
var j = i + 1
reporter.logScenarioMinimization(scenario)
failure = failure.minimize { minimizedScenario ->
minimizedScenario.run(j++, this, createVerifier())
minimizedScenario.run(this, createVerifier())
}
}
reporter.logFailedIteration(failure)
runReplayForPlugin(failure, verifier)
return failure
}
return null
Expand All @@ -118,7 +119,6 @@ class LinChecker(private val testClass: Class<*>, options: Options<*, *>?) {
}

private fun ExecutionScenario.run(
iteration: Int,
testCfg: CTestConfiguration,
verifier: Verifier,
): LincheckFailure? {
Expand All @@ -129,19 +129,24 @@ class LinChecker(private val testClass: Class<*>, options: Options<*, *>?) {
stateRepresentationMethod = testStructure.stateRepresentation,
)
return strategy.use {
it.runIteration(iteration, testCfg.invocationsPerIteration, verifier)
it.runIteration(testCfg.invocationsPerIteration, verifier)
}
}

private fun CTestConfiguration.createVerifier() =
verifierClass.getConstructor(Class::class.java).newInstance(sequentialSpecification)

private fun CTestConfiguration.createExecutionGenerator(randomProvider: RandomProvider) =
generatorClass.getConstructor(
private fun CTestConfiguration.createExecutionGenerator(randomProvider: RandomProvider): ExecutionGenerator {
if (iterations > 0) {
checkAtLeastOneMethodIsMarkedAsOperation(testClass)
}
val constructor = generatorClass.getConstructor(
CTestConfiguration::class.java,
CTestStructure::class.java,
RandomProvider::class.java
).newInstance(this, testStructure, randomProvider)
)
return constructor.newInstance(this, testStructure, randomProvider)
}

private val CTestConfiguration.invocationsPerIteration get() = when (this) {
is ModelCheckingCTestConfiguration -> this.invocationsPerIteration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ abstract class Strategy protected constructor(
*
* @return the failure, if detected, null otherwise.
*/
fun Strategy.runIteration(iteration: Int, invocationsBound: Int, verifier: Verifier): LincheckFailure? {
fun Strategy.runIteration(invocationsBound: Int, verifier: Verifier): LincheckFailure? {
var spinning = false
for (invocation in 0 until invocationsBound) {
if (!(spinning || nextInvocation()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ abstract class ManagedStrategy(

override fun close() {
runner.close()
// clear object numeration at the end to avoid memory leaks
cleanObjectNumeration()
}

private fun createRunner(): ManagedStrategyRunner =
Expand Down Expand Up @@ -247,8 +249,11 @@ abstract class ManagedStrategy(
// Therefore, if the runner detects deadlock, we don't even try to collect trace.
if (loggedResults is RunnerTimeoutInvocationResult) return null
val sameResultTypes = loggedResults.javaClass == result.javaClass
val sameResults =
loggedResults !is CompletedInvocationResult || result !is CompletedInvocationResult || loggedResults.results == failingResult.results
val sameResults = (
loggedResults !is CompletedInvocationResult ||
result !is CompletedInvocationResult ||
loggedResults.results == result.results
)
check(sameResultTypes && sameResults) {
StringBuilder().apply {
appendln("Non-determinism found. Probably caused by non-deterministic code (WeakHashMap, Object.hashCode, etc).")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ class ModelCheckingCTestConfiguration(testClass: Class<*>, iterations: Int, thre
scenario: ExecutionScenario,
validationFunction: Actor?,
stateRepresentationMethod: Method?,
): Strategy = ModelCheckingStrategy(this, testClass, scenario, validationFunction, stateRepresentationMethod)
): Strategy = ModelCheckingStrategy(this, testClass, scenario, validationFunction, stateRepresentationMethod, isReplayModeForIdeaPluginEnabled)
}

0 comments on commit 2a7dd77

Please sign in to comment.