Add a switch to destroy runtime only on shutdown (#4482)
This commit is contained in:
committed by
Stanislav Erokhin
parent
37ff2c338e
commit
ee508efb23
@@ -4361,9 +4361,19 @@ dynamicTest("interop_cleaners_leak") {
|
||||
flags = ['-Xopt-in=kotlin.native.internal.InternalForKotlinNative']
|
||||
}
|
||||
|
||||
dynamicTest("interop_migrating_main_thread_legacy") {
|
||||
disabled = (project.target.name != project.hostName)
|
||||
source = "interop/migrating_main_thread/lib.kt"
|
||||
flags = ['-Xdestroy-runtime-mode=legacy']
|
||||
clangFlags = ['-DIS_LEGACY']
|
||||
cSource = "$projectDir/interop/migrating_main_thread/main.cpp"
|
||||
clangTool = "clang++"
|
||||
}
|
||||
|
||||
dynamicTest("interop_migrating_main_thread") {
|
||||
disabled = (project.target.name != project.hostName)
|
||||
source = "interop/migrating_main_thread/lib.kt"
|
||||
flags = ['-Xdestroy-runtime-mode=on-shutdown']
|
||||
cSource = "$projectDir/interop/migrating_main_thread/main.cpp"
|
||||
clangTool = "clang++"
|
||||
}
|
||||
@@ -4374,7 +4384,7 @@ dynamicTest("interop_memory_leaks") {
|
||||
source = "interop/memory_leaks/lib.kt"
|
||||
cSource = "$projectDir/interop/memory_leaks/main.cpp"
|
||||
clangTool = "clang++"
|
||||
flags = ['-g']
|
||||
flags = ['-g', '-Xdestroy-runtime-mode=legacy'] // Runtime cannot be destroyed with interop with on-shutdown.
|
||||
expectedExitStatusChecker = { it != 0 }
|
||||
outputChecker = { s -> s.contains("Memory leaks detected, 1 objects leaked!") }
|
||||
}
|
||||
|
||||
@@ -13,4 +13,10 @@ fun writeToA(i: Int) {
|
||||
globalA.i = i
|
||||
}
|
||||
|
||||
fun readFromA() = globalA.i
|
||||
fun tryReadFromA(default: Int): Int {
|
||||
return try {
|
||||
globalA.i
|
||||
} catch (e: IncorrectDereferenceException) {
|
||||
default
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,26 @@
|
||||
#include <cassert>
|
||||
#include <thread>
|
||||
|
||||
constexpr int kInitialValue = 0;
|
||||
constexpr int kNewValue = 1;
|
||||
constexpr int kErrorValue = 2;
|
||||
|
||||
int main() {
|
||||
std::thread main1([]() {
|
||||
assert(testlib_symbols()->kotlin.root.readFromA() == 0);
|
||||
testlib_symbols()->kotlin.root.writeToA(1);
|
||||
assert(testlib_symbols()->kotlin.root.readFromA() == 1);
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kInitialValue);
|
||||
testlib_symbols()->kotlin.root.writeToA(kNewValue);
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kNewValue);
|
||||
});
|
||||
main1.join();
|
||||
|
||||
std::thread main2([]() {
|
||||
#if defined(IS_LEGACY)
|
||||
// Globals were reinitialized.
|
||||
assert(testlib_symbols()->kotlin.root.readFromA() == 0);
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kInitialValue);
|
||||
#else
|
||||
// Globals are not accessible.
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kErrorValue);
|
||||
#endif
|
||||
});
|
||||
main2.join();
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import kotlin.native.ref.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// Test relies on full deinitialization at shutdown.
|
||||
kotlin.native.internal.Debugging.forceCheckedShutdown = true
|
||||
autoreleasepool {
|
||||
run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user