Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | package kotlinx.coroutines.experimental.internal |
| 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.* |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 11 | import kotlinx.coroutines.experimental.* |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 12 | import kotlin.test.* |
| 13 | |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 14 | @OpGroupConfigs(OpGroupConfig(name = "consumer", nonParallel = true)) |
| 15 | @Param(name = "value", gen = IntGen::class, conf = "1:3") |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 16 | class LockFreeMPSCQueueLinearizabilityTest : TestBase() { |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 17 | private lateinit var q: LockFreeMPSCQueue<Int> |
| 18 | |
| 19 | @Reset |
| 20 | fun reset() { |
| 21 | q = LockFreeMPSCQueue() |
| 22 | } |
| 23 | |
| 24 | @Operation |
| 25 | fun close() = q.close() |
| 26 | |
| 27 | @Operation |
| 28 | fun addLast(@Param(name = "value") value: Int) = q.addLast(value) |
| 29 | |
Roman Elizarov | e873c0a | 2018-01-10 18:26:57 +0300 | [diff] [blame] | 30 | /** |
| 31 | * Note, that removeFirstOrNull is not linearizable w.r.t. to addLast, so here |
| 32 | * we test only linearizability of close. |
| 33 | */ |
| 34 | // @Operation(group = "consumer") |
| 35 | // fun removeFirstOrNull() = q.removeFirstOrNull() |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 36 | |
| 37 | @Test |
| 38 | fun testLinearizability() { |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 39 | val options = StressOptions() |
Roman Elizarov | e873c0a | 2018-01-10 18:26:57 +0300 | [diff] [blame] | 40 | .iterations(100 * stressTestMultiplierSqrt) |
| 41 | .invocationsPerIteration(1000 * stressTestMultiplierSqrt) |
Roman Elizarov | 6129c94 | 2018-01-10 17:34:40 +0300 | [diff] [blame] | 42 | .addThread(1, 3) |
| 43 | .addThread(1, 3) |
| 44 | .addThread(1, 3) |
| 45 | LinChecker.check(LockFreeMPSCQueueLinearizabilityTest::class.java, options) |
Roman Elizarov | 5d94a26 | 2017-12-28 00:23:39 +0300 | [diff] [blame] | 46 | } |
| 47 | } |