[K/N][tests] Migrate interopTest tests ^KT-61259
This commit is contained in:
committed by
Space Team
parent
c227e60150
commit
bbcc5c9aed
+68
@@ -0,0 +1,68 @@
|
||||
// EXIT_CODE: !0
|
||||
// OUTPUT_REGEX: Cannot run checkers when there are 1 alive runtimes at the shutdown.*
|
||||
// MODULE: cinterop
|
||||
// FILE: leakMemory.def
|
||||
---
|
||||
void test_RunInNewThread(void (*)());
|
||||
|
||||
// FILE: leakMemory.h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void test_RunInNewThread(void (*)());
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// FILE: leakMemory.cpp
|
||||
#include "leakMemory.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
extern "C" void test_RunInNewThread(void (*f)()) {
|
||||
std::atomic<bool> haveRun(false);
|
||||
std::thread t([f, &haveRun]() {
|
||||
f();
|
||||
haveRun = true;
|
||||
while (true) {}
|
||||
});
|
||||
t.detach();
|
||||
while (!haveRun) {}
|
||||
}
|
||||
|
||||
// MODULE: main(cinterop)
|
||||
// FILE: main.kt
|
||||
@file:OptIn(
|
||||
kotlin.experimental.ExperimentalNativeApi::class,
|
||||
kotlin.native.runtime.NativeRuntimeApi::class,
|
||||
kotlinx.cinterop.ExperimentalForeignApi::class
|
||||
)
|
||||
|
||||
import leakMemory.*
|
||||
import kotlin.concurrent.AtomicInt
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.Platform
|
||||
import kotlin.test.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
val global = AtomicInt(0)
|
||||
|
||||
fun ensureInititalized() {
|
||||
// Leak memory
|
||||
StableRef.create(Any())
|
||||
global.value = 1
|
||||
}
|
||||
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
kotlin.native.runtime.Debugging.forceCheckedShutdown = true
|
||||
assertTrue(global.value == 0)
|
||||
// Created a thread, made sure Kotlin is initialized there.
|
||||
test_RunInNewThread(staticCFunction(::ensureInititalized))
|
||||
assertTrue(global.value == 1)
|
||||
// Now exiting. With checked shutdown we will fail, complaining there're
|
||||
// unfinished threads with runtimes.
|
||||
}
|
||||
+1
-6
@@ -1,4 +1,3 @@
|
||||
// TARGET_BACKEND: NATIVE
|
||||
// MODULE: cinterop
|
||||
// FILE: leakMemoryWithRunningThreadUnchecked.def
|
||||
---
|
||||
@@ -51,14 +50,12 @@ import kotlinx.cinterop.*
|
||||
val global = AtomicInt(0)
|
||||
|
||||
fun ensureInititalized() {
|
||||
// Only needed with the legacy MM. TODO: Remove when legacy MM is gone.
|
||||
kotlin.native.initRuntimeIfNeeded()
|
||||
// Leak memory
|
||||
StableRef.create(Any())
|
||||
global.value = 1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
fun main() {
|
||||
Platform.isMemoryLeakCheckerActive = true
|
||||
kotlin.native.runtime.Debugging.forceCheckedShutdown = false
|
||||
assertTrue(global.value == 0)
|
||||
@@ -67,6 +64,4 @@ fun box(): String {
|
||||
assertTrue(global.value == 1)
|
||||
// Now exiting. With unchecked shutdown, we exit quietly, even though there're
|
||||
// unfinished threads with runtimes.
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// Cross-thread signalling does not work on Windows
|
||||
// DISABLE_NATIVE: targetFamily=MINGW
|
||||
// MODULE: cinterop
|
||||
// FILE: workerSignals.def
|
||||
---
|
||||
#include <stdint.h>
|
||||
void setupSignalHandler(void);
|
||||
void signalThread(uint64_t thread, int value);
|
||||
int getValue(void);
|
||||
|
||||
// FILE: workerSignals.cpp
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
namespace {
|
||||
|
||||
int pendingValue = 0;
|
||||
thread_local int value = 0;
|
||||
|
||||
void signalHandler(int signal) {
|
||||
value = pendingValue;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" void setupSignalHandler(void) {
|
||||
signal(SIGUSR1, &signalHandler);
|
||||
}
|
||||
|
||||
extern "C" void signalThread(uint64_t thread, int value) {
|
||||
pendingValue = value;
|
||||
pthread_t t = {};
|
||||
memcpy(&t, &thread, sizeof(pthread_t));
|
||||
auto result = pthread_kill(t, SIGUSR1);
|
||||
assert(result == 0);
|
||||
}
|
||||
|
||||
extern "C" int getValue(void) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// MODULE: main(cinterop)
|
||||
// FILE: main.kt
|
||||
@file:OptIn(kotlin.ExperimentalStdlibApi::class, ObsoleteWorkersApi::class, kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.test.*
|
||||
import workerSignals.*
|
||||
|
||||
const val defaultValue = 0
|
||||
const val newValue = 42
|
||||
|
||||
fun main() {
|
||||
setupSignalHandler()
|
||||
|
||||
withWorker {
|
||||
val before = execute(TransferMode.SAFE, {}) {
|
||||
getValue()
|
||||
}.result
|
||||
assertEquals(defaultValue, getValue())
|
||||
assertEquals(defaultValue, before)
|
||||
|
||||
signalThread(platformThreadId, newValue)
|
||||
val after = execute(TransferMode.SAFE, {}) {
|
||||
getValue()
|
||||
}.result
|
||||
assertEquals(defaultValue, getValue())
|
||||
assertEquals(newValue, after)
|
||||
}
|
||||
}
|
||||
-6
@@ -225,12 +225,6 @@ public class FirNativeCodegenLocalTestGenerated extends AbstractNativeCodegenBox
|
||||
runTest("native/native.tests/testData/codegen/cinterop/kt64105.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadUnchecked() {
|
||||
runTest("native/native.tests/testData/codegen/cinterop/leakMemoryWithRunningThreadUnchecked.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("toKString.kt")
|
||||
public void testToKString() {
|
||||
|
||||
+33
@@ -46,6 +46,39 @@ public class FirNativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest
|
||||
runTest("native/native.tests/testData/standalone/kt56048.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("workerSignals.kt")
|
||||
public void testWorkerSignals() {
|
||||
runTest("native/native.tests/testData/standalone/workerSignals.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("native/native.tests/testData/standalone/checkers")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("standalone")
|
||||
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
|
||||
@UseStandardTestCaseGroupProvider()
|
||||
@Tag("frontend-fir")
|
||||
@FirPipeline()
|
||||
public class Checkers {
|
||||
@Test
|
||||
public void testAllFilesPresentInCheckers() {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/checkers"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadChecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadChecked() {
|
||||
runTest("native/native.tests/testData/standalone/checkers/leakMemoryWithRunningThreadChecked.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadUnchecked() {
|
||||
runTest("native/native.tests/testData/standalone/checkers/leakMemoryWithRunningThreadUnchecked.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("native/native.tests/testData/standalone/console")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
-6
@@ -215,12 +215,6 @@ public class NativeCodegenLocalTestGenerated extends AbstractNativeCodegenBoxTes
|
||||
runTest("native/native.tests/testData/codegen/cinterop/kt64105.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadUnchecked() {
|
||||
runTest("native/native.tests/testData/codegen/cinterop/leakMemoryWithRunningThreadUnchecked.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("toKString.kt")
|
||||
public void testToKString() {
|
||||
|
||||
+31
@@ -43,6 +43,37 @@ public class NativeStandaloneTestGenerated extends AbstractNativeBlackBoxTest {
|
||||
runTest("native/native.tests/testData/standalone/kt56048.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("workerSignals.kt")
|
||||
public void testWorkerSignals() {
|
||||
runTest("native/native.tests/testData/standalone/workerSignals.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("native/native.tests/testData/standalone/checkers")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@Tag("standalone")
|
||||
@EnforcedProperty(property = ClassLevelProperty.TEST_KIND, propertyValue = "STANDALONE_NO_TR")
|
||||
@UseStandardTestCaseGroupProvider()
|
||||
public class Checkers {
|
||||
@Test
|
||||
public void testAllFilesPresentInCheckers() {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("native/native.tests/testData/standalone/checkers"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadChecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadChecked() {
|
||||
runTest("native/native.tests/testData/standalone/checkers/leakMemoryWithRunningThreadChecked.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("leakMemoryWithRunningThreadUnchecked.kt")
|
||||
public void testLeakMemoryWithRunningThreadUnchecked() {
|
||||
runTest("native/native.tests/testData/standalone/checkers/leakMemoryWithRunningThreadUnchecked.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("native/native.tests/testData/standalone/console")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Reference in New Issue
Block a user