blob: ab6f8e8a120c76e37ff33a810798f2cff0f6f857 [file] [log] [blame]
Sergey Mashkov8b310cb2017-11-10 10:28:30 +03001package kotlinx.coroutines.experimental.io
2
3import com.devexperts.dxlab.lincheck.*
4import com.devexperts.dxlab.lincheck.annotations.*
5import com.devexperts.dxlab.lincheck.stress.*
6import kotlinx.coroutines.experimental.*
7import org.junit.*
8
Sergey Mashkov8b310cb2017-11-10 10:28:30 +03009@OpGroupConfigs(
10 OpGroupConfig(name = "write", nonParallel = true),
11 OpGroupConfig(name = "read1", nonParallel = true),
12 OpGroupConfig(name = "read2", nonParallel = true)
13)
Roman Elizarov6129c942018-01-10 17:34:40 +030014class ByteChannelJoinLinearizabilityTest : TestBase() {
Sergey Mashkov8b310cb2017-11-10 10:28:30 +030015 private lateinit var from: ByteChannel
16 private lateinit var to: ByteChannel
17
18 private val lr = LinTesting()
19
20 @Reset
21 fun reset() {
22// println("============== reset ====================")
23 from = ByteChannel(true)
24 to = ByteChannel(true)
25 }
26
27 @Operation(runOnce = true, group = "read1")
28 fun read() = lr.run("read") {
29 to.readLong()
30 }
31
32 @Operation(runOnce = true, group = "write")
33 fun write() = lr.run("write") {
34 from.writeLong(0x1122334455667788L)
35 }
36
37 @Operation(runOnce = true, group = "read2")
38 fun joinTo() = lr.run("join") {
39 from.joinTo(to, true)
40 }
41
42 @Test
43 fun test() {
Roman Elizarov6129c942018-01-10 17:34:40 +030044 val options = StressOptions()
45 .iterations(100)
46 .invocationsPerIteration(1000 * stressTestMultiplier)
47 .addThread(1, 1)
48 .addThread(1, 1)
49 .addThread(1, 1)
50 .verifier(LinVerifier::class.java)
51 LinChecker.check(ByteChannelJoinLinearizabilityTest::class.java, options)
Sergey Mashkov8b310cb2017-11-10 10:28:30 +030052 }
53}