-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft API for the general-purpose model checker #411
Conversation
@dmitrii-artuhov thanks for the PR. |
9e0d1fa
to
426aa8a
Compare
src/jvm/main/org/jetbrains/kotlinx/lincheck/CTestConfiguration.kt
Outdated
Show resolved
Hide resolved
...rg/jetbrains/kotlinx/lincheck_test/representation/AtomicReferencesNamesRunWithLambdaTests.kt
Outdated
Show resolved
Hide resolved
...11/org/jetbrains/kotlinx/lincheck_test/representation/BaseRunWithLambdaRepresentationTest.kt
Outdated
Show resolved
Hide resolved
...11/org/jetbrains/kotlinx/lincheck_test/representation/BaseRunWithLambdaRepresentationTest.kt
Outdated
Show resolved
Hide resolved
...jdk11/org/jetbrains/kotlinx/lincheck_test/representation/RunWithLambdaRepresentationTests.kt
Outdated
Show resolved
Hide resolved
91168ea
to
0c0e25c
Compare
@eupp I added the |
Let's please revert this change. The API should be as simple as it could be, that is the point why we adding it. It should only take the lambda to run and that's it.
To make the test work with only the lambda, please remove any state of the test class by either:
Use one method or another, depending on which makes more sense for a particular test. This way we will eliminate any "external" state outside lambda (except static state, but it will be handled by the snapshot tracker). In general, there is indeed a problem here --- the problem is that the lambda that we pass to the model checker should not capture any state, in order to be deterministically reproducible. One of possible solutions is similar to what you propose --- to force the user to explicitly mention all captured objects as method parameters. But we need to discuss this solution and how to express it in the API in more detail before implementing it. |
3c3d5d8
to
951e45a
Compare
The task to add support for thread pools turned out to be more challenging than anticipated, and it required non-trivial changes. I transferred it into separate PR so we can review and discuss that code separately: #447 |
I've tried to add tests with coroutines, using custom thread pool as a dispacther, using But it seems I run into bug #404 with this test, so I am going to try debug and fix it first. |
val strategy = testCfg.createStrategy(GeneralPurposeMCWrapper::class.java, scenario, null, null) | ||
val verifier = testCfg.createVerifier() | ||
|
||
for (i in 1..invocations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to implement this logic again? Can't we just call options.checkImpl
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, just using options.checkImpl
currently does not work.
The problem is that we need to manually trigger the instrumentation of the passed lambda class:
ensureObjectIsTransformed(block)
Otherwise, it is not triggered automatically, with the current implementation of ensureObjectIsTransformed
and ensureClassHierarchyIsTransformed
. This is because instead of the lambda itself, we pass the GeneralPurposeModelCheckingWrapper
object to make the whole thing work with the scenario-based Lincheck API. So only this class is transformed. Because this class does not store block
lambda in any of its fields, but instead is passed as actor argument, its instrumentation is not triggered automatically.
I propose we implement the required refactoring in a separate PR, because it would touch a lot of places in the code (LinChecker.kt
, runners, managed strategy, LincheckJavaAgent
, etc).
In a meantime, I changed the code to use Strategy.runIteration
. It is not as good, but still simplifies the code and avoids unnecessary duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would storing the lambda in GeneralPurposeModelCheckingWrapper
solve the issue and simplify the logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see why not -- GeneralPurposeModelCheckingWrapper
must have an empty constructor.
*/ | ||
fun <R> runConcurrentTest( | ||
invocations: Int = DEFAULT_INVOCATIONS_COUNT, | ||
block: () -> R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test on Java, with and without invocations
, to check the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, using this API from Java is currently unsupported due to technical limitations: #445
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, so let's ignore the test. However, we need to see what the code looks like in Java.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: as we are not working on the API now, we can postpone this question.
.../test/org/jetbrains/kotlinx/lincheck_test/representation/RunWithLambdaRepresentationTests.kt
Outdated
Show resolved
Hide resolved
...m/test/org/jetbrains/kotlinx/lincheck_test/representation/CustomThreadsRepresentationTest.kt
Show resolved
Hide resolved
src/jvm/test/resources/expected_logs/array_rw_run_with_lambda.txt
Outdated
Show resolved
Hide resolved
src/jvm/test/resources/expected_logs/array_rw_run_with_lambda.txt
Outdated
Show resolved
Hide resolved
…yWithModelChecking' call
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
5ef8842
to
ba7d010
Compare
src/jvm/test/resources/expected_logs/run_concurrent_test/array_rw.txt
Outdated
Show resolved
Hide resolved
src/jvm/test/resources/expected_logs/run_concurrent_test/array_rw.txt
Outdated
Show resolved
Hide resolved
Signed-off-by: Evgeniy Moiseenko <[email protected]>
…cks) GOD FORGIVE ME FOR THIS CODE Signed-off-by: Evgeniy Moiseenko <[email protected]>
Signed-off-by: Evgeniy Moiseenko <[email protected]>
@@ -0,0 +1,42 @@ | |||
= Concurrent test failed = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this line, or should we start the output with the exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it.
-
It is a title of the whole report, explaining what happened. Starting with the exception might be confusing, as if the code itself thrown an exception.
-
Currently there are two possible lines:
= Concurrent test failed =
= Concurrent test has hung =
Signed-off-by: Evgeniy Moiseenko <[email protected]>
Description:
PR adds function for running lincheck model checker algorithm on arbitrary code via lambda body.
Usage example:
Additional improvements to the PR:
runConcurrentTest
throwAssertionError
instead of returning itrunConcurrentTest
when it is used from java #445