Skip to content

Commit 19a2a30

Browse files
committed
Update lincheck
1 parent e06585a commit 19a2a30

9 files changed

+94
-228
lines changed

core/kotlinx-coroutines-core/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
dependencies {
6-
testCompile "com.devexperts.lincheck:core:$lincheck_version"
6+
testCompile "com.devexperts.lincheck:lincheck:$lincheck_version"
77
testCompile "com.esotericsoftware:kryo:4.0.0"
88
}
99

core/kotlinx-coroutines-core/test/internal/LockFreeTaskQueueLinearizabilityTest.kt

-79
This file was deleted.

core/kotlinx-coroutines-core/test/channels/ChannelIsClosedLinearizabilityTest.kt renamed to core/kotlinx-coroutines-core/test/linearizability/ChannelIsClosedLinearizabilityTest.kt

+5-21
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,22 @@
33
*/
44
@file:Suppress("unused")
55

6-
package kotlinx.coroutines.channels
6+
package kotlinx.coroutines.linearizability
77

88
import com.devexperts.dxlab.lincheck.*
99
import com.devexperts.dxlab.lincheck.annotations.*
1010
import com.devexperts.dxlab.lincheck.paramgen.*
11-
import com.devexperts.dxlab.lincheck.stress.*
11+
import com.devexperts.dxlab.lincheck.strategy.stress.*
1212
import kotlinx.coroutines.*
13+
import kotlinx.coroutines.channels.*
1314
import org.junit.*
1415
import java.io.*
1516

