Skip to content

Commit

Permalink
Do not show clocks when they don't provide any useful information (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval authored Aug 1, 2024
1 parent 4753c39 commit 203abb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 34 deletions.
19 changes: 10 additions & 9 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/Reporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,22 +412,22 @@ private fun executionResultsRepresentation(
val scenario = failure.scenario

val initActorData = results.initResults.zip(scenario.initExecution).map { (result, actor) ->
ResultActorData(actor, result, exceptionStackTraces, null)
ResultActorData(0, actor, result, exceptionStackTraces, null)
}
val isIncorrectResultsFailure = failure is IncorrectResultsFailure
var hasClock = false
val parallelActorData = scenario.parallelExecution.mapIndexed { i, actors ->
actors.zip(results.parallelResultsWithClock[i]) { actor, resultWithClock ->
val parallelActorData = scenario.parallelExecution.mapIndexed { threadId, actors ->
actors.zip(results.parallelResultsWithClock[threadId]) { actor, resultWithClock ->
val hbClock = if (isIncorrectResultsFailure) resultWithClock.clockOnStart else null
if (hbClock != null && !hbClock.empty) {
if (hbClock != null && !hbClock.isEmpty(threadId)) {
hasClock = true
}
ResultActorData(actor, resultWithClock.result, exceptionStackTraces, hbClock)
ResultActorData(threadId, actor, resultWithClock.result, exceptionStackTraces, hbClock)
}
}
hasClock = isIncorrectResultsFailure && hasClock
val postActorData = results.postResults.zip(scenario.postExecution).map { (result, actor) ->
ResultActorData(actor, result, exceptionStackTraces, null)
ResultActorData(0, actor, result, exceptionStackTraces, null)
}
var executionHung: Boolean
val (initialExecutionHung, initialActorRepresentation) = executionResultsRepresentation(initActorData, failure)
Expand Down Expand Up @@ -458,18 +458,19 @@ private fun executionResultsRepresentation(


private data class ResultActorData(
val threadId: Int,
val actor: Actor,
val result: Result?,
val exceptionInfo: ExceptionNumberAndStacktrace? = null,
val hbClock: HBClock? = null
) {
constructor(actor: Actor, result: Result?, exceptionStackTraces: Map<Throwable, ExceptionNumberAndStacktrace>, hbClock: HBClock?)
: this(actor, result, (result as? ExceptionResult)?.let { exceptionStackTraces[it.throwable] }, hbClock)
constructor(threadId: Int, actor: Actor, result: Result?, exceptionStackTraces: Map<Throwable, ExceptionNumberAndStacktrace>, hbClock: HBClock?)
: this(threadId, actor, result, (result as? ExceptionResult)?.let { exceptionStackTraces[it.throwable] }, hbClock)

override fun toString(): String {
return "${actor}${result.toString().let { ": $it" }}" +
(exceptionInfo?.let { " #${it.number}" } ?: "") +
(hbClock?.takeIf { !it.empty }?.let { " $it" } ?: "")
(hbClock?.takeIf { !it.isEmpty(threadId) }?.let { " $it" } ?: "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import org.jetbrains.kotlinx.lincheck.Result

data class HBClock(val clock: IntArray) {
val threads: Int get() = clock.size
val empty: Boolean get() = clock.all { it == 0 }

operator fun get(i: Int) = clock[i]

/**
* Checks whether the clock contains information for any thread
* excluding the one this clock is associated with.
*/
fun isEmpty(clockThreadId: Int) = clock.filterIndexed { t, _ -> t != clockThreadId }.all { it == 0 }

override fun toString() = clock.joinToString(prefix = "[", separator = ",", postfix = "]")

override fun equals(other: Any?): Boolean {
Expand Down
36 changes: 18 additions & 18 deletions src/jvm/test/resources/expected_logs/clocks_and_exceptions.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
= Invalid execution results =
| ----------------------------------------------------------------------- |
| Thread 1 | Thread 2 |
| ----------------------------------------------------------------------- |
| operation2(): void | |
| operation1(): void | |
| operation1(): void | |
| operation2(): void | |
| operation2(): void | |
| ----------------------------------------------------------------------- |
| operation1(): void | operation2(): IllegalStateException #1 [1,0] |
| operation1(): void [1,0] | operation1(): void [1,1] |
| ----------------------------------------------------------------------- |
| operation1(): void | |
| operation1(): void | |
| operation1(): void | |
| operation2(): void | |
| operation1(): void | |
| ----------------------------------------------------------------------- |
| ----------------------------------------------------------------- |
| Thread 1 | Thread 2 |
| ----------------------------------------------------------------- |
| operation2(): void | |
| operation1(): void | |
| operation1(): void | |
| operation2(): void | |
| operation2(): void | |
| ----------------------------------------------------------------- |
| operation1(): void | operation2(): IllegalStateException #1 [1,0] |
| operation1(): void | operation1(): void [1,1] |
| ----------------------------------------------------------------- |
| operation1(): void | |
| operation1(): void | |
| operation1(): void | |
| operation2(): void | |
| operation1(): void | |
| ----------------------------------------------------------------- |

---
All operations above the horizontal line | ----- | happen before those below the line
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
= Invalid execution results =
| ------------------------------ |
| Thread 1 | Thread 2 |
| ------------------------------ |
| a(): void | c(): void |
| b(): void [1,0] | d(): 0 [2,1] |
| ------------------------------ |
| ------------------------ |
| Thread 1 | Thread 2 |
| ------------------------ |
| a(): void | c(): void |
| b(): void | d(): 0 [2,1] |
| ------------------------ |

---
Values in "[..]" brackets indicate the number of completed operations
Expand Down

0 comments on commit 203abb4

Please sign in to comment.