blob: 6f8b9dc439cba248aa535bb00e199fb216e604d0 [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 Mashkov8b310cb2017-11-10 10:28:30 +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 Mashkov8b310cb2017-11-10 10:28:30 +030013@OpGroupConfigs(
14 OpGroupConfig(name = "write", nonParallel = true),
15 OpGroupConfig(name = "read1", nonParallel = true),
16 OpGroupConfig(name = "read2", nonParallel = true)
17)
Roman Elizarov6129c942018-01-10 17:34:40 +030018class ByteChannelJoinLinearizabilityTest : TestBase() {
Sergey Mashkov8b310cb2017-11-10 10:28:30 +030019 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 Elizarov6129c942018-01-10 17:34:40 +030048 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 Mashkov8b310cb2017-11-10 10:28:30 +030056 }
57}