f4e8ae5191
* @ExperimentalForeignApi for all declarations that operate on
unmanaged memory (i.e. pointers and references)
* @BetaInteropApi for the rest of the interoperability declarations,
namely Swift/CInterop-specific interfaces and convenience-functions
### Implementation details
* Some typealiases are not marked explicitly because it crashes the compiler,
yet their experimentality is properly propagated
* License header is adjusted where it previously had been existing
* Deprecated with ERROR interop declarations that are deprecated for more than
two years are removed
* WASM target interop declarations are deprecated
* Deliberately make Boolean.toByte and Byte.toBoolean foreign-experimental to scare
people away
^KT-57728 fixed
Merge-request: KT-MR-9788
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
44 lines
1.9 KiB
Kotlin
44 lines
1.9 KiB
Kotlin
/*
|
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
*/
|
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
|
|
|
import kotlin.native.*
|
|
import kotlin.test.*
|
|
import cstdlib.*
|
|
import kotlinx.cinterop.*
|
|
|
|
|
|
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
|
fun main(args: Array<String>) {
|
|
require(args.size == 1) {
|
|
"An expected anount of processors should be specified as program argument"
|
|
}
|
|
val x: Int = Platform.getAvailableProcessors()
|
|
println("Got available processors: $x")
|
|
assertTrue(x > 0)
|
|
if (!(Platform.osFamily == OsFamily.LINUX && (Platform.cpuArchitecture == CpuArchitecture.ARM32 ||
|
|
Platform.cpuArchitecture == CpuArchitecture.ARM64))) {
|
|
assertEquals(args[0].trim().toInt(), x)
|
|
}
|
|
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", "12345", 1)
|
|
assertEquals(Platform.getAvailableProcessors(), 12345)
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", Long.MAX_VALUE.toString(), 1)
|
|
assertFailsWith<IllegalStateException> { Platform.getAvailableProcessors() }
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", "-1", 1)
|
|
assertFailsWith<IllegalStateException> { Platform.getAvailableProcessors() }
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", "0", 1)
|
|
assertFailsWith<IllegalStateException> { Platform.getAvailableProcessors() }
|
|
// windows doesn't support empty env variables
|
|
if (Platform.osFamily != OsFamily.WINDOWS) {
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", "", 1)
|
|
assertFailsWith<IllegalStateException> { Platform.getAvailableProcessors() }
|
|
}
|
|
setenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS", "123aaaa", 1)
|
|
assertFailsWith<IllegalStateException> { Platform.getAvailableProcessors() }
|
|
unsetenv("KOTLIN_NATIVE_AVAILABLE_PROCESSORS")
|
|
assertEquals(Platform.getAvailableProcessors(), x)
|
|
}
|