• 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 {
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) 200 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) 200 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         // All the bugs we have discovered so far
36         // were reproducible on at most 3 threads
37         .threads(3)
38         // 3 operations per thread is sufficient,
39         // while increasing this number declines
40         // the model checking coverage.
41         .actorsPerThread(if (isStressTest) 3 else 2)
42         .actorsAfter(if (isStressTest) 3 else 0)
43         .customize(isStressTest)
44 }
45