blob: ec013d1c80164697357ad29fc18bbaa2d12334fd [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Sergey Mashkov62deb432017-11-09 19:50:26 +03005package kotlinx.coroutines.experimental.io
6
7import com.devexperts.dxlab.lincheck.*
8import com.devexperts.dxlab.lincheck.annotations.*
9import com.devexperts.dxlab.lincheck.paramgen.*
10import com.devexperts.dxlab.lincheck.stress.*
11import kotlinx.coroutines.experimental.*
12import org.junit.*
13
Sergey Mashkov62deb432017-11-09 19:50:26 +030014@Param(name = "value", gen = IntGen::class, conf = "1:8192")
15@OpGroupConfigs(
16 OpGroupConfig(name = "write", nonParallel = true),
17 OpGroupConfig(name = "read", nonParallel = true)
18)
Roman Elizarov6129c942018-01-10 17:34:40 +030019class ByteChannelLinearizabilityTest : TestBase() {
Sergey Mashkov62deb432017-11-09 19:50:26 +030020 private lateinit var channel: ByteChannel
21 private val lr = LinTesting()
22
23 @Reset
24 fun reset() {
25 channel = ByteChannel()
26 }
27
28 @Operation(runOnce = true, group = "write")
29 fun writeInt1(@Param(name = "value") value: Int) = lr.run("writeInt1") {
30 channel.writeInt(value)
31 }
32
33 @Operation(runOnce = true, group = "write")
34 fun writeInt2(@Param(name = "value") value: Int) = lr.run("writeInt2") {
35 channel.writeInt(value)
36 }
37
38 @Operation(runOnce = true, group = "read")
39 fun readInt1() = lr.run("readInt1") {
40 channel.readInt()
41 }
42
43 @Operation(runOnce = true, group = "read")
44 fun readInt2() = lr.run("readInt2") {
45 channel.readInt()
46 }
47
48 @Operation(group = "write")
49 fun close() = lr.run("close") {
50 channel.close()
51 }
52
53 @Operation
54 fun flush() = lr.run("flush") {
55 channel.flush()
56 }
57
58 @Test
59 fun test() {
Roman Elizarov6129c942018-01-10 17:34:40 +030060 val options = StressOptions()
61 .iterations(100)
62 .invocationsPerIteration(1000 * stressTestMultiplier)
63 .addThread(1, 1)
64 .addThread(1, 1)
65 .addThread(1, 1)
66 .verifier(LinVerifier::class.java)
67 LinChecker.check(ByteChannelLinearizabilityTest::class.java, options)
Sergey Mashkov62deb432017-11-09 19:50:26 +030068 }
69}