From 7ff5be10d0494e97b211d8a3d92838811354c444 Mon Sep 17 00:00:00 2001 From: Nikita Koval Date: Wed, 20 Mar 2024 21:25:23 +0100 Subject: [PATCH] Add tests to reproduce the problem --- .../representation/ValidationFunctionTests.kt | 56 +++++++++++++++++++ .../validation_function_hangs.txt | 0 .../validation_function_livelock.txt | 0 3 files changed, 56 insertions(+) create mode 100644 src/jvm/test/resources/expected_logs/validation_function_hangs.txt create mode 100644 src/jvm/test/resources/expected_logs/validation_function_livelock.txt diff --git a/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/representation/ValidationFunctionTests.kt b/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/representation/ValidationFunctionTests.kt index 643200471..0076cf94d 100644 --- a/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/representation/ValidationFunctionTests.kt +++ b/src/jvm/test/org/jetbrains/kotlinx/lincheck_test/representation/ValidationFunctionTests.kt @@ -111,4 +111,60 @@ class MoreThenOneValidationFunctionFailureTest { @Test fun test() = ModelCheckingOptions() .checkFailsWithException(this::class.java, "two_validation_functions_exception.txt") +} + +class ValidationFunctionLivelockTest { + var a = 0 + + @Operation + fun operation() { + a = 1 + } + + @Validate + fun validate() { + // Lincheck should detect a live-lock in the validation function. + repeat(10_000) { + a++ + } + } + + @Test + fun test() = ModelCheckingOptions() + .iterations(1) + .invocationsPerIteration(1) + .actorsBefore(0) + .threads(1) + .actorsPerThread(1) + .actorsAfter(0) + .minimizeFailedScenario(false) + .checkImpl(this::class.java) + .checkLincheckOutput("validation_function_livelock.txt") +} + +class ValidationFunctionHangsIsolatedTest { + var a = 0 + + @Operation + fun operation() { + a = 1 + } + + @Validate + fun validate() { + while (true) {} + } + + @Test + fun test() = ModelCheckingOptions() + .iterations(1) + .invocationsPerIteration(1) + .actorsBefore(0) + .threads(1) + .actorsPerThread(1) + .actorsAfter(0) + .invocationTimeout(100) + .minimizeFailedScenario(false) + .checkImpl(this::class.java) + .checkLincheckOutput("validation_function_hangs.txt") } \ No newline at end of file diff --git a/src/jvm/test/resources/expected_logs/validation_function_hangs.txt b/src/jvm/test/resources/expected_logs/validation_function_hangs.txt new file mode 100644 index 000000000..e69de29bb diff --git a/src/jvm/test/resources/expected_logs/validation_function_livelock.txt b/src/jvm/test/resources/expected_logs/validation_function_livelock.txt new file mode 100644 index 000000000..e69de29bb