blob: 0d61cc8979c8ad8eed1e93162e12239d7e1b4031 [file] [log] [blame]
Sergey Mashkov62deb432017-11-09 19:50:26 +03001package kotlinx.coroutines.experimental.io
2
3import com.devexperts.dxlab.lincheck.*
4import com.devexperts.dxlab.lincheck.annotations.*
5import com.devexperts.dxlab.lincheck.paramgen.*
6import com.devexperts.dxlab.lincheck.stress.*
7import kotlinx.coroutines.experimental.*
8import org.junit.*
9
Sergey Mashkov62deb432017-11-09 19:50:26 +030010@Param(name = "value", gen = IntGen::class, conf = "1:8192")
11@OpGroupConfigs(
12 OpGroupConfig(name = "write", nonParallel = true),
13 OpGroupConfig(name = "read", nonParallel = true)
14)
Roman Elizarov6129c942018-01-10 17:34:40 +030015class ByteChannelLinearizabilityTest : TestBase() {
Sergey Mashkov62deb432017-11-09 19:50:26 +030016 private lateinit var channel: ByteChannel
17 private val lr = LinTesting()
18
19 @Reset
20 fun reset() {
21 channel = ByteChannel()
22 }
23
24 @Operation(runOnce = true, group = "write")
25 fun writeInt1(@Param(name = "value") value: Int) = lr.run("writeInt1") {
26 channel.writeInt(value)
27 }
28
29 @Operation(runOnce = true, group = "write")
30 fun writeInt2(@Param(name = "value") value: Int) = lr.run("writeInt2") {
31 channel.writeInt(value)
32 }
33
34 @Operation(runOnce = true, group = "read")
35 fun readInt1() = lr.run("readInt1") {
36 channel.readInt()
37 }
38
39 @Operation(runOnce = true, group = "read")
40 fun readInt2() = lr.run("readInt2") {
41 channel.readInt()
42 }
43
44 @Operation(group = "write")
45 fun close() = lr.run("close") {
46 channel.close()
47 }
48
49 @Operation
50 fun flush() = lr.run("flush") {
51 channel.flush()
52 }
53
54 @Test
55 fun test() {
Roman Elizarov6129c942018-01-10 17:34:40 +030056 val options = StressOptions()
57 .iterations(100)
58 .invocationsPerIteration(1000 * stressTestMultiplier)
59 .addThread(1, 1)
60 .addThread(1, 1)
61 .addThread(1, 1)
62 .verifier(LinVerifier::class.java)
63 LinChecker.check(ByteChannelLinearizabilityTest::class.java, options)
Sergey Mashkov62deb432017-11-09 19:50:26 +030064 }
65}