diff --git a/testsuite/src/commonMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublication.kt b/testsuite/src/commonMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublication.kt index a94b45f..81cb6c4 100644 --- a/testsuite/src/commonMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublication.kt +++ b/testsuite/src/commonMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublication.kt @@ -1,7 +1,7 @@ package org.jetbrains.litmuskt.tests -import org.jetbrains.litmuskt.autooutcomes.LitmusIOutcome import org.jetbrains.litmuskt.LitmusTestContainer +import org.jetbrains.litmuskt.autooutcomes.LitmusIOutcome import org.jetbrains.litmuskt.autooutcomes.accept import org.jetbrains.litmuskt.autooutcomes.forbid import org.jetbrains.litmuskt.autooutcomes.interesting @@ -72,13 +72,35 @@ object UnsafePublication { } }) { thread { - arr = Array(10) { 0 } + arr = Array(1) { 1 } } thread { r1 = arr?.get(0) ?: -1 } spec { - accept(0) + accept(1) + // 0 is the default value for `Int`. However, since Int-s in `Array` are boxed, we don't get to see a 0. + // On JVM, a NullPointerException here is technically valid. Currently, there is no support for exceptions as accepted outcomes. + // On Native, there is no NullPointerException, so we can see a segmentation fault. + interesting(0) + accept(-1) + } + } + + val PlainIntArray = litmusTest({ + object : LitmusIOutcome() { + var arr: IntArray? = null + } + }) { + thread { + arr = IntArray(1) { 1 } + } + thread { + r1 = arr?.get(0) ?: -1 + } + spec { + accept(1) + interesting(0) accept(-1) } } diff --git a/testsuite/src/jvmMain/kotlin/org/jetbrains/litmuskt/UnsafePublicationJvm.kt b/testsuite/src/jvmMain/kotlin/org/jetbrains/litmuskt/UnsafePublicationJvm.kt new file mode 100644 index 0000000..13b261f --- /dev/null +++ b/testsuite/src/jvmMain/kotlin/org/jetbrains/litmuskt/UnsafePublicationJvm.kt @@ -0,0 +1,27 @@ +package org.jetbrains.litmuskt + +import org.jetbrains.litmuskt.autooutcomes.LitmusIOutcome +import org.jetbrains.litmuskt.autooutcomes.accept +import org.jetbrains.litmuskt.autooutcomes.forbid +import java.util.concurrent.atomic.AtomicIntegerArray + +@LitmusTestContainer +object UnsafePublicationJvm { + val PlainAtomicIntegerArray = litmusTest({ + object : LitmusIOutcome() { + var arr: AtomicIntegerArray? = null + } + }) { + thread { + arr = AtomicIntegerArray(intArrayOf(1)) + } + thread { + r1 = arr?.get(0) ?: -1 + } + spec { + accept(1) + forbid(0) + accept(-1) + } + } +} diff --git a/testsuite/src/nativeMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublicationNative.kt b/testsuite/src/nativeMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublicationNative.kt new file mode 100644 index 0000000..b7882af --- /dev/null +++ b/testsuite/src/nativeMain/kotlin/org/jetbrains/litmuskt/tests/UnsafePublicationNative.kt @@ -0,0 +1,31 @@ +package org.jetbrains.litmuskt.tests + +import org.jetbrains.litmuskt.LitmusTestContainer +import org.jetbrains.litmuskt.autooutcomes.LitmusIOutcome +import org.jetbrains.litmuskt.autooutcomes.accept +import org.jetbrains.litmuskt.autooutcomes.interesting +import org.jetbrains.litmuskt.litmusTest +import kotlin.concurrent.AtomicIntArray + +@LitmusTestContainer +object UnsafePublicationNative { + + @OptIn(ExperimentalStdlibApi::class) + val PlainAtomicIntArray = litmusTest({ + object : LitmusIOutcome() { + var arr: AtomicIntArray? = null + } + }) { + thread { + arr = AtomicIntArray(1) { 1 } + } + thread { + r1 = arr?.get(0) ?: -1 + } + spec { + accept(1) + interesting(0) + accept(-1) + } + } +}