• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 package kotlinx.coroutines
5 
6 import org.jetbrains.kotlinx.lincheck.*
7 import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.*
8 import org.jetbrains.kotlinx.lincheck.strategy.stress.*
9 import org.jetbrains.kotlinx.lincheck.verifier.*
10 import org.junit.*
11 
12 abstract class AbstractLincheckTest : VerifierState() {
customizenull13     open fun <O: Options<O, *>> O.customize(isStressTest: Boolean): O = this
14     open fun ModelCheckingOptions.customize(isStressTest: Boolean): ModelCheckingOptions = this
15     open fun StressOptions.customize(isStressTest: Boolean): StressOptions = this
16 
17     @Test
18     fun modelCheckingTest() = ModelCheckingOptions()
19         .iterations(if (isStressTest) 100 else 20)
20         .invocationsPerIteration(if (isStressTest) 10_000 else 1_000)
21         .commonConfiguration()
22         .customize(isStressTest)
23         .check(this::class)
24 
25     @Test
26     fun stressTest() = StressOptions()
27         .iterations(if (isStressTest) 100 else 20)
28         .invocationsPerIteration(if (isStressTest) 10_000 else 1_000)
29         .commonConfiguration()
30         .customize(isStressTest)
31         .check(this::class)
32 
33     private fun <O : Options<O, *>> O.commonConfiguration(): O = this
34         .actorsBefore(if (isStressTest) 3 else 1)
35         .threads(3)
36         .actorsPerThread(if (isStressTest) 4 else 2)
37         .actorsAfter(if (isStressTest) 3 else 0)
38         .customize(isStressTest)
39 
40     override fun extractState(): Any = error("Not implemented")
41 }
42