-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a mechanism to provide the thread number as an operation parameter (
#47)
- Loading branch information
Showing
12 changed files
with
161 additions
and
121 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
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
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
79 changes: 0 additions & 79 deletions
79
src/main/java/org/jetbrains/kotlinx/lincheck/execution/ActorGenerator.java
This file was deleted.
Oops, something went wrong.
56 changes: 56 additions & 0 deletions
56
src/main/java/org/jetbrains/kotlinx/lincheck/execution/ActorGenerator.kt
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,56 @@ | ||
/*- | ||
* #%L | ||
* Lincheck | ||
* %% | ||
* Copyright (C) 2019 - 2020 JetBrains s.r.o. | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-3.0.html>. | ||
* #L% | ||
*/ | ||
package org.jetbrains.kotlinx.lincheck.execution | ||
|
||
import org.jetbrains.kotlinx.lincheck.* | ||
import org.jetbrains.kotlinx.lincheck.paramgen.* | ||
import java.lang.reflect.* | ||
import kotlin.random.* | ||
|
||
/** | ||
* Implementations of this class generate [actors][Actor] | ||
* using [parameter generators][ParameterGenerator]. | ||
*/ | ||
class ActorGenerator( | ||
private val method: Method, | ||
private val parameterGenerators: List<ParameterGenerator<*>>, | ||
private val handledExceptions: List<Class<out Throwable?>>, | ||
val useOnce: Boolean, | ||
cancellableOnSuspension: Boolean, | ||
val allowExtraSuspension: Boolean | ||
) { | ||
private val cancellableOnSuspension = cancellableOnSuspension && isSuspendable | ||
|
||
fun generate(threadId: Int): Actor { | ||
val parameters = parameterGenerators | ||
.map { it.generate() } | ||
.map { if (it === THREAD_ID_TOKEN) threadId else it } | ||
val cancelOnSuspension = cancellableOnSuspension and DETERMINISTIC_RANDOM.nextBoolean() | ||
return Actor(method, parameters, handledExceptions, | ||
cancelOnSuspension, allowExtraSuspension) | ||
} | ||
|
||
val isSuspendable: Boolean get() = method.isSuspendable() | ||
override fun toString() = method.toString() | ||
} | ||
|
||
private val DETERMINISTIC_RANDOM = Random(42) |
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/jetbrains/kotlinx/lincheck/paramgen/ThreadIdGen.kt
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,38 @@ | ||
/*- | ||
* #%L | ||
* Lincheck | ||
* %% | ||
* Copyright (C) 2019 - 2020 JetBrains s.r.o. | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-3.0.html>. | ||
* #L% | ||
*/ | ||
package org.jetbrains.kotlinx.lincheck.paramgen | ||
|
||
/** | ||
* This generator puts the number of the | ||
* executing thread as the parameter value. | ||
* The `0`-th thread specifies the init part | ||
* of the execution, while the `t+1`-th thread | ||
* references the post part (here we assume that | ||
* the parallel part has `t` threads). | ||
* | ||
* Note, that this API is unstable and is subject to change. | ||
*/ | ||
class ThreadIdGen(configuration: String) : ParameterGenerator<Any> { | ||
override fun generate() = THREAD_ID_TOKEN | ||
} | ||
|
||
internal val THREAD_ID_TOKEN = Any() |
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
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
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
Oops, something went wrong.