-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aleksandr.Potapov
committed
Jun 29, 2023
1 parent
bab4c68
commit 3040c8e
Showing
3 changed files
with
167 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 36 additions & 36 deletions
72
src/jvm/test/org/jetbrains/kotlinx/lincheck/test/representation/ThreadDumpTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
///* | ||
// * Lincheck | ||
// * | ||
// * Copyright (C) 2019 - 2023 JetBrains s.r.o. | ||
// * | ||
// * This Source Code Form is subject to the terms of the | ||
// * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed | ||
// * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// */ | ||
//package org.jetbrains.kotlinx.lincheck.test.representation | ||
// | ||
//import org.jetbrains.kotlinx.lincheck.* | ||
//import org.jetbrains.kotlinx.lincheck.strategy.* | ||
//import org.jetbrains.kotlinx.lincheck.strategy.stress.* | ||
//import org.jetbrains.kotlinx.lincheck.test.runner.* | ||
//import org.junit.* | ||
// | ||
///** | ||
// * This test checks that there is no old thread in thread dump. | ||
// */ | ||
//class ThreadDumpTest { | ||
// @Test | ||
// fun test() { | ||
// val iterations = 30 | ||
// repeat(iterations) { | ||
// val options = StressOptions() | ||
// .minimizeFailedScenario(false) | ||
// .iterations(100_000) | ||
// .invocationsPerIteration(1) | ||
// .invocationTimeout(100) | ||
// val failure = options.checkImpl(DeadlockOnSynchronizedTest::class.java) | ||
// check(failure is DeadlockWithDumpFailure) { "${DeadlockWithDumpFailure::class.simpleName} was expected but ${failure?.javaClass} was obtained"} | ||
// check(failure.threadDump!!.size == 2) { "thread dump for 2 threads expected, but for ${failure.threadDump.size} threads was detected"} | ||
// } | ||
// } | ||
//} | ||
/* | ||
* Lincheck | ||
* | ||
* Copyright (C) 2019 - 2023 JetBrains s.r.o. | ||
* | ||
* This Source Code Form is subject to the terms of the | ||
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed | ||
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.jetbrains.kotlinx.lincheck.test.representation | ||
|
||
import org.jetbrains.kotlinx.lincheck.* | ||
import org.jetbrains.kotlinx.lincheck.strategy.* | ||
import org.jetbrains.kotlinx.lincheck.strategy.stress.* | ||
import org.jetbrains.kotlinx.lincheck.test.runner.* | ||
import org.junit.* | ||
|
||
/** | ||
* This test checks that there is no old thread in thread dump. | ||
*/ | ||
class ThreadDumpTest { | ||
@Test | ||
fun test() { | ||
val iterations = 30 | ||
repeat(iterations) { | ||
val options = StressOptions() | ||
.minimizeFailedScenario(false) | ||
.iterations(100_000) | ||
.invocationsPerIteration(1) | ||
.invocationTimeout(100) | ||
val failure = options.checkImpl(DeadlockOnSynchronizedTest::class.java) | ||
check(failure is DeadlockWithDumpFailure) { "${DeadlockWithDumpFailure::class.simpleName} was expected but ${failure?.javaClass} was obtained"} | ||
check(failure.threadDump!!.size == 2) { "thread dump for 2 threads expected, but for ${failure.threadDump.size} threads was detected"} | ||
} | ||
} | ||
} |
202 changes: 101 additions & 101 deletions
202
src/jvm/test/org/jetbrains/kotlinx/lincheck/test/runner/DeadlockTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,101 @@ | ||
///* | ||
// * Lincheck | ||
// * | ||
// * Copyright (C) 2019 - 2023 JetBrains s.r.o. | ||
// * | ||
// * This Source Code Form is subject to the terms of the | ||
// * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed | ||
// * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
// */ | ||
//package org.jetbrains.kotlinx.lincheck.test.runner | ||
// | ||
//import org.jetbrains.kotlinx.lincheck.* | ||
//import org.jetbrains.kotlinx.lincheck.annotations.Operation | ||
//import org.jetbrains.kotlinx.lincheck.strategy.* | ||
//import org.jetbrains.kotlinx.lincheck.test.AbstractLincheckTest | ||
//import java.util.concurrent.atomic.AtomicBoolean | ||
// | ||
//class DeadlockOnSynchronizedTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
// private var counter = 0 | ||
// private var lock1 = Any() | ||
// private var lock2 = Any() | ||
// | ||
// @Operation | ||
// fun inc12(): Int { | ||
// synchronized(lock1) { | ||
// synchronized(lock2) { | ||
// return counter++ | ||
// } | ||
// } | ||
// } | ||
// | ||
// @Operation | ||
// fun inc21(): Int { | ||
// synchronized(lock2) { | ||
// synchronized(lock1) { | ||
// return counter++ | ||
// } | ||
// } | ||
// } | ||
// | ||
// override fun <O : Options<O, *>> O.customize() { | ||
// minimizeFailedScenario(false) | ||
// invocationTimeout(200) | ||
// } | ||
// | ||
// override fun extractState(): Any = counter | ||
//} | ||
// | ||
//class DeadlockOnSynchronizedWaitTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
// private var lock = Object() | ||
// | ||
// @Operation | ||
// fun operation() { | ||
// synchronized(lock) { | ||
// lock.wait() | ||
// } | ||
// } | ||
// | ||
// override fun <O : Options<O, *>> O.customize() { | ||
// actorsBefore(0) | ||
// minimizeFailedScenario(false) | ||
// invocationTimeout(200) | ||
// } | ||
// | ||
// override fun extractState(): Any = 0 // constant | ||
//} | ||
// | ||
//class LiveLockTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
// private var counter = 0 | ||
// private val lock1 = AtomicBoolean(false) | ||
// private val lock2 = AtomicBoolean(false) | ||
// | ||
// @Operation | ||
// fun inc12(): Int = lock1.withSpinLock { | ||
// lock2.withSpinLock { | ||
// counter++ | ||
// } | ||
// } | ||
// | ||
// @Operation | ||
// fun inc21(): Int = lock2.withSpinLock { | ||
// lock1.withSpinLock { | ||
// counter++ | ||
// } | ||
// } | ||
// | ||
// override fun extractState(): Any = counter | ||
// | ||
// override fun <O : Options<O, *>> O.customize() { | ||
// minimizeFailedScenario(false) | ||
// invocationTimeout(200) | ||
// } | ||
// | ||
// private fun AtomicBoolean.withSpinLock(block: () -> Int): Int { | ||
// while (!this.compareAndSet(false, true)); | ||
// val result = block() | ||
// this.set(false) | ||
// return result | ||
// } | ||
//} | ||
// | ||
/* | ||
* Lincheck | ||
* | ||
* Copyright (C) 2019 - 2023 JetBrains s.r.o. | ||
* | ||
* This Source Code Form is subject to the terms of the | ||
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed | ||
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.jetbrains.kotlinx.lincheck.test.runner | ||
|
||
import org.jetbrains.kotlinx.lincheck.* | ||
import org.jetbrains.kotlinx.lincheck.annotations.Operation | ||
import org.jetbrains.kotlinx.lincheck.strategy.* | ||
import org.jetbrains.kotlinx.lincheck.test.AbstractLincheckTest | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
class DeadlockOnSynchronizedTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
private var counter = 0 | ||
private var lock1 = Any() | ||
private var lock2 = Any() | ||
|
||
@Operation | ||
fun inc12(): Int { | ||
synchronized(lock1) { | ||
synchronized(lock2) { | ||
return counter++ | ||
} | ||
} | ||
} | ||
|
||
@Operation | ||
fun inc21(): Int { | ||
synchronized(lock2) { | ||
synchronized(lock1) { | ||
return counter++ | ||
} | ||
} | ||
} | ||
|
||
override fun <O : Options<O, *>> O.customize() { | ||
minimizeFailedScenario(false) | ||
invocationTimeout(200) | ||
} | ||
|
||
override fun extractState(): Any = counter | ||
} | ||
|
||
class DeadlockOnSynchronizedWaitTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
private var lock = Object() | ||
|
||
@Operation | ||
fun operation() { | ||
synchronized(lock) { | ||
lock.wait() | ||
} | ||
} | ||
|
||
override fun <O : Options<O, *>> O.customize() { | ||
actorsBefore(0) | ||
minimizeFailedScenario(false) | ||
invocationTimeout(200) | ||
} | ||
|
||
override fun extractState(): Any = 0 // constant | ||
} | ||
|
||
class LiveLockTest : AbstractLincheckTest(DeadlockWithDumpFailure::class) { | ||
private var counter = 0 | ||
private val lock1 = AtomicBoolean(false) | ||
private val lock2 = AtomicBoolean(false) | ||
|
||
@Operation | ||
fun inc12(): Int = lock1.withSpinLock { | ||
lock2.withSpinLock { | ||
counter++ | ||
} | ||
} | ||
|
||
@Operation | ||
fun inc21(): Int = lock2.withSpinLock { | ||
lock1.withSpinLock { | ||
counter++ | ||
} | ||
} | ||
|
||
override fun extractState(): Any = counter | ||
|
||
override fun <O : Options<O, *>> O.customize() { | ||
minimizeFailedScenario(false) | ||
invocationTimeout(200) | ||
} | ||
|
||
private fun AtomicBoolean.withSpinLock(block: () -> Int): Int { | ||
while (!this.compareAndSet(false, true)); | ||
val result = block() | ||
this.set(false) | ||
return result | ||
} | ||
} | ||
|