Skip to content

Commit

Permalink
Remove access calls from trace (for function accesses only). #537
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrockbernd committed Feb 20, 2025
1 parent b7b2588 commit f51afaf
Show file tree
Hide file tree
Showing 9 changed files with 1,500 additions and 14,564 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ private fun compressCallStackTrace(
}

// Check if current and next are a "default" combo
if (currentElement.tracePoint.methodName == "${nextElement.tracePoint.methodName}\$default") {

if (isCompressiblePair(currentElement.tracePoint.methodName, nextElement.tracePoint.methodName)) {
// Combine fields of next and current, and store in current
currentElement.tracePoint.methodName = nextElement.tracePoint.methodName
currentElement.tracePoint.parameters = nextElement.tracePoint.parameters
Expand Down Expand Up @@ -468,6 +467,22 @@ private fun actorNodeResultRepresentation(result: Result?, failure: LincheckFail
}
}

/**
* Default pair example:
* ```
* A.calLMe$default(A#1, 3, null, 2, null) at A.operation(A.kt:23)
* A.callMe(3, "Hey") at A.callMe$default(A.kt:27)
*```
* Access pair example:
* ```
* A.access$callMe() at A.operation(A.kt:N)
* A.callMe() at A.callMe$default(A.kt:N)
*```
*/
private fun isCompressiblePair(currentName: String, nextName: String): Boolean =
currentName == "${nextName}\$default" || currentName == "access$${nextName}"


/**
* Helper class to provider execution results, including a validation function result
*/
Expand Down Expand Up @@ -848,7 +863,6 @@ private class TraceNodePrefixFactory(nThreads: Int) {

private const val TRACE_INDENTATION = " "


internal class TraceEventRepresentation(val iThread: Int, val representation: String)

const val TRACE_TITLE = "The following interleaving leads to the error:"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck_test.representation

class AccessFunctionRepresentationTest: BaseRunConcurrentRepresentationTest<Unit>("access_function_representation_test.txt") {

@Volatile
private var a = 0

override fun block() {
runn { inc() }
check(false)
}

private fun inc() {
Nested().inc2()
}

private fun inc3() {
a++
}
private inner class Nested {
fun inc2() {
inc3()
}

}
}

fun runn(r: () -> Unit) {
r()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
= Concurrent test failed =

java.lang.IllegalStateException: Check failed.
at org.jetbrains.kotlinx.lincheck_test.representation.AccessFunctionRepresentationTest.block(AccessFunctionRepresentationTest.kt:20)
at org.jetbrains.kotlinx.lincheck_test.representation.AccessFunctionRepresentationTest.block(AccessFunctionRepresentationTest.kt:13)
at org.jetbrains.kotlinx.lincheck_test.representation.BaseRunConcurrentRepresentationTest$testRunWithModelChecker$result$1$1.invoke(RunConcurrentRepresentationTests.kt:40)
at java.base/java.lang.Thread.run(Thread.java:840)

The following interleaving leads to the error:
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Thread 1 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| AccessFunctionRepresentationTest#1.block(): threw IllegalStateException at BaseRunConcurrentRepresentationTest$testRunWithModelChecker$result$1$1.invoke(RunConcurrentRepresentationTests.kt:40) |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

Detailed trace:
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Thread 1 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| AccessFunctionRepresentationTest#1.block(): threw IllegalStateException at BaseRunConcurrentRepresentationTest$testRunWithModelChecker$result$1$1.invoke(RunConcurrentRepresentationTests.kt:40) |
| block(): threw IllegalStateException at AccessFunctionRepresentationTest.block(AccessFunctionRepresentationTest.kt:13) |
| AccessFunctionRepresentationTestKt.runn(block$1) at AccessFunctionRepresentationTest.block(AccessFunctionRepresentationTest.kt:19) |
| block$1.invoke() at AccessFunctionRepresentationTestKt.runn(AccessFunctionRepresentationTest.kt:39) |
| invoke() at AccessFunctionRepresentationTest$block$1.invoke(AccessFunctionRepresentationTest.kt:19) |
| AccessFunctionRepresentationTest.inc() at AccessFunctionRepresentationTest$block$1.invoke(AccessFunctionRepresentationTest.kt:19) |
| Nested#1.inc2() at AccessFunctionRepresentationTest.inc(AccessFunctionRepresentationTest.kt:24) |
| AccessFunctionRepresentationTest.inc3() at AccessFunctionRepresentationTest$Nested.inc2(AccessFunctionRepresentationTest.kt:32) |
| a ➜ 1 at AccessFunctionRepresentationTest.inc3(AccessFunctionRepresentationTest.kt:28) |
| a = 2 at AccessFunctionRepresentationTest.inc3(AccessFunctionRepresentationTest.kt:28) |
| result: IllegalStateException #1 |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Loading

0 comments on commit f51afaf

Please sign in to comment.