File tree 3 files changed +67
-1
lines changed
kotlinx-coroutines-core/jvm/test/linearizability
3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ junit_version=4.12
12
12
atomicfu_version =0.14.2
13
13
knit_version =0.1.3
14
14
html_version =0.6.8
15
- lincheck_version =2.5.3
15
+ lincheck_version =2.6
16
16
dokka_version =0.9.16-rdev-2-mpp-hacks
17
17
byte_buddy_version =1.9.3
18
18
reactor_vesion =3.2.5.RELEASE
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+ @file:Suppress(" unused" )
5
+ package kotlinx.coroutines.linearizability
6
+
7
+ import kotlinx.coroutines.*
8
+ import kotlinx.coroutines.sync.*
9
+ import org.jetbrains.kotlinx.lincheck.annotations.Operation
10
+ import org.jetbrains.kotlinx.lincheck.verifier.*
11
+ import org.junit.*
12
+
13
+ class MutexLCStressTest : VerifierState () {
14
+ private val mutex = Mutex ()
15
+
16
+ @Operation
17
+ fun tryLock () = mutex.tryLock()
18
+
19
+ @Operation(cancellableOnSuspension = true )
20
+ suspend fun lock () = mutex.lock()
21
+
22
+ @Operation(handleExceptionsAsResult = [IllegalStateException ::class ])
23
+ fun unlock () = mutex.unlock()
24
+
25
+ @Test
26
+ fun test () = LCStressOptionsDefault ()
27
+ .actorsBefore(0 )
28
+ .check(this ::class )
29
+
30
+ override fun extractState () = mutex.isLocked
31
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+ @file:Suppress(" unused" )
5
+ package kotlinx.coroutines.linearizability
6
+
7
+ import kotlinx.coroutines.*
8
+ import kotlinx.coroutines.sync.*
9
+ import org.jetbrains.kotlinx.lincheck.annotations.Operation
10
+ import org.jetbrains.kotlinx.lincheck.verifier.*
11
+ import org.junit.*
12
+
13
+ abstract class SemaphoreLCStressTestBase (permits : Int ) : VerifierState() {
14
+ private val semaphore = Semaphore (permits)
15
+
16
+ // @Operation
17
+ fun tryAcquire () = semaphore.tryAcquire()
18
+
19
+ @Operation(cancellableOnSuspension = true )
20
+ suspend fun acquire () = semaphore.acquire()
21
+
22
+ @Operation(handleExceptionsAsResult = [IllegalStateException ::class ])
23
+ fun release () = semaphore.release()
24
+
25
+ @Test
26
+ fun test () = LCStressOptionsDefault ()
27
+ .actorsBefore(0 )
28
+ .check(this ::class )
29
+
30
+ override fun extractState () = semaphore.availablePermits
31
+ }
32
+
33
+ class Semaphore1LCStressTest : SemaphoreLCStressTestBase (1 )
34
+ class Semaphore2LCStressTest : SemaphoreLCStressTestBase (2 )
35
+ class Semaphore4LCStressTest : SemaphoreLCStressTestBase (4 )
You can’t perform that action at this time.
0 commit comments