Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
| 5 | @file:Suppress("unused") |
| 6 | |
Aurimas Liutikas | c8879d6 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 7 | package kotlinx.coroutines.linearizability |
Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 8 | |
| 9 | import kotlinx.coroutines.* |
| 10 | import kotlinx.coroutines.internal.* |
| 11 | import org.jetbrains.kotlinx.lincheck.annotations.* |
Aurimas Liutikas | c8879d6 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 12 | import org.jetbrains.kotlinx.lincheck.annotations.Operation |
Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 13 | import org.jetbrains.kotlinx.lincheck.paramgen.* |
Aurimas Liutikas | c8879d6 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 14 | import org.jetbrains.kotlinx.lincheck.verifier.* |
| 15 | import org.junit.* |
Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 16 | |
Aurimas Liutikas | c8879d6 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 17 | |
| 18 | class SegmentListRemoveLCStressTest : VerifierState() { |
Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 19 | private val q = SegmentBasedQueue<Int>() |
| 20 | private val segments: Array<OneElementSegment<Int>> |
| 21 | |
| 22 | init { |
| 23 | segments = (0..5).map { q.enqueue(it)!! }.toTypedArray() |
| 24 | q.enqueue(6) |
| 25 | } |
| 26 | |
| 27 | @Operation |
| 28 | fun removeSegment(@Param(gen = IntGen::class, conf = "1:5") index: Int) { |
| 29 | segments[index].removeSegment() |
| 30 | } |
| 31 | |
| 32 | override fun extractState() = segments.map { it.logicallyRemoved } |
| 33 | |
| 34 | @Validate |
| 35 | fun checkAllRemoved() { |
| 36 | q.checkHeadPrevIsCleaned() |
| 37 | q.checkAllSegmentsAreNotLogicallyRemoved() |
| 38 | } |
| 39 | |
Aurimas Liutikas | c8879d6 | 2021-05-12 21:56:16 +0000 | [diff] [blame^] | 40 | @Test |
| 41 | fun test() = LCStressOptionsDefault() |
| 42 | .actorsBefore(0) |
| 43 | .actorsAfter(0) |
| 44 | .check(this::class) |
Nikita Koval | 515e86a | 2020-04-28 11:30:04 +0300 | [diff] [blame] | 45 | } |