Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 1 | package kotlinx.coroutines.experimental.io |
| 2 | |
| 3 | import com.devexperts.dxlab.lincheck.* |
| 4 | import com.devexperts.dxlab.lincheck.annotations.* |
| 5 | import com.devexperts.dxlab.lincheck.paramgen.* |
| 6 | import com.devexperts.dxlab.lincheck.stress.* |
| 7 | import kotlinx.coroutines.experimental.* |
| 8 | import org.junit.* |
| 9 | |
Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 10 | @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 Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 15 | class ByteChannelLinearizabilityTest : TestBase() { |
Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 16 | 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 Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 56 | 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 Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 64 | } |
| 65 | } |