Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 5 | package kotlinx.coroutines.experimental.io |
| 6 | |
| 7 | import com.devexperts.dxlab.lincheck.* |
| 8 | import com.devexperts.dxlab.lincheck.annotations.* |
| 9 | import com.devexperts.dxlab.lincheck.paramgen.* |
| 10 | import com.devexperts.dxlab.lincheck.stress.* |
| 11 | import kotlinx.coroutines.experimental.* |
| 12 | import org.junit.* |
| 13 | |
Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 14 | @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 Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 19 | class ByteChannelLinearizabilityTest : TestBase() { |
Sergey Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 20 | 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 Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 60 | 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 Mashkov | 62deb43 | 2017-11-09 19:50:26 +0300 | [diff] [blame] | 68 | } |
| 69 | } |