Tests on migrating main thread and memory leaks with interop (#4494)

This commit is contained in:
Alexander Shabalin
2020-11-03 15:49:27 +03:00
committed by Stanislav Erokhin
parent 4c9bbe54d4
commit fc7cf48798
5 changed files with 87 additions and 0 deletions
@@ -4343,6 +4343,25 @@ dynamicTest("interop_cleaners_leak") {
flags = ['-Xopt-in=kotlin.native.internal.InternalForKotlinNative']
}
dynamicTest("interop_migrating_main_thread") {
// TODO: Fix it.
disabled = (project.testTarget != null && project.testTarget != project.hostName)
source = "interop/migrating_main_thread/lib.kt"
cSource = "$projectDir/interop/migrating_main_thread/main.cpp"
clangTool = "clang++"
}
dynamicTest("interop_memory_leaks") {
// TODO: Fix it.
disabled = (project.testTarget != null && project.testTarget != project.hostName) || project.globalTestArgs.contains('-opt') || (project.testTarget == 'wasm32') // Needs debug build.
source = "interop/memory_leaks/lib.kt"
cSource = "$projectDir/interop/memory_leaks/main.cpp"
clangTool = "clang++"
flags = ['-g']
expectedExitStatusChecker = { it != 0 }
outputChecker = { s -> s.contains("Memory leaks detected, 1 objects leaked!") }
}
task library_mismatch(type: KonanDriverTest) {
// Does not work for cross targets yet.
enabled = !(project.testTarget != null && project.target.name != project.hostName)
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlinx.cinterop.*
fun leakMemory() {
StableRef.create(Any())
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
#include "testlib_api.h"
#include <thread>
int main() {
std::thread t([]() {
testlib_symbols()->kotlin.root.leakMemory();
});
t.join();
return 0;
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
class A {
var i = 0
}
private var globalA = A()
fun writeToA(i: Int) {
globalA.i = i
}
fun readFromA() = globalA.i
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
#include "testlib_api.h"
#include <cassert>
#include <thread>
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);
});
main1.join();
std::thread main2([]() {
// Globals were reinitialized.
assert(testlib_symbols()->kotlin.root.readFromA() == 0);
});
main2.join();
return 0;
}