From 8539d9395e0f0501adb7e3101178c63c575cb4b3 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 13 Feb 2019 17:46:35 +0300 Subject: [PATCH] Fix cross-tests on Mac. (#2655) --- backend.native/tests/build.gradle | 41 ++++++++----------- .../tests/interop/basics/echo_server.kt | 21 ++++------ build.gradle | 7 ++++ 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 4bb03aefa3a..9d3da6812e2 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2904,7 +2904,7 @@ kotlinNativeInterop { defFile 'interop/basics/ccallbacksAndVarargs.def' } - if (isMac()) { + if (isAppleTarget(project)) { objcSmoke { defFile 'interop/objc/objcSmoke.def' headers "$projectDir/interop/objc/smoke.h" @@ -3012,34 +3012,29 @@ task interop_callbacksAndVarargs(type: RunInteropKonanTest) { task interop_echo_server(type: RunInteropKonanTest) { disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. - if (!isMac()) { - // Not supported or not tested. - disabled = true - } run = false source = "interop/basics/echo_server.kt" interop = 'sockets' } -if (isMac()) { - task interop_opengl_teapot(type: RunStandaloneKonanTest) { - dependsOnPlatformLibs(it as Task) - disabled = (project.testTarget == 'wasm32') || // No interop for wasm yet. - (project.testTarget == 'ios_x64') // No GLUT in iOS - run = false - source = "interop/basics/opengl_teapot.kt" - } +task interop_opengl_teapot(type: RunStandaloneKonanTest) { + disabled = !isAppleTarget(project) || (project.testTarget == 'ios_x64') // No GLUT in iOS + dependsOnPlatformLibs(it as Task) + run = false + source = "interop/basics/opengl_teapot.kt" +} - task interop_objc_smoke(type: RunInteropKonanTest) { - disabled = (project.testTarget == 'wasm32') // No interop for wasm yet. - goldValue = "84\nFoo\nHello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" + - "true\ntrue\n" + - "Global string\nAnother global string\nnull\nglobal object\n" + - "5\n" + - "String macro\n" + - "CFString macro\n" + - "Deallocated\nDeallocated\n" +task interop_objc_smoke(type: RunInteropKonanTest) { + disabled = !isAppleTarget(project) + goldValue = "84\nFoo\nHello, World!\nKotlin says: Hello, everybody!\nHello from Kotlin\n2, 1\n" + + "true\ntrue\n" + + "Global string\nAnother global string\nnull\nglobal object\n" + + "5\n" + + "String macro\n" + + "CFString macro\n" + + "Deallocated\nDeallocated\n" + if (isAppleTarget(project)) { source = "interop/objc/smoke.kt" interop = 'objcSmoke' @@ -3138,7 +3133,7 @@ task library_mismatch(type: RunStandaloneKonanTest) { goldValue = isWindows() ? messages.replaceAll('\\/', '\\\\') : messages } -if (isMac() && project.testTarget != 'wasm32') { +if (isAppleTarget(project)) { def target = ext.platformManager.targetByName(project.testTarget ?: 'host').name task testValuesFramework(type: FrameworkTest) { diff --git a/backend.native/tests/interop/basics/echo_server.kt b/backend.native/tests/interop/basics/echo_server.kt index d19db93a6ed..347711e580d 100644 --- a/backend.native/tests/interop/basics/echo_server.kt +++ b/backend.native/tests/interop/basics/echo_server.kt @@ -21,7 +21,7 @@ fun main(args: Array) { val serverAddr = alloc() val listenFd = socket(AF_INET, SOCK_STREAM, 0) - .ensureUnixCallResult { it >= 0 } + .toInt().ensureUnixCallResult { it >= 0 } with(serverAddr) { memset(this.ptr, 0, sockaddr_in.size.convert()) @@ -31,24 +31,24 @@ fun main(args: Array) { } bind(listenFd, serverAddr.ptr.reinterpret(), sockaddr_in.size.toUInt()) - .ensureUnixCallResult { it == 0 } + .toInt().ensureUnixCallResult { it == 0 } listen(listenFd, 10) - .ensureUnixCallResult { it == 0 } + .toInt().ensureUnixCallResult { it == 0 } val commFd = accept(listenFd, null, null) - .ensureUnixCallResult { it >= 0 } + .toInt().ensureUnixCallResult { it >= 0 } while (true) { val length = read(commFd, buffer, bufferLength.convert()) - .ensureUnixCallResult { it >= 0 } + .toInt().ensureUnixCallResult { it >= 0 } - if (length == 0L) { + if (length == 0) { break } write(commFd, buffer, length.convert()) - .ensureUnixCallResult { it >= 0 } + .toInt().ensureUnixCallResult { it >= 0 } } } } @@ -67,10 +67,3 @@ inline fun Int.ensureUnixCallResult(predicate: (Int) -> Boolean): Int { } return this } - -inline fun Long.ensureUnixCallResult(predicate: (Long) -> Boolean): Long { - if (!predicate(this)) { - throwUnixError() - } - return this -} \ No newline at end of file diff --git a/build.gradle b/build.gradle index df4bf9ea5d5..0067fbc5a88 100644 --- a/build.gradle +++ b/build.gradle @@ -162,6 +162,13 @@ class PlatformInfo { return HostManager.hostIsLinux } + boolean isAppleTarget(Project project) { + def platformManager = project.rootProject.platformManager + def targetName = project.project.testTarget ?: 'host' + def target = platformManager.targetManager(targetName).target + return target.family == Family.IOS || target.family == Family.OSX + } + Throwable unsupportedPlatformException() { return new TargetSupportException() }