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 | eab5c25 | 2017-11-20 11:43:45 +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 | eab5c25 | 2017-11-20 11:43:45 +0300 | [diff] [blame] | 13 | @OpGroupConfigs( |
| 14 | OpGroupConfig(name = "write", nonParallel = true), |
| 15 | OpGroupConfig(name = "read", nonParallel = true) |
| 16 | ) |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 17 | class BufferReleaseLinearizabilityTest : TestBase() { |
Sergey Mashkov | eab5c25 | 2017-11-20 11:43:45 +0300 | [diff] [blame] | 18 | private lateinit var ch: ByteChannel |
| 19 | |
| 20 | private val lr = LinTesting() |
| 21 | |
| 22 | @Reset |
| 23 | fun reset() { |
| 24 | ch = ByteChannel(false) |
| 25 | } |
| 26 | |
| 27 | @Operation(group = "read", runOnce = true) |
| 28 | fun read() = lr.run("read") { |
| 29 | ch.readLong() |
| 30 | } |
| 31 | |
| 32 | @Operation(group = "write", runOnce = true) |
| 33 | fun write() = lr.run("write") { |
| 34 | ch.writeLong(11111) |
| 35 | } |
| 36 | |
| 37 | @Operation |
| 38 | fun test1() = lr.run("isClosedForRead") { |
| 39 | ch.isClosedForRead |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | fun test() { |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 44 | val options = StressOptions() |
| 45 | .iterations(100) |
| 46 | .invocationsPerIteration(1000 * stressTestMultiplier) |
| 47 | .addThread(1, 2) |
| 48 | .addThread(1, 2) |
| 49 | LinChecker.check(BufferReleaseLinearizabilityTest::class.java, options) |
Sergey Mashkov | eab5c25 | 2017-11-20 11:43:45 +0300 | [diff] [blame] | 50 | } |
| 51 | } |