blob: 5ba315a79d13c126b991f2c071759e0576b2ff55 [file] [log] [blame]
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03001/*
2 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
Sergey Mashkov9f9b72d2017-11-20 11:46:28 +03005package kotlinx.coroutines.experimental.io
6
7import com.devexperts.dxlab.lincheck.*
8import com.devexperts.dxlab.lincheck.annotations.*
9import com.devexperts.dxlab.lincheck.stress.*
10import kotlinx.coroutines.experimental.*
11import org.junit.*
12
Sergey Mashkov9f9b72d2017-11-20 11:46:28 +030013@OpGroupConfigs(
14 OpGroupConfig(name = "write", nonParallel = true),
15 OpGroupConfig(name = "read", nonParallel = true)
16)
Roman Elizarov6129c942018-01-10 17:34:40 +030017class WriteBlockLinearizabilityTest : TestBase() {
Sergey Mashkov9f9b72d2017-11-20 11:46:28 +030018 private lateinit var ch: ByteChannel
19
20 private val lr = LinTesting()
21
22 @Reset
23 fun reset() {
24 ch = ByteChannel(false)
25 runBlocking {
26 ch.writeLong(111)
27 }
28 }
29
30 @Operation(group = "read")
31 fun read() = lr.run("read") {
32 ch.readLong()
33 }
34
35 @Operation(group = "write")
36 fun write() = lr.run("write") {
37 ch.write(8) {
38 it.putLong(9699)
39 }
40 }
41
42 @Test
43 fun test() {
Roman Elizarov6129c942018-01-10 17:34:40 +030044 val options = StressOptions()
45 .iterations(100)
46 .invocationsPerIteration(1000 * stressTestMultiplier)
47 .addThread(1, 1)
48 .addThread(1, 1)
49 .verifier(LinVerifier::class.java)
50 LinChecker.check(WriteBlockLinearizabilityTest::class.java, options)
Sergey Mashkov9f9b72d2017-11-20 11:46:28 +030051 }
52}