diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index 2c6e08af979..c2bbc2eef01 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -97,6 +97,7 @@ ext.isExperimentalMM = !(project.globalTestArgs.contains("-memory-model") && project.globalTestArgs.contains("strict")) && project.testTarget != 'wasm32' ext.isNoopGC = project.globalTestArgs.contains("-Xgc=noop") +ext.isAggressiveGC = project.globalTestArgs.contains("-Xbinary=gcSchedulerType=aggressive") // TODO: It also makes sense to test -g without asserts, and also to test -opt with asserts. if (project.globalTestArgs.contains("-g")) { @@ -5409,6 +5410,9 @@ if (isAppleTarget(project)) { if (isNoopGC) { swiftExtraOpts += ["-D", "NOOP_GC"] } + if (isAggressiveGC) { + swiftExtraOpts += ["-D", "AGGRESSIVE_GC"] + } } frameworkTest('testObjCExportNoGenerics') { diff --git a/kotlin-native/backend.native/tests/objcexport/values.swift b/kotlin-native/backend.native/tests/objcexport/values.swift index b7745306fd7..d2ff8f17e67 100644 --- a/kotlin-native/backend.native/tests/objcexport/values.swift +++ b/kotlin-native/backend.native/tests/objcexport/values.swift @@ -896,10 +896,6 @@ func testWeakRefs0(frozen: Bool) throws { Holder.ref2 = obj2 } - try assertFalse(Holder.ref1 === nil) - try assertFalse(Holder.ref2 === nil) - try assertEquals(actual: Holder.deinitialized, expected: 0) - ValuesKt.gc() try assertTrue(Holder.ref1 === nil) @@ -942,9 +938,13 @@ class TestSharedRefs { let ignore = SharedRefs() // Ensures that Kotlin runtime gets initialized. } - Closure.currentBlock!() + // Take the block from Closure to avoid races when block() execution triggers + // calling launchInNewThread on another thread (e.g. on the finalizer thread). + let block = Closure.currentBlock! Closure.currentBlock = nil + block() + return nil }, nil) try! assertEquals(actual: createCode, expected: 0)