Sergey Mashkov | 9f9b72d | 2017-11-20 11:46:28 +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.stress.* |
| 6 | import kotlinx.coroutines.experimental.* |
| 7 | import org.junit.* |
| 8 | |
Sergey Mashkov | 9f9b72d | 2017-11-20 11:46:28 +0300 | [diff] [blame] | 9 | @OpGroupConfigs( |
| 10 | OpGroupConfig(name = "write", nonParallel = true), |
| 11 | OpGroupConfig(name = "read", nonParallel = true) |
| 12 | ) |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 13 | class WriteBlockLinearizabilityTest : TestBase() { |
Sergey Mashkov | 9f9b72d | 2017-11-20 11:46:28 +0300 | [diff] [blame] | 14 | private lateinit var ch: ByteChannel |
| 15 | |
| 16 | private val lr = LinTesting() |
| 17 | |
| 18 | @Reset |
| 19 | fun reset() { |
| 20 | ch = ByteChannel(false) |
| 21 | runBlocking { |
| 22 | ch.writeLong(111) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | @Operation(group = "read") |
| 27 | fun read() = lr.run("read") { |
| 28 | ch.readLong() |
| 29 | } |
| 30 | |
| 31 | @Operation(group = "write") |
| 32 | fun write() = lr.run("write") { |
| 33 | ch.write(8) { |
| 34 | it.putLong(9699) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | @Test |
| 39 | fun test() { |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 40 | val options = StressOptions() |
| 41 | .iterations(100) |
| 42 | .invocationsPerIteration(1000 * stressTestMultiplier) |
| 43 | .addThread(1, 1) |
| 44 | .addThread(1, 1) |
| 45 | .verifier(LinVerifier::class.java) |
| 46 | LinChecker.check(WriteBlockLinearizabilityTest::class.java, options) |
Sergey Mashkov | 9f9b72d | 2017-11-20 11:46:28 +0300 | [diff] [blame] | 47 | } |
| 48 | } |