1617
@Param(name = "value", gen = IntGen::class, conf = "1:3")
1718
class ChannelIsClosedLinearizabilityTest : TestBase() {
1819

1920
private val lt = LinTesting()
20-
private lateinit var channel: Channel<Int>
21-
22-
@Reset
23-
fun resetChannel() {
24-
channel = Channel()
25-
}
21+
private val channel = Channel<Int>()
2622

2723
@Operation(runOnce = true)
2824
fun send1(@Param(name = "value") value: Int) = lt.run("send1") { channel.send(value) }
@@ -50,20 +46,8 @@ class ChannelIsClosedLinearizabilityTest : TestBase() {
5046
val options = StressOptions()
5147
.iterations(100)
5248
.invocationsPerIteration(1000 * stressTestMultiplier)
53-
.addThread(1, 3)
54-
.addThread(1, 3)
55-
.addThread(1, 3)
49+
.threads(3)
5650
.verifier(LinVerifier::class.java)
57-
.injectExecution { actors, methods ->
58-
actors[0].add(actorMethod(methods, "receive1"))
59-
actors[0].add(actorMethod(methods, "receive2"))
60-
actors[0].add(actorMethod(methods, "close1"))
61-
62-
actors[1].add(actorMethod(methods, "send2"))
63-
actors[1].add(actorMethod(methods, "send1"))
64-
65-
actors[2].add(actorMethod(methods, "isClosedForSend"))
66-
}
6751

6852
LinChecker.check(ChannelIsClosedLinearizabilityTest::class.java, options)
6953
}

core/kotlinx-coroutines-core/test/channels/ChannelLinearizabilityTest.kt renamed to core/kotlinx-coroutines-core/test/linearizability/ChannelLinearizabilityTest.kt

+11-12
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
*/
44
@file:Suppress("unused")
55

6-
package kotlinx.coroutines.channels
6+
package kotlinx.coroutines.linearizability
77

88
import com.devexperts.dxlab.lincheck.*
99
import com.devexperts.dxlab.lincheck.annotations.*
1010
import com.devexperts.dxlab.lincheck.paramgen.*
11-
import com.devexperts.dxlab.lincheck.stress.*
11+
import com.devexperts.dxlab.lincheck.strategy.stress.*
1212
import kotlinx.coroutines.*
13+
import kotlinx.coroutines.channels.*
1314
import org.junit.*
1415
import java.io.*
1516

1617
@Param(name = "value", gen = IntGen::class, conf = "1:3")
1718
class ChannelLinearizabilityTest : TestBase() {
1819

20+
private companion object {
21+
// Emulating ctor argument for lincheck
22+
var capacity = 0
23+
}
24+
1925
private val lt = LinTesting()
20-
private var capacity = 0
21-
private lateinit var channel: Channel<Int>
26+
private var channel: Channel<Int> = Channel(capacity)
2227

23-
@Reset
24-
fun resetChannel() {
25-
channel = Channel(capacity)
26-
}
2728

2829
@Operation(runOnce = true)
2930
fun send1(@Param(name = "value") value: Int) = lt.run("send1") { channel.send(value) }
@@ -68,13 +69,11 @@ class ChannelLinearizabilityTest : TestBase() {
6869
fun testUnlimitedChannelLinearizability() = runTest(Channel.UNLIMITED)
6970

7071
private fun runTest(capacity: Int) {
71-
this.capacity = capacity
72+
ChannelLinearizabilityTest.capacity = capacity
7273
val options = StressOptions()
7374
.iterations(100)
7475
.invocationsPerIteration(1000 * stressTestMultiplier)
75-
.addThread(1, 3)
76-
.addThread(1, 3)
77-
.addThread(1, 3)
76+
.threads(3)
7877
.verifier(LinVerifier::class.java)
7978
LinChecker.check(ChannelLinearizabilityTest::class.java, options)
8079
}

core/kotlinx-coroutines-core/test/linearizability/FixedBehaviourExecutionGenerator.kt

-92
This file was deleted.

core/kotlinx-coroutines-core/test/linearizability/LinTesting.kt

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package kotlinx.coroutines
66

77
import com.devexperts.dxlab.lincheck.Actor
88
import com.devexperts.dxlab.lincheck.Result
9+
import com.devexperts.dxlab.lincheck.Utils.*
10+
import com.devexperts.dxlab.lincheck.execution.*
911
import com.devexperts.dxlab.lincheck.verifier.Verifier
1012
import java.lang.reflect.Method
1113
import java.util.*
@@ -57,29 +59,30 @@ class LinTesting {
5759
}
5860
}
5961

60-
class LinVerifier(
61-
actorsPerThread: List<List<Actor>>, testInstance: Any, resetMethod: Method?
62-
) : Verifier(actorsPerThread, testInstance, resetMethod) {
62+
class LinVerifier(scenario: ExecutionScenario,
63+
testClass: Class<*>) : Verifier {
6364
private val possibleResultsSet: Set<List<List<Result>>> =
64-
generateAllLinearizableExecutions(actorsPerThread)
65+
generateAllLinearizableExecutions(scenario.parallelExecution)
6566
.asSequence()
6667
.map { linEx: List<Actor> ->
67-
val res: List<Result> = executeActors(testInstance, linEx)
68+
val res: List<Result> = executeActors(testClass.newInstance(), linEx)
6869
val actorIds = linEx.asSequence().withIndex().associateBy({ it.value}, { it.index })
69-
actorsPerThread.map { actors -> actors.map { actor -> res[actorIds[actor]!!] } }
70+
scenario.parallelExecution.map { actors -> actors.map { actor -> res[actorIds[actor]!!] } }
7071
}.toSet()
7172

72-
override fun verifyResults(results: List<List<Result>>) {
73-
if (!valid(results)) {
73+
override fun verifyResults(results: ExecutionResult): Boolean {
74+
if (!valid(results.parallelResults)) {
7475
println("\nNon-linearizable execution:")
75-
printResults(results)
76+
printResults(results.parallelResults)
7677
println("\nPossible linearizable executions:")
7778
possibleResultsSet.forEach { possibleResults ->
7879
printResults(possibleResults)
7980
println()
8081
}
8182
throw AssertionError("Non-linearizable execution detected, see log for details")
8283
}
84+
85+
return true
8386
}
8487

8588
private fun printResults(results: List<List<Result>>) {
@@ -103,7 +106,7 @@ class LinVerifier(
103106
private fun generateAllLinearizableExecutions(actorsPerThread: List<List<Actor>>): List<List<Actor>> {
104107
val executions = ArrayList<List<Actor>>()
105108
generateLinearizableExecutions0(
106-
executions, actorsPerThread, ArrayList<Actor>(), IntArray(actorsPerThread.size),
109+
executions, actorsPerThread, ArrayList(), IntArray(actorsPerThread.size),
107110
actorsPerThread.sumBy { it.size })
108111
return executions
109112
}

core/kotlinx-coroutines-core/test/internal/LockFreeListLinearizabilityTest.kt renamed to core/kotlinx-coroutines-core/test/linearizability/LockFreeListLinearizabilityTest.kt

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33
*/
44
@file:Suppress("unused")
55

6-
package kotlinx.coroutines.internal
6+
package kotlinx.coroutines.linearizability
77

88
import com.devexperts.dxlab.lincheck.*
99
import com.devexperts.dxlab.lincheck.annotations.*
1010
import com.devexperts.dxlab.lincheck.paramgen.*
11-
import com.devexperts.dxlab.lincheck.stress.*
11+
import com.devexperts.dxlab.lincheck.strategy.stress.*
1212
import kotlinx.coroutines.*
13+
import kotlinx.coroutines.internal.*
1314
import kotlin.test.*
1415

1516
@Param(name = "value", gen = IntGen::class, conf = "1:3")
1617
class LockFreeListLinearizabilityTest : TestBase() {
1718
class Node(val value: Int): LockFreeLinkedListNode()
1819

19-
private lateinit var q: LockFreeLinkedListHead
20-
21-
@Reset
22-
fun resetList() {
23-
q = LockFreeLinkedListHead()
24-
}
20+
private val q: LockFreeLinkedListHead = LockFreeLinkedListHead()
2521

2622
@Operation
2723
fun addLast(@Param(name = "value") value: Int) {
@@ -52,10 +48,7 @@ class LockFreeListLinearizabilityTest : TestBase() {
5248
val options = StressOptions()
5349
.iterations(100)
5450
.invocationsPerIteration(1000 * stressTestMultiplier)
55-
.addThread(1, 2)
56-
.addThread(1, 2)
57-
.addThread(1, 2)
58-
.addThread(1, 2)
51+
.threads(4)
5952
LinChecker.check(LockFreeListLinearizabilityTest::class.java, options)
6053
}
6154
}

0 commit comments

Comments
 (0)