-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package stack | ||
|
||
import org.jetbrains.kotlinx.lincheck.annotations.Operation | ||
import org.jetbrains.kotlinx.lincheck.check | ||
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.ModelCheckingOptions | ||
import org.jetbrains.kotlinx.lincheck.strategy.stress.StressOptions | ||
import stack.common.ConcurrentStack | ||
import stack.simple.ConcurrentTreiberStack | ||
import kotlin.test.Test | ||
|
||
abstract class ConcurrentStackTests(private val stack: ConcurrentStack<Int>) { | ||
@Operation | ||
fun push(value: Int) = stack.push(value) | ||
|
||
@Operation | ||
fun pop(): Int? = stack.pop() | ||
|
||
@Operation | ||
fun top(): Int? = stack.top() | ||
|
||
@Test | ||
fun stressTest() = StressOptions() | ||
.sequentialSpecification(SequentialStack::class.java) | ||
.check(this::class) | ||
|
||
@Test | ||
fun fourThreadsStressTest() = StressOptions() | ||
.sequentialSpecification(SequentialStack::class.java) | ||
.threads(4) | ||
.iterations(50) | ||
.invocationsPerIteration(1000) | ||
.check(this::class) | ||
|
||
@Test | ||
fun modelCheckingTest() = ModelCheckingOptions() | ||
.sequentialSpecification(SequentialStack::class.java) | ||
.checkObstructionFreedom() | ||
.check(this::class) | ||
|
||
@Test | ||
fun fourThreadsModelCheckingTest() = ModelCheckingOptions() | ||
.sequentialSpecification(SequentialStack::class.java) | ||
.checkObstructionFreedom() | ||
.threads(4) | ||
.iterations(50) | ||
.invocationsPerIteration(1000) | ||
.check(this::class) | ||
} | ||
|
||
class ConcurrentTreiberStackTests : ConcurrentStackTests(ConcurrentTreiberStack()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package stack | ||
|
||
class SequentialStack { | ||
private val deque = ArrayDeque<Int>() | ||
|
||
fun push(x: Int) = deque.addLast(x) | ||
|
||
fun pop(): Int? = deque.removeLastOrNull() | ||
|
||
fun top(): Int? = deque.lastOrNull() | ||
} |