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 | 8b310cb | 2017-11-10 10:28:30 +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.stress.* |
| 10 | import kotlinx.coroutines.experimental.* |
| 11 | import org.junit.* |
| 12 | |
Sergey Mashkov | 8b310cb | 2017-11-10 10:28:30 +0300 | [diff] [blame] | 13 | @OpGroupConfigs( |
| 14 | OpGroupConfig(name = "write", nonParallel = true), |
| 15 | OpGroupConfig(name = "read1", nonParallel = true), |
| 16 | OpGroupConfig(name = "read2", nonParallel = true) |
| 17 | ) |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 18 | class ByteChannelJoinLinearizabilityTest : TestBase() { |
Sergey Mashkov | 8b310cb | 2017-11-10 10:28:30 +0300 | [diff] [blame] | 19 | private lateinit var from: ByteChannel |
| 20 | private lateinit var to: ByteChannel |
| 21 | |
| 22 | private val lr = LinTesting() |
| 23 | |
| 24 | @Reset |
| 25 | fun reset() { |
| 26 | // println("============== reset ====================") |
| 27 | from = ByteChannel(true) |
| 28 | to = ByteChannel(true) |
| 29 | } |
| 30 | |
| 31 | @Operation(runOnce = true, group = "read1") |
| 32 | fun read() = lr.run("read") { |
| 33 | to.readLong() |
| 34 | } |
| 35 | |
| 36 | @Operation(runOnce = true, group = "write") |
| 37 | fun write() = lr.run("write") { |
| 38 | from.writeLong(0x1122334455667788L) |
| 39 | } |
| 40 | |
| 41 | @Operation(runOnce = true, group = "read2") |
| 42 | fun joinTo() = lr.run("join") { |
| 43 | from.joinTo(to, true) |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | fun test() { |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 48 | val options = StressOptions() |
| 49 | .iterations(100) |
| 50 | .invocationsPerIteration(1000 * stressTestMultiplier) |
| 51 | .addThread(1, 1) |
| 52 | .addThread(1, 1) |
| 53 | .addThread(1, 1) |
| 54 | .verifier(LinVerifier::class.java) |
| 55 | LinChecker.check(ByteChannelJoinLinearizabilityTest::class.java, options) |
Sergey Mashkov | 8b310cb | 2017-11-10 10:28:30 +0300 | [diff] [blame] | 56 | } |
| 57 | } |