From 9d3191b951b7b1fdaadc7a102b52b9ff7d8979d9 Mon Sep 17 00:00:00 2001 From: Nikita Koval Date: Tue, 16 Apr 2024 10:34:40 +0100 Subject: [PATCH] Ignore coroutine internals --- .../kotlinx/lincheck/strategy/managed/ManagedStrategy.kt | 4 ++++ .../lincheck/transformation/LincheckClassVisitor.kt | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ManagedStrategy.kt b/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ManagedStrategy.kt index 22cb9a356..73f0279ac 100644 --- a/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ManagedStrategy.kt +++ b/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/ManagedStrategy.kt @@ -834,6 +834,10 @@ abstract class ManagedStrategy( } private fun methodGuaranteeType(owner: Any?, className: String, methodName: String): ManagedGuaranteeType? = runInIgnoredSection { + // Treat `CancellableContinuation + if (owner is CancellableContinuation<*> && (methodName == "tryResume" || methodName == "completeResume")) { + return ManagedGuaranteeType.TREAT_AS_ATOMIC + } userDefinedGuarantees?.forEach { guarantee -> val ownerName = owner?.javaClass?.canonicalName ?: className if (guarantee.classPredicate(ownerName) && guarantee.methodPredicate(methodName)) { diff --git a/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckClassVisitor.kt b/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckClassVisitor.kt index e882c5a4c..0033b08a4 100644 --- a/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckClassVisitor.kt +++ b/src/jvm/main/org/jetbrains/kotlinx/lincheck/transformation/LincheckClassVisitor.kt @@ -91,11 +91,16 @@ internal class LincheckClassVisitor( } } if (methodName == "" || + // Ignore coroutine internals unrelated to testing. + className == "kotlinx/coroutines/CancellableContinuationImpl" && methodName == "initCancellability" || + className == "kotlinx/coroutines/CancellableContinuationImpl" && methodName == "detachChildIfNonResuable" || + className == "kotlinx/coroutines/CancellableContinuationImpl" && methodName == "dispatchResume" || // Debugger implicitly evaluates toString for variables rendering // We need to disable breakpoints in such a case, as the numeration will break. // Breakpoints are disabled as we do not instrument toString and enter an ignored section, // so there are no beforeEvents inside. - ideaPluginEnabled && methodName == "toString" && desc == "()Ljava/lang/String;") { + ideaPluginEnabled && methodName == "toString" && desc == "()Ljava/lang/String;") + { mv = WrapMethodInIgnoredSectionTransformer(methodName, GeneratorAdapter(mv, access, methodName, desc)) return mv }