Skip to content

Commit 475c043

Browse files
committed
LockFreeListLinearizabilityTest using Lincheck
1 parent ee9289b commit 475c043

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

kotlinx-coroutines-core/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@
3333
<kotlin.compiler.jdkHome>${env.JDK_16}</kotlin.compiler.jdkHome>
3434
</properties>
3535

36+
<repositories>
37+
<repository>
38+
<id>bintray-devexperts</id>
39+
<url>https://dl.bintray.com/devexperts/Maven/</url>
40+
</repository>
41+
</repositories>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>com.devexperts.lincheck</groupId>
46+
<artifactId>core</artifactId>
47+
<version>1.8.1</version>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
3652
<build>
3753
<sourceDirectory>src/main/kotlin</sourceDirectory>
3854
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2016-2017 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package kotlinx.coroutines.experimental.internal
18+
19+
import com.devexperts.dxlab.lincheck.LinChecker
20+
import com.devexperts.dxlab.lincheck.annotations.CTest
21+
import com.devexperts.dxlab.lincheck.annotations.Operation
22+
import com.devexperts.dxlab.lincheck.annotations.Param
23+
import com.devexperts.dxlab.lincheck.annotations.Reset
24+
import com.devexperts.dxlab.lincheck.generators.IntGen
25+
import org.junit.Test
26+
27+
28+
@CTest(iterations = 100, actorsPerThread = arrayOf("1:2", "1:2", "1:2", "1:2"))
29+
@Param(name = "value", gen = IntGen::class, conf = "1:3")
30+
class LockFreeListLinearizabilityTest {
31+
class Node(val value: Int): LockFreeLinkedListNode()
32+
33+
lateinit var q: LockFreeLinkedListHead
34+
35+
@Reset
36+
fun reset() {
37+
q = LockFreeLinkedListHead()
38+
}
39+
40+
@Operation
41+
fun addLast(@Param(name = "value") value: Int) {
42+
q.addLast(Node(value))
43+
}
44+
45+
@Operation
46+
fun addLastIfNotSame(@Param(name = "value") value: Int) {
47+
q.addLastIfPrev(Node(value)) { !it.isSame(value) }
48+
}
49+
50+
@Operation
51+
fun removeFirst(): Int? {
52+
val node = q.removeFirstOrNull() ?: return null
53+
return (node as Node).value
54+
}
55+
56+
@Operation
57+
fun removeFirstOrPeekIfNotSame(@Param(name = "value") value: Int): Int? {
58+
val node = q.removeFirstIfIsInstanceOfOrPeekIf<Node> { !it.isSame(value) } ?: return null
59+
return (node as Node).value
60+
}
61+
62+
fun Any.isSame(value: Int) = this is Node && this.value == value
63+
64+
@Test
65+
fun testAddRemoveLinearizability() {
66+
LinChecker.check(this)
67+
}
68+
}

0 commit comments

Comments
 (0)