blob: c08e109db37fb46b9a3d098f4e6dff1db91e865f [file] [log] [blame]
Roman Elizarov5d94a262017-12-28 00:23:39 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarov5d94a262017-12-28 00:23:39 +03003 */
4
5package kotlinx.coroutines.experimental.internal
6
7import com.devexperts.dxlab.lincheck.*
8import com.devexperts.dxlab.lincheck.annotations.*
9import com.devexperts.dxlab.lincheck.paramgen.*
10import com.devexperts.dxlab.lincheck.stress.*
Roman Elizarov6129c942018-01-10 17:34:40 +030011import kotlinx.coroutines.experimental.*
Roman Elizarov5d94a262017-12-28 00:23:39 +030012import kotlin.test.*
13
Roman Elizarov5d94a262017-12-28 00:23:39 +030014@OpGroupConfigs(OpGroupConfig(name = "consumer", nonParallel = true))
15@Param(name = "value", gen = IntGen::class, conf = "1:3")
Roman Elizarov6129c942018-01-10 17:34:40 +030016class LockFreeMPSCQueueLinearizabilityTest : TestBase() {
Roman Elizarov5d94a262017-12-28 00:23:39 +030017 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 Elizarove873c0a2018-01-10 18:26:57 +030030 /**
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 Elizarov5d94a262017-12-28 00:23:39 +030036
37 @Test
38 fun testLinearizability() {
Roman Elizarov6129c942018-01-10 17:34:40 +030039 val options = StressOptions()
Roman Elizarove873c0a2018-01-10 18:26:57 +030040 .iterations(100 * stressTestMultiplierSqrt)
41 .invocationsPerIteration(1000 * stressTestMultiplierSqrt)
Roman Elizarov6129c942018-01-10 17:34:40 +030042 .addThread(1, 3)
43 .addThread(1, 3)
44 .addThread(1, 3)
45 LinChecker.check(LockFreeMPSCQueueLinearizabilityTest::class.java, options)
Roman Elizarov5d94a262017-12-28 00:23:39 +030046 }
47}