Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
for (s in args) {
|
||||
println(s)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
assert(false)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
assert(true)
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
package runtime.basic.cleaner_basic
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.ref.WeakReference
|
||||
|
||||
class AtomicBoolean(initialValue: Boolean) {
|
||||
private val impl = AtomicInt(if (initialValue) 1 else 0)
|
||||
|
||||
init {
|
||||
freeze()
|
||||
}
|
||||
|
||||
public var value: Boolean
|
||||
get() = impl.value != 0
|
||||
set(new) { impl.value = if (new) 1 else 0 }
|
||||
}
|
||||
|
||||
class FunBox(private val impl: () -> Unit) {
|
||||
fun call() {
|
||||
impl()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerLambda() {
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
createCleaner(funBox) { it.call() }
|
||||
}()
|
||||
GC.collect() // Make sure local funBox reference is gone
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertFalse(called.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerAnonymousFunction() {
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
createCleaner(funBox, fun (it: FunBox) { it.call() })
|
||||
}()
|
||||
GC.collect() // Make sure local funBox reference is gone
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertFalse(called.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerFunctionReference() {
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
createCleaner(funBox, FunBox::call)
|
||||
}()
|
||||
GC.collect() // Make sure local funBox reference is gone
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertFalse(called.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerFailWithNonShareableArgument() {
|
||||
val funBox = FunBox {}
|
||||
assertFailsWith<IllegalArgumentException> {
|
||||
createCleaner(funBox) {}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerCleansWithoutGC() {
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
createCleaner(funBox) { it.call() }
|
||||
}()
|
||||
GC.collect() // Make sure local funBox reference is gone
|
||||
cleaner.freeze()
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertFalse(called.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
|
||||
waitCleanerWorker()
|
||||
|
||||
assertTrue(called.value)
|
||||
// If this fails, GC has somehow ran on the cleaners worker.
|
||||
assertNotNull(funBoxWeak!!.value)
|
||||
}
|
||||
|
||||
val globalInt = AtomicInt(0)
|
||||
|
||||
@Test
|
||||
fun testCleanerWithInt() {
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = createCleaner(42) {
|
||||
globalInt.value = it
|
||||
}.freeze()
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertEquals(0, globalInt.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertEquals(42, globalInt.value)
|
||||
}
|
||||
|
||||
val globalPtr = AtomicNativePtr(NativePtr.NULL)
|
||||
|
||||
@Test
|
||||
fun testCleanerWithNativePtr() {
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val cleaner = createCleaner(NativePtr.NULL + 42L) {
|
||||
globalPtr.value = it
|
||||
}
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
assertEquals(NativePtr.NULL, globalPtr.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertEquals(NativePtr.NULL + 42L, globalPtr.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerWithException() {
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
val cleaner = createCleaner(funBox) {
|
||||
it.call()
|
||||
error("Cleaner block failed")
|
||||
}
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
// Cleaners block started executing.
|
||||
assertTrue(called.value)
|
||||
// Even though the block failed, the captured funBox is freed.
|
||||
assertNull(funBoxWeak!!.value)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// This cleaner will run, because with the checker active this cleaner
|
||||
// will get collected, block scheduled and executed before cleaners are disabled.
|
||||
createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = false
|
||||
// This cleaner will not run, because with the checker inactive this cleaner
|
||||
// will not get collected before cleaners are disabled.
|
||||
createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@ThreadLocal
|
||||
var tlsCleaner: Cleaner? = null
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// This cleaner won't be run
|
||||
tlsCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
+26
@@ -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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@ThreadLocal
|
||||
var tlsCleaner: Cleaner? = null
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = false
|
||||
// This cleaner won't be run
|
||||
tlsCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.internal.*
|
||||
|
||||
@ThreadLocal
|
||||
var tlsCleaner: Cleaner? = null
|
||||
|
||||
val value = AtomicInt(0)
|
||||
|
||||
fun main() {
|
||||
val worker = Worker.start()
|
||||
|
||||
worker.execute(TransferMode.SAFE, {}) {
|
||||
tlsCleaner = createCleaner(42) {
|
||||
value.value = it
|
||||
}
|
||||
}
|
||||
|
||||
worker.requestTermination().result
|
||||
waitWorkerTermination(worker)
|
||||
waitCleanerWorker()
|
||||
|
||||
assertEquals(42, value.value)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.internal.*
|
||||
|
||||
// This cleaner won't be run, because it's deinitialized with globals after
|
||||
// cleaners are disabled.
|
||||
val globalCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
// Make sure cleaner is initialized.
|
||||
assertNotNull(globalCleaner)
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
// This cleaner won't be run, because it's deinitialized with globals after
|
||||
// cleaners are disabled.
|
||||
val globalCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = true
|
||||
// Make sure cleaner is initialized.
|
||||
assertNotNull(globalCleaner)
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
// This cleaner won't be run, because it's deinitialized with globals after
|
||||
// cleaners are disabled.
|
||||
val globalCleaner = createCleaner(42) {
|
||||
println(it)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
// Cleaner holds onto a finalization lambda. If it doesn't get executed,
|
||||
// the memory will leak. Suppress memory leak checker to check for cleaners
|
||||
// leak only.
|
||||
Platform.isMemoryLeakCheckerActive = false
|
||||
Platform.isCleanersLeakCheckerActive = false
|
||||
// Make sure cleaner is initialized.
|
||||
assertNotNull(globalCleaner)
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@file:OptIn(ExperimentalStdlibApi::class)
|
||||
|
||||
package runtime.basic.cleaner_workers
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.internal.*
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.native.ref.WeakReference
|
||||
|
||||
class AtomicBoolean(initialValue: Boolean) {
|
||||
private val impl = AtomicInt(if (initialValue) 1 else 0)
|
||||
|
||||
init {
|
||||
freeze()
|
||||
}
|
||||
|
||||
public var value: Boolean
|
||||
get() = impl.value != 0
|
||||
set(new) { impl.value = if (new) 1 else 0 }
|
||||
}
|
||||
|
||||
class FunBox(private val impl: () -> Unit) {
|
||||
fun call() {
|
||||
impl()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerDestroyInChild() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
worker.execute(TransferMode.SAFE, {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
val cleaner = createCleaner(funBox) { it.call() }
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
Pair(called, cleaner)
|
||||
}) { (called, cleaner) ->
|
||||
assertFalse(called.value)
|
||||
}.result
|
||||
|
||||
GC.collect()
|
||||
worker.execute(TransferMode.SAFE, {}) { GC.collect() }.result
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerDestroyWithChild() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
worker.execute(TransferMode.SAFE, {
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
val cleaner = createCleaner(funBox) { it.call() }
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
Pair(called, cleaner)
|
||||
}) { (called, cleaner) ->
|
||||
assertFalse(called.value)
|
||||
}.result
|
||||
|
||||
GC.collect()
|
||||
worker.requestTermination().result
|
||||
waitWorkerTermination(worker)
|
||||
|
||||
performGCOnCleanerWorker() // Collect cleaners stack
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerDestroyInMain() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
{
|
||||
val result = worker.execute(TransferMode.SAFE, { called }) { called ->
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
val cleaner = createCleaner(funBox) { it.call() }
|
||||
Triple(cleaner, WeakReference(funBox), WeakReference(cleaner))
|
||||
}.result
|
||||
val cleaner = result.first
|
||||
funBoxWeak = result.second
|
||||
cleanerWeak = result.third
|
||||
assertFalse(called.value)
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
worker.execute(TransferMode.SAFE, {}) { GC.collect() }.result
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCleanerDestroyShared() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val called = AtomicBoolean(false);
|
||||
var funBoxWeak: WeakReference<FunBox>? = null
|
||||
var cleanerWeak: WeakReference<Cleaner>? = null
|
||||
val cleanerHolder: AtomicReference<Cleaner?> = AtomicReference(null);
|
||||
{
|
||||
val funBox = FunBox { called.value = true }.freeze()
|
||||
funBoxWeak = WeakReference(funBox)
|
||||
val cleaner = createCleaner(funBox) { it.call() }
|
||||
cleanerWeak = WeakReference(cleaner)
|
||||
cleanerHolder.value = cleaner
|
||||
worker.execute(TransferMode.SAFE, { Pair(called, cleanerHolder) }) { (called, cleanerHolder) ->
|
||||
cleanerHolder.value = null
|
||||
assertFalse(called.value)
|
||||
}.result
|
||||
}()
|
||||
|
||||
GC.collect()
|
||||
worker.execute(TransferMode.SAFE, {}) { GC.collect() }.result
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertNull(cleanerWeak!!.value)
|
||||
assertTrue(called.value)
|
||||
assertNull(funBoxWeak!!.value)
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
|
||||
@ThreadLocal
|
||||
var tlsValue = 11
|
||||
|
||||
@Test
|
||||
fun testCleanerWithTLS() {
|
||||
val worker = Worker.start()
|
||||
|
||||
tlsValue = 12
|
||||
|
||||
val value = AtomicInt(0)
|
||||
worker.execute(TransferMode.SAFE, {value}) {
|
||||
tlsValue = 13
|
||||
createCleaner(it) {
|
||||
it.value = tlsValue
|
||||
}
|
||||
Unit
|
||||
}.result
|
||||
|
||||
worker.execute(TransferMode.SAFE, {}) { GC.collect() }.result
|
||||
performGCOnCleanerWorker()
|
||||
|
||||
assertEquals(11, value.value)
|
||||
|
||||
worker.requestTermination().result
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
// TODO: remove kotlin_native.io once overrides are in place.
|
||||
fun main(args : Array<String>) {
|
||||
println("Hello, world!")
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.empty_substring
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val hello = "Hello world"
|
||||
println(hello.subSequence(1, 1).toString())
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.entry0
|
||||
|
||||
fun fail() {
|
||||
println("Test failed, this is a wrong main() function.")
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fail()
|
||||
}
|
||||
|
||||
fun <T> main(args: Array<String>) {
|
||||
fail()
|
||||
}
|
||||
|
||||
fun main(args: Array<Int>) {
|
||||
fail()
|
||||
}
|
||||
|
||||
fun main(args: Array<String>, second_arg: Int) {
|
||||
fail()
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun main(args: Array<String>) {
|
||||
fail()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println("Hello.")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun fail() {
|
||||
println("Test failed, this is a wrong main() function.")
|
||||
}
|
||||
|
||||
fun foo(args: Array<String>) {
|
||||
println("Hello.")
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
println("Hello, without args.")
|
||||
}
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fail()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
fail()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
println("This is main without args")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.enum_equals
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class EnumA {
|
||||
A, B
|
||||
}
|
||||
|
||||
enum class EnumB {
|
||||
B
|
||||
}
|
||||
|
||||
fun main() {
|
||||
println(EnumA.A == EnumA.A)
|
||||
println(EnumA.A == EnumA.B)
|
||||
println(EnumA.A == EnumB.B)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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 kotlin.system.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
exitProcess(42)
|
||||
@Suppress("UNREACHABLE_CODE")
|
||||
throw RuntimeException("Exit function call returned normally")
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.for0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val byteArray = ByteArray(3)
|
||||
byteArray[0] = 2
|
||||
byteArray[1] = 3
|
||||
byteArray[2] = 4
|
||||
for (item in byteArray) {
|
||||
println(item)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.hash0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(239.hashCode())
|
||||
println((-1L).hashCode())
|
||||
println('a'.hashCode())
|
||||
println(1.0f.hashCode())
|
||||
println(1.0.hashCode())
|
||||
println(true.hashCode())
|
||||
println(false.hashCode())
|
||||
println(Any().hashCode() != Any().hashCode())
|
||||
val a = CharArray(5)
|
||||
a[0] = 'H'
|
||||
a[1] = 'e'
|
||||
a[2] = 'l'
|
||||
a[3] = 'l'
|
||||
a[4] = 'o'
|
||||
println("Hello".hashCode() == String(a, 0, 5).hashCode())
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.hello0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println("Hello, world!")
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
// TODO: TestRuner should be able to pass input to stdin
|
||||
// TODO: remove kotlin_native.io once overrides are in place.
|
||||
fun main(args: Array<String>) {
|
||||
print(readLine().toString())
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
// TODO: TestRuner should be able to pass input to stdin
|
||||
// TODO: remove kotlin_native.io once overrides are in place.
|
||||
fun main(args : Array<String>) {
|
||||
print("you entered '" + readLine() + "'")
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.hello3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(239)
|
||||
// TODO: enable, once override by name is implemented.
|
||||
println(true)
|
||||
println(3.14159)
|
||||
println('A')
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.hello4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val x = 2
|
||||
println(if (x == 2) "Hello" else "Привет")
|
||||
println(if (x == 3) "Bye" else "Пока")
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 kotlin.test.*
|
||||
import kotlin.math.*
|
||||
|
||||
fun main() {
|
||||
val hf = hypot(Float.NEGATIVE_INFINITY, Float.NaN)
|
||||
println("float hypot: $hf ${hf.toRawBits().toString(16)}")
|
||||
println("Float.NaN: ${Float.NaN.toRawBits().toString(16)}")
|
||||
println("Float.+Inf: ${Float.POSITIVE_INFINITY} ${Float.POSITIVE_INFINITY.toRawBits().toString(16)}")
|
||||
println("Float.-Inf: ${Float.NEGATIVE_INFINITY} ${Float.NEGATIVE_INFINITY.toRawBits().toUInt().toString(16)}")
|
||||
println(Float.POSITIVE_INFINITY == Float.NEGATIVE_INFINITY)
|
||||
assertEquals(Float.POSITIVE_INFINITY, hypot(Float.NEGATIVE_INFINITY, Float.NaN))
|
||||
|
||||
val hd = hypot(Double.NEGATIVE_INFINITY, Double.NaN)
|
||||
println("Double hypot: $hd ${hd.toRawBits().toString(16)}")
|
||||
println("Double.NaN: ${Double.NaN.toRawBits().toString(16)}")
|
||||
println("Double.+Inf: ${Double.POSITIVE_INFINITY} ${Double.POSITIVE_INFINITY.toRawBits().toString(16)}")
|
||||
println("Double.-Inf: ${Double.NEGATIVE_INFINITY} ${Double.NEGATIVE_INFINITY.toRawBits().toUInt().toString(16)}")
|
||||
println(Double.POSITIVE_INFINITY == Double.NEGATIVE_INFINITY)
|
||||
assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY, Double.NaN))
|
||||
|
||||
println("hypot NaN, 0: ${hypot(Double.NaN, 0.0).toRawBits().toString(16)}")
|
||||
assertTrue(hypot(Double.NaN, 0.0).isNaN())
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.ieee754
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val v = Float.POSITIVE_INFINITY
|
||||
val i = v.toInt()
|
||||
println("$v $i ${v.toShort()} ${i.toShort()}")
|
||||
|
||||
val a = 42
|
||||
val b = Float.MAX_VALUE
|
||||
println("${a + b}")
|
||||
|
||||
val s = Float.NaN.toShort()
|
||||
println("NAN2SHORT:: $s")
|
||||
|
||||
val d: Float = Float.MAX_VALUE
|
||||
println("MAX2SHORT:: ${d.toShort()}")
|
||||
val d2i = d.toInt()
|
||||
println("$d2i ${d2i.toShort()}")
|
||||
|
||||
for (f in arrayOf(Float.POSITIVE_INFINITY, Float.MAX_VALUE / 2, Float.MAX_VALUE,
|
||||
3.14f, Float.NaN, -33333.12312f, Float.MIN_VALUE, Float.NEGATIVE_INFINITY,
|
||||
-1.2f, -12.6f, 2.3f)) {
|
||||
println("FLOAT:: $f INT:: ${f.toInt()}")
|
||||
}
|
||||
|
||||
println("OK")
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
val x = initRuntimeIfNeeded()
|
||||
|
||||
fun main() {
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
init{
|
||||
println ("A::init")
|
||||
}
|
||||
|
||||
val a = 1
|
||||
|
||||
companion object :B(1) {
|
||||
init {
|
||||
println ("A::companion")
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
println("A::companion::foo")
|
||||
}
|
||||
}
|
||||
|
||||
object AObj : B(){
|
||||
init {
|
||||
println("A::Obj")
|
||||
}
|
||||
fun foo() {
|
||||
println("A::AObj::foo")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println("main")
|
||||
A.foo()
|
||||
A.foo()
|
||||
A.AObj.foo()
|
||||
A.AObj.foo()
|
||||
}
|
||||
|
||||
open class B(val a:Int, val b:Int) {
|
||||
constructor(a:Int):this (a, 0) {
|
||||
println("B::constructor(" + a.toString()+ ")")
|
||||
}
|
||||
constructor():this(0) {
|
||||
println("B::constructor()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class TestClass {
|
||||
companion object {
|
||||
init {
|
||||
println("Init Test")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val t1 = TestClass()
|
||||
val t2 = TestClass()
|
||||
println("Done")
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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(val msg: String) {
|
||||
init {
|
||||
println("init $msg")
|
||||
}
|
||||
override fun toString(): String = msg
|
||||
}
|
||||
|
||||
val globalValue1 = 1
|
||||
val globalValue2 = A("globalValue2")
|
||||
val globalValue3 = A("globalValue3")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(globalValue1.toString())
|
||||
println(globalValue2.toString())
|
||||
println(globalValue3.toString())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo(val bar: Int)
|
||||
|
||||
var x = Foo(42)
|
||||
|
||||
@Test fun runTest() {
|
||||
println(x.bar)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1
|
||||
val DOUBLE = Double.MAX_VALUE - 1.0
|
||||
|
||||
@Test fun runTest() {
|
||||
println(INT_MAX_POWER_OF_TWO)
|
||||
println(DOUBLE > 0.0)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
val a = 42
|
||||
val b = A.a
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(A.b)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
val aWorkerId = AtomicInt(0)
|
||||
val bWorkersCount = 3
|
||||
|
||||
val aWorkerUnlocker = AtomicInt(0)
|
||||
val bWorkerUnlocker = AtomicInt(0)
|
||||
|
||||
object A {
|
||||
init {
|
||||
// Must be called by aWorker only.
|
||||
assertEquals(aWorkerId.value, Worker.current.id)
|
||||
// Only allow b workers to run, when a worker has started initialization.
|
||||
bWorkerUnlocker.increment()
|
||||
// Only proceed with initialization, when all b workers have started executing.
|
||||
while (aWorkerUnlocker.value < bWorkersCount) {}
|
||||
// And now wait a bit, to increase probability of races.
|
||||
Worker.current.park(100 * 1000L)
|
||||
}
|
||||
val a = produceA()
|
||||
val b = produceB()
|
||||
}
|
||||
|
||||
fun produceA(): String {
|
||||
// Must've been called by aWorker only.
|
||||
assertEquals(aWorkerId.value, Worker.current.id)
|
||||
return "A"
|
||||
}
|
||||
|
||||
fun produceB(): String {
|
||||
// Must've been called by aWorker only.
|
||||
assertEquals(aWorkerId.value, Worker.current.id)
|
||||
// Also check that it's ok to get A.a while initializing A.b.
|
||||
return "B+${A.a}"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val aWorker = Worker.start()
|
||||
aWorkerId.value = aWorker.id
|
||||
val bWorkers = Array(bWorkersCount, { _ -> Worker.start() })
|
||||
|
||||
val aFuture = aWorker.execute(TransferMode.SAFE, {}, {
|
||||
A.b
|
||||
})
|
||||
val bFutures = Array(bWorkers.size, {
|
||||
bWorkers[it].execute(TransferMode.SAFE, {}, {
|
||||
// Wait until A has started to initialize.
|
||||
while (bWorkerUnlocker.value < 1) {}
|
||||
// Now allow A initialization to continue.
|
||||
aWorkerUnlocker.increment()
|
||||
// And this should not've tried to init A itself.
|
||||
A.a + A.b
|
||||
})
|
||||
})
|
||||
|
||||
for (future in bFutures) {
|
||||
assertEquals("AB+A", future.result)
|
||||
}
|
||||
assertEquals("B+A", aFuture.result)
|
||||
|
||||
for (worker in bWorkers) {
|
||||
worker.requestTermination().result
|
||||
}
|
||||
aWorker.requestTermination().result
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.initializers7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
object A {
|
||||
init {
|
||||
assertAUninitialized()
|
||||
}
|
||||
val a1 = 7
|
||||
val a2 = 12
|
||||
}
|
||||
|
||||
// Check that A is initialized dynamically.
|
||||
fun assertAUninitialized() {
|
||||
assertEquals(0, A.a1)
|
||||
assertEquals(0, A.a2)
|
||||
}
|
||||
|
||||
object B {
|
||||
init {
|
||||
assertBUninitialized()
|
||||
}
|
||||
val b1 = A.a2
|
||||
val b2 = C.c1
|
||||
}
|
||||
|
||||
// Check that B is initialized dynamically.
|
||||
fun assertBUninitialized() {
|
||||
assertEquals(0, B.b1)
|
||||
assertEquals(0, B.b2)
|
||||
}
|
||||
|
||||
object C {
|
||||
init {
|
||||
assertCUninitialized()
|
||||
}
|
||||
val c1 = 42
|
||||
val c2 = A.a1
|
||||
val c3 = B.b1
|
||||
val c4 = B.b2
|
||||
}
|
||||
|
||||
// Check that C is initialized dynamically.
|
||||
fun assertCUninitialized() {
|
||||
assertEquals(0, C.c1)
|
||||
assertEquals(0, C.c2)
|
||||
assertEquals(0, C.c3)
|
||||
assertEquals(0, C.c4)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
assertEquals(A.a1, C.c2)
|
||||
assertEquals(A.a2, C.c3)
|
||||
assertEquals(C.c1, C.c4)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.interface0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
fun b() = c()
|
||||
fun c()
|
||||
}
|
||||
|
||||
class B(): A {
|
||||
override fun c() {
|
||||
println("PASSED")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val a:A = B()
|
||||
a.b()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun fail() {
|
||||
println("Test failed, this is a wrong main() function.")
|
||||
}
|
||||
|
||||
fun foo(args: Array<String>) {
|
||||
println("Hello.")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.main_exception
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
throw Error("Hello!")
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.random
|
||||
|
||||
import kotlin.collections.*
|
||||
import kotlin.random.*
|
||||
import kotlin.system.*
|
||||
import kotlin.test.*
|
||||
|
||||
/**
|
||||
* Tests that setting the same seed make random generate the same sequence
|
||||
*/
|
||||
private inline fun <reified T> testReproducibility(seed: Long, generator: Random.() -> T) {
|
||||
// Reset seed. This will make Random to start a new sequence
|
||||
val r1 = Random(seed)
|
||||
val first = Array<T>(50, { i -> r1.generator() }).toList()
|
||||
|
||||
// Reset seed and try again
|
||||
val r2 = Random(seed)
|
||||
val second = Array<T>(50, { i -> r2.generator() }).toList()
|
||||
assertTrue(first == second, "FAIL: got different sequences of generated values " +
|
||||
"first: $first, second: $second")
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that setting seed makes random generate different sequence.
|
||||
*/
|
||||
private inline fun <reified T> testDifference(generator: Random.() -> T) {
|
||||
val r1 = Random(12345678L)
|
||||
val first = Array<T>(100, { i -> r1.generator() }).toList()
|
||||
|
||||
val r2 = Random(87654321L)
|
||||
val second = Array<T>(100, { i -> r2.generator() }).toList()
|
||||
assertTrue(first != second, "FAIL: got the same sequence of generated values " +
|
||||
"first: $first, second: $second")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInts() {
|
||||
testReproducibility(getTimeMillis(), { nextInt() })
|
||||
testReproducibility(Long.MAX_VALUE, { nextInt() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLong() {
|
||||
testReproducibility(getTimeMillis(), { nextLong() })
|
||||
testReproducibility(Long.MAX_VALUE, { nextLong() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDiffInt() = testDifference { nextInt() }
|
||||
|
||||
@Test
|
||||
fun testDiffLong() = testDifference { nextLong() }
|
||||
|
||||
@Test
|
||||
fun testNextInt() {
|
||||
testReproducibility(getTimeMillis(), { nextInt(1000) })
|
||||
testReproducibility(1000L, { nextInt(1024) })
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print(readLine()!!.toInt())
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print(readLine()!!)
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.simd
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
@Test fun runTest() {
|
||||
testBoxingSimple()
|
||||
testBoxing()
|
||||
testSetGet()
|
||||
testString()
|
||||
testOOB()
|
||||
testEquals()
|
||||
testHash()
|
||||
testDefaultValue()
|
||||
}
|
||||
|
||||
|
||||
class Box<T>(t: T) {
|
||||
var value = t
|
||||
}
|
||||
|
||||
class UnalignedC(t: Vector128) {
|
||||
var smth = 1
|
||||
var value = t
|
||||
}
|
||||
|
||||
fun testBoxingSimple() {
|
||||
val v = vectorOf(1f, 3.162f, 10f, 31f)
|
||||
val box: Box<Vector128> = Box<Vector128>(v)
|
||||
assertEquals(v, box.value, "testBoxingSimple FAILED")
|
||||
}
|
||||
|
||||
fun testBoxing() {
|
||||
var u = UnalignedC(vectorOf(0, 1, 2, 3))
|
||||
assertEquals(3, u.value.getIntAt(3))
|
||||
u.value = vectorOf(0f, 1f, 2f, 3f)
|
||||
assertEquals(vectorOf(0f, 1f, 2f, 3f), u.value, "testBoxing FAILED")
|
||||
}
|
||||
|
||||
fun testSetGet() {
|
||||
var v4any = vectorOf(0, 1, 2, 3)
|
||||
(0 until 4).forEach { assertEquals(it, v4any.getIntAt(it), "testSetGet FAILED for <4 x i32>") }
|
||||
|
||||
// type punning: set the variable to another runtime type
|
||||
val a = arrayOf(1f, 3.162f, 10f, 31f)
|
||||
v4any = vectorOf(a[0], a[1], a[2], a[3])
|
||||
(0 until 4).forEach { assertEquals(a[it], v4any.getFloatAt(it), "testSetGet FAILED for <4 x float>") }
|
||||
}
|
||||
|
||||
fun testString() {
|
||||
val v4i = vectorOf(100, 1024, Int.MAX_VALUE, Int.MIN_VALUE)
|
||||
assertEquals("(0x64, 0x400, 0x7fffffff, 0x80000000)", v4i.toString(), "testString FAILED")
|
||||
}
|
||||
|
||||
fun testOOB() {
|
||||
val f = vectorOf(1f, 3.162f, 10f, 31f)
|
||||
|
||||
println("f.getByteAt(15) is OK ${f.getByteAt(15)}")
|
||||
|
||||
assertFailsWith<IndexOutOfBoundsException>("f.getByteAt(16) should fail") {
|
||||
f.getByteAt(16)
|
||||
}
|
||||
|
||||
assertFailsWith<IndexOutOfBoundsException>("f.getIntAt(-1) should fail") {
|
||||
f.getIntAt(-1)
|
||||
}
|
||||
|
||||
assertFailsWith<IndexOutOfBoundsException>("f.getFloatAt(4) should fail") {
|
||||
f.getFloatAt(4)
|
||||
}
|
||||
}
|
||||
|
||||
fun testEquals() {
|
||||
var v1 = vectorOf(-1f, 0f, 0f, -7f)
|
||||
var v2 = vectorOf(1f, 4f, 3f, 7f)
|
||||
assertEquals(false, v1 == v2)
|
||||
assertEquals(false, v1.equals(v2))
|
||||
assertEquals(false, v1.equals(Any()))
|
||||
assertEquals(true, v2 == v2)
|
||||
|
||||
v1 = v2
|
||||
assertEquals(true, v1 == v2)
|
||||
}
|
||||
|
||||
fun testHash() {
|
||||
val h1 = vectorOf(1f, 4f, 3f, 7f).hashCode()
|
||||
val h2 = vectorOf(3f, 7f, 1f, 4f).hashCode()
|
||||
assertEquals(false, h1 == h2)
|
||||
|
||||
val i = 654687
|
||||
assertEquals(true, vectorOf(0, 0, i, 0).hashCode() == i.hashCode()) // exploit little endianness
|
||||
assertEquals(true, vectorOf(1, 0, 0, 0).hashCode() == vectorOf(0, 0, 31, 0).hashCode())
|
||||
}
|
||||
|
||||
private fun funDefaultValue(v: Vector128 = vectorOf(1.0f, 2.0f, 3.0f, 4.0f)) = v
|
||||
|
||||
fun testDefaultValue() {
|
||||
assertEquals(vectorOf(1.0f, 2.0f, 3.0f, 4.0f), funDefaultValue())
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.standard
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Foo(val bar: Int)
|
||||
|
||||
fun <T> assertEquals(actual: T, expected: T) {
|
||||
if (actual != expected) throw AssertionError("Assertion failed. Expected value: $expected, actual value: $actual")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
try {
|
||||
TODO()
|
||||
throw AssertionError("TODO() doesn't throw an exception")
|
||||
} catch(e: NotImplementedError) {}
|
||||
|
||||
val foo = Foo(42)
|
||||
assertEquals(run { 42 }, 42)
|
||||
assertEquals(foo.run { bar }, 42)
|
||||
assertEquals(with(foo) { bar }, 42)
|
||||
assertEquals(foo.apply { bar }, foo)
|
||||
assertEquals(foo.also { it.bar }, foo)
|
||||
assertEquals(foo.let { it.bar }, 42)
|
||||
var i = 0
|
||||
repeat(10) { i++ }
|
||||
assertEquals(i, 10)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.statements0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun simple() {
|
||||
var a = 238
|
||||
a++
|
||||
println(a)
|
||||
--a
|
||||
println(a)
|
||||
}
|
||||
|
||||
class Foo() {
|
||||
val j = 2
|
||||
var i = 29
|
||||
|
||||
fun more() {
|
||||
i++
|
||||
}
|
||||
|
||||
fun less() {
|
||||
--i
|
||||
}
|
||||
}
|
||||
|
||||
fun fields() {
|
||||
val foo = Foo()
|
||||
foo.more()
|
||||
println(foo.i)
|
||||
foo.less()
|
||||
println(foo.i)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
simple()
|
||||
fields()
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.throw0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val cond = 1
|
||||
if (cond == 2) throw RuntimeException()
|
||||
if (cond == 3) throw NoSuchElementException("no such element")
|
||||
if (cond == 4) throw Error("error happens")
|
||||
|
||||
println("Done")
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.tostring0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
println(127.toByte().toString())
|
||||
println(255.toByte().toString())
|
||||
println(239.toShort().toString())
|
||||
println('A'.toString())
|
||||
println('Ё'.toString())
|
||||
println('ト'.toString())
|
||||
println(1122334455.toString())
|
||||
println(112233445566778899.toString())
|
||||
// Here we differ from Java, as have no dtoa() yet.
|
||||
println(3.14159265358.toString())
|
||||
// Here we differ from Java, as have no dtoa() yet.
|
||||
println(1e27.toFloat().toString())
|
||||
println(1e7.toString())
|
||||
println(1e-300.toDouble().toString())
|
||||
println(true.toString())
|
||||
println(false.toString())
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.tostring1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val hello = "Hello world"
|
||||
println(hello.subSequence(1, 5).toString())
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.tostring2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val hello = "Hello"
|
||||
val array = hello.toCharArray()
|
||||
for (ch in array) {
|
||||
print(ch)
|
||||
print(" ")
|
||||
}
|
||||
println()
|
||||
println(String(array, 0, array.size))
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.tostring3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun testByte() {
|
||||
val values = ByteArray(2)
|
||||
values[0] = Byte.MIN_VALUE
|
||||
values[1] = Byte.MAX_VALUE
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun testShort() {
|
||||
val values = ShortArray(2)
|
||||
values[0] = Short.MIN_VALUE
|
||||
values[1] = Short.MAX_VALUE
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun testInt() {
|
||||
val values = IntArray(2)
|
||||
values[0] = Int.MIN_VALUE
|
||||
values[1] = Int.MAX_VALUE
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun testLong() {
|
||||
val values = LongArray(2)
|
||||
values[0] = Long.MIN_VALUE
|
||||
values[1] = Long.MAX_VALUE
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun testFloat() {
|
||||
val values = FloatArray(5)
|
||||
values[0] = Float.MIN_VALUE
|
||||
values[1] = Float.MAX_VALUE
|
||||
values[2] = Float.NEGATIVE_INFINITY
|
||||
values[3] = Float.POSITIVE_INFINITY
|
||||
values[4] = Float.NaN
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
fun testDouble() {
|
||||
val values = DoubleArray(5)
|
||||
values[0] = Double.MIN_VALUE
|
||||
values[1] = Double.MAX_VALUE
|
||||
values[2] = Double.NEGATIVE_INFINITY
|
||||
values[3] = Double.POSITIVE_INFINITY
|
||||
values[4] = Double.NaN
|
||||
for (v in values) {
|
||||
println(v)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
testByte()
|
||||
testShort()
|
||||
testInt()
|
||||
testLong()
|
||||
testFloat()
|
||||
testDouble()
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.
|
||||
*/
|
||||
|
||||
package runtime.basic.worker_random
|
||||
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlin.collections.*
|
||||
import kotlin.random.*
|
||||
import kotlin.system.*
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun testRandomWorkers() {
|
||||
val seed = getTimeMillis()
|
||||
val workers = Array(5, { _ -> Worker.start() })
|
||||
|
||||
val attempts = 3
|
||||
val results = Array(attempts, { ArrayList<Int>() } )
|
||||
for (attempt in 0 until attempts) {
|
||||
// Produce a list of random numbers in each worker
|
||||
val futures = Array(workers.size, { workerIndex ->
|
||||
workers[workerIndex].execute(TransferMode.SAFE, { workerIndex }) {
|
||||
input ->
|
||||
Array(10, { Random.nextInt() }).toList()
|
||||
}
|
||||
})
|
||||
// Now collect all results into current attempt's list
|
||||
val futureSet = futures.toSet()
|
||||
var finished = 0
|
||||
while (finished < futureSet.size) {
|
||||
val ready = waitForMultipleFutures(futureSet, 10000)
|
||||
ready.forEach { results[attempt].addAll(it.result) }
|
||||
finished += ready.size
|
||||
}
|
||||
}
|
||||
|
||||
workers.forEach {
|
||||
it.requestTermination().result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user