Skip to content

Commit c1869f5

Browse files
committed
Get rid of old Kotlin/Native memory model
Fixes #3375
1 parent 19666ac commit c1869f5

27 files changed

+59
-191
lines changed

kotlinx-coroutines-core/build.gradle

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void defineSourceSet(newName, dependsOn, includedInPred) {
5656
}
5757

5858
static boolean isNativeDarwin(String name) { return ["ios", "macos", "tvos", "watchos"].any { name.startsWith(it) } }
59+
5960
static boolean isNativeOther(String name) { return ["linux", "mingw"].any { name.startsWith(it) } }
6061

6162
defineSourceSet("concurrent", ["common"]) { it in ["jvm", "native"] }
@@ -77,40 +78,18 @@ kotlin {
7778
}
7879

7980
/*
80-
* Configure four test runs:
81-
* 1) Old memory model, Main thread
82-
* 2) New memory model, Main thread
83-
* 3) Old memory model, BG thread
84-
* 4) New memory model, BG thread (required for Dispatchers.Main tests on Darwin)
81+
* Configure two test runs:
82+
* 1) New memory model, Main thread
83+
* 2) New memory model, BG thread (required for Dispatchers.Main tests on Darwin)
8584
*
8685
* All new MM targets are build with optimize = true to have stress tests properly run.
8786
*/
8887
targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests.class).configureEach {
89-
binaries {
90-
// Test for memory leaks using a special entry point that does not exit but returns from main
91-
binaries.getTest("DEBUG").freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
92-
}
93-
94-
binaries.test("newMM", [DEBUG]) {
95-
def thisTest = it
96-
freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
97-
optimized = true
98-
binaryOptions["memoryModel"] = "experimental"
99-
testRuns.create("newMM") {
100-
setExecutionSourceFrom(thisTest)
101-
// A hack to get different suffixes in the aggregated report.
102-
executionTask.configure { targetName = "$targetName new MM" }
103-
}
104-
}
105-
106-
binaries.test("worker", [DEBUG]) {
107-
def thisTest = it
108-
freeCompilerArgs += ["-e", "kotlinx.coroutines.mainBackground"]
109-
testRuns.create("worker") {
110-
setExecutionSourceFrom(thisTest)
111-
executionTask.configure { targetName = "$targetName worker" }
112-
}
113-
}
88+
def defaultTests = binaries.getTest("DEBUG")
89+
// Test for memory leaks using a special entry point that does not exit but returns from main
90+
defaultTests.freeCompilerArgs += ["-e", "kotlinx.coroutines.mainNoExit"]
91+
defaultTests.optimized = true
92+
defaultTests.binaryOptions["memoryModel"] = "experimental"
11493

11594
binaries.test("workerWithNewMM", [DEBUG]) {
11695
def thisTest = it
@@ -150,11 +129,11 @@ def configureNativeSourceSetPreset(name, preset) {
150129
def implementationConfiguration = configurations[hostMainCompilation.defaultSourceSet.implementationMetadataConfigurationName]
151130
// Now find the libraries: Finds platform libs & stdlib, but platform declarations are still not resolved due to IDE bugs
152131
def hostNativePlatformLibs = files(
153-
provider {
154-
implementationConfiguration.findAll {
155-
it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") || it.absolutePath.contains("stdlib")
132+
provider {
133+
implementationConfiguration.findAll {
134+
it.path.endsWith(".klib") || it.absolutePath.contains("klib${File.separator}platform") || it.absolutePath.contains("stdlib")
135+
}
156136
}
157-
}
158137
)
159138
// Add all those dependencies
160139
for (suffix in sourceSetSuffixes) {

kotlinx-coroutines-core/concurrent/test/AbstractDispatcherConcurrencyTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
1212
public abstract val dispatcher: CoroutineDispatcher
1313

1414
@Test
15-
fun testLaunchAndJoin() = runMtTest {
15+
fun testLaunchAndJoin() = runTest {
1616
expect(1)
1717
var capturedMutableState = 0
1818
val job = GlobalScope.launch(dispatcher) {
@@ -25,7 +25,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
2525
}
2626

2727
@Test
28-
fun testDispatcherHasOwnThreads() = runMtTest {
28+
fun testDispatcherHasOwnThreads() = runTest {
2929
val channel = Channel<Int>()
3030
GlobalScope.launch(dispatcher) {
3131
channel.send(42)
@@ -41,7 +41,7 @@ abstract class AbstractDispatcherConcurrencyTest : TestBase() {
4141
}
4242

4343
@Test
44-
fun testDelayInDispatcher() = runMtTest {
44+
fun testDelayInDispatcher() = runTest {
4545
expect(1)
4646
val job = GlobalScope.launch(dispatcher) {
4747
expect(2)

kotlinx-coroutines-core/concurrent/test/ConcurrentExceptionsStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConcurrentExceptionsStressTest : TestBase() {
2222
}
2323

2424
@Test
25-
fun testStress() = runMtTest {
25+
fun testStress() = runTest {
2626
workers = Array(nWorkers) { index ->
2727
newSingleThreadContext("JobExceptionsStressTest-$index")
2828
}

kotlinx-coroutines-core/concurrent/test/JobStructuredJoinStressTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class JobStructuredJoinStressTest : TestBase() {
1616
private val nRepeats = 10_000 * stressTestMultiplier
1717

1818
@Test
19-
fun testStressRegularJoin() = runMtTest {
19+
fun testStressRegularJoin() = runTest {
2020
stress(Job::join)
2121
}
2222

2323
@Test
24-
fun testStressSuspendCancellable() = runMtTest {
24+
fun testStressSuspendCancellable() = runTest {
2525
stress { job ->
2626
suspendCancellableCoroutine { cont ->
2727
job.invokeOnCompletion { cont.resume(Unit) }
@@ -30,7 +30,7 @@ class JobStructuredJoinStressTest : TestBase() {
3030
}
3131

3232
@Test
33-
fun testStressSuspendCancellableReusable() = runMtTest {
33+
fun testStressSuspendCancellableReusable() = runTest {
3434
stress { job ->
3535
suspendCancellableCoroutineReusable { cont ->
3636
job.invokeOnCompletion { cont.resume(Unit) }

kotlinx-coroutines-core/concurrent/test/LimitedParallelismConcurrentTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LimitedParallelismConcurrentTest : TestBase() {
2323
}
2424

2525
@Test
26-
fun testLimitedExecutor() = runMtTest {
26+
fun testLimitedExecutor() = runTest {
2727
val executor = newFixedThreadPoolContext(targetParallelism, "test")
2828
val view = executor.limitedParallelism(targetParallelism)
2929
doStress {
@@ -45,7 +45,7 @@ class LimitedParallelismConcurrentTest : TestBase() {
4545
}
4646

4747
@Test
48-
fun testTaskFairness() = runMtTest {
48+
fun testTaskFairness() = runTest {
4949
val executor = newSingleThreadContext("test")
5050
val view = executor.limitedParallelism(1)
5151
val view2 = executor.limitedParallelism(1)

kotlinx-coroutines-core/concurrent/test/RunBlockingTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.test.*
1010
class RunBlockingTest : TestBase() {
1111

1212
@Test
13-
fun testWithTimeoutBusyWait() = runMtTest {
13+
fun testWithTimeoutBusyWait() = runTest {
1414
val value = withTimeoutOrNull(10) {
1515
while (isActive) {
1616
// Busy wait
@@ -52,7 +52,7 @@ class RunBlockingTest : TestBase() {
5252
}
5353

5454
@Test
55-
fun testOtherDispatcher() = runMtTest {
55+
fun testOtherDispatcher() = runTest {
5656
expect(1)
5757
val name = "RunBlockingTest.testOtherDispatcher"
5858
val thread = newSingleThreadContext(name)
@@ -68,7 +68,7 @@ class RunBlockingTest : TestBase() {
6868
}
6969

7070
@Test
71-
fun testCancellation() = runMtTest {
71+
fun testCancellation() = runTest {
7272
newFixedThreadPoolContext(2, "testCancellation").use {
7373
val job = GlobalScope.launch(it) {
7474
runBlocking(coroutineContext) {

kotlinx-coroutines-core/concurrent/test/TestBaseExtension.common.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

kotlinx-coroutines-core/concurrent/test/channels/BroadcastChannelSubStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BroadcastChannelSubStressTest: TestBase() {
2020
private val receivedTotal = atomic(0L)
2121

2222
@Test
23-
fun testStress() = runMtTest {
23+
fun testStress() = runTest {
2424
TestBroadcastChannelKind.values().forEach { kind ->
2525
println("--- BroadcastChannelSubStressTest $kind")
2626
val broadcast = kind.create<Long>()

kotlinx-coroutines-core/concurrent/test/channels/ChannelCancelUndeliveredElementStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ChannelCancelUndeliveredElementStressTest : TestBase() {
2828
private val dUndeliveredCnt = atomic(0)
2929

3030
@Test
31-
fun testStress() = runMtTest {
31+
fun testStress() = runTest {
3232
repeat(repeatTimes) {
3333
val channel = Channel<Int>(1) { dUndeliveredCnt.incrementAndGet() }
3434
val j1 = launch(Dispatchers.Default) {

kotlinx-coroutines-core/concurrent/test/channels/ConflatedBroadcastChannelNotifyStressTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ConflatedBroadcastChannelNotifyStressTest : TestBase() {
2222
private val receivedTotal = atomic(0)
2323

2424
@Test
25-
fun testStressNotify()= runMtTest {
25+
fun testStressNotify()= runTest {
2626
println("--- ConflatedBroadcastChannelNotifyStressTest")
2727
val senders = List(nSenders) { senderId ->
2828
launch(Dispatchers.Default + CoroutineName("Sender$senderId")) {

0 commit comments

Comments
 (0